[R-sig-mediawiki] Various changes to R extension - md5, uname, png
Alex Brown
alex at transitive.com
Tue Sep 5 17:51:32 CEST 2006
Here are some changes I have made against version 0.02 of the
mediawiki extension to make it run on my server (suse), or to improve
functionality
Patch 1:
Change the checksum to use md5 instead of sha1, which did not exist
on my site
Change the uname call to not have an argument, since it does not on
my site
At some point we should probably detect what checksums are available
and use whatever is.
Patch 2:
Change the default image type to png instead of jpg. Png is widely
supported by user agents, and compared to jpg it creates a much nicer
output image for line art such as that produced by R.
This
I will at some point upgrade to 0.03 and provide patches, but I
wanted to make these public now.
If you would prefer these diffs in a different format, please let me
know.
-Alex
Patch 1:
diff -u extensions/Rext.php Rext_backup_1_clean.php | less
--- extensions/Rext.php 2006-09-05 13:53:03.751510701 +0100
+++ Rext_backup_1_clean.php 2006-09-05 16:37:48.367253212 +0100
@@ -37,7 +37,8 @@
define('convert', RgetDefault('convert'));
function RgetDefault ($key) {
- $hostname = php_uname('n');
+ #$hostname = php_uname('n');
+ $hostname = php_uname();
# First general constants
switch ($key) {
case 'htdocs' :
@@ -382,7 +383,7 @@
$onsave = array_key_exists('onsave', $params);
$echo = array_key_exists('echo', $params);
$direct = !array_key_exists('iframe', $params);
- $sha1 = sha1($input . $output . $style);
+ $sha1 = md5($input . $output . $style);
$ws = array_key_exists('workspace', $params)? $params
['workspace'] : '';
// security checks
Patch 2:
--- Rext_backup_2_clean.php 2006-09-05 16:42:33.211654510 +0100
+++ Rext_backup_1.php 2006-09-05 13:43:31.657285129 +0100
@@ -207,12 +207,12 @@
$rws = r_dir. DIRECTORY_SEPARATOR . $ws;
switch ($output) {
case 'display':
- $png = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.png';
+ $jpg = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.jpg';
$pdf = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.pdf';
- $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '.png';
+ $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '.jpg';
$urlpdf = r_url . DIRECTORY_SEPARATOR . $sha1 . '.pdf';
$htm = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.html';
- if (!file_exists($png) or onsave) {
+ if (!file_exists($jpg) or onsave) {
$content = '';
if ($ws!='') {
$content = $content . 'sys.load.image("' . $rws . '",
TRUE)' ."\n";
@@ -229,14 +229,14 @@
fwrite ($fd, $content);
fclose ($fd);
$err = $err . runShell (r_cmd . ' < ' . $fn);
- $err = $err . runShell (convert . ' ' . $pdf . ' ' .
$convert . ' ' . $png);
+ $err = $err . runShell (convert . ' ' . $pdf . ' ' .
$convert . ' ' . $jpg);
}
- if (!file_exists($png)) {
- $png = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.png.0';
- if (file_exists($png)) {
+ if (!file_exists($jpg)) {
+ $jpg = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.jpg.0';
+ if (file_exists($jpg)) {
for ($i=0; ; $i++) {
- $old = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.png.' . $i;
- $new = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-' . $i .
'.png';
+ $old = r_dir . DIRECTORY_SEPARATOR . $sha1 . '.jpg.' . $i;
+ $new = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-' . $i .
'.jpg';
if (file_exists($old)) {
rename ($old, $new);
} else {
@@ -244,14 +244,14 @@
}
}
}
- $png = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-0.png';
- file_exists($png) or Rerror ('R', 'PNG file does not exist:
' . $png, $input . $err);
- $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '-0.png';
+ $jpg = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-0.jpg';
+ file_exists($jpg) or Rerror ('R', 'JPEG file does not exist:
' . $jpg, $input . $err);
+ $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '-0.jpg';
$ret = '<a href="' . $urlpdf . '"><img src="' . $url . '"
border="0" style="' . style . '"></a>';
for ($i=1; ; $i++) {
- $png = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-'. $i .
'.png';
- $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '-' . $i .
'.png';
- if (file_exists($png)) {
+ $jpg = r_dir . DIRECTORY_SEPARATOR . $sha1 . '-'. $i .
'.jpg';
+ $url = r_url . DIRECTORY_SEPARATOR . $sha1 . '-' . $i .
'.jpg';
+ if (file_exists($jpg)) {
$ret = $ret . '<a href="' . $urlpdf . '"><img src="' .
$url . '" border="0" style="' . $style . '"></a>';
} else {
break;
More information about the R-sig-mediawiki
mailing list