r71546 broke imagemagick usage in Windows, since cmd.exe takes the variable
authorPlatonides <platonides@users.mediawiki.org>
Fri, 15 Oct 2010 19:48:21 +0000 (19:48 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Fri, 15 Oct 2010 19:48:21 +0000 (19:48 +0000)
names as the program name.
I'm just not exporting those variables here, but we need to support them in Windows, too.
We could use putenv() but that seems ugly (and risky). A better solution would be to have
wfShellExec() call proc_open() with a modified environment.

A POSIX shell is required to accept variable assignments before the command so we shouldn't
have problems on any UNIX-like system.
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_01

includes/media/Bitmap.php

index 4909af2..7e9edb7 100644 (file)
@@ -147,16 +147,13 @@ class BitmapHandler extends ImageHandler {
                                }
                        }
 
+                       // Use one thread only, to avoid deadlock bugs on OOM
+                       $tempEnv = 'OMP_NUM_THREADS=1 ';
                        if ( strval( $wgImageMagickTempDir ) !== '' ) {
-                               $tempEnv = 'MAGICK_TMPDIR=' . wfEscapeShellArg( $wgImageMagickTempDir ) . ' ';
-                       } else {
-                               $tempEnv = '';
+                               $tempEnv .= 'MAGICK_TMPDIR=' . wfEscapeShellArg( $wgImageMagickTempDir ) . ' ';
                        }
 
                        $cmd  = 
-                               $tempEnv .
-                               // Use one thread only, to avoid deadlock bugs on OOM
-                               'OMP_NUM_THREADS=1 ' .
                                wfEscapeShellArg( $wgImageMagickConvertCommand ) .
                                // Specify white background color, will be used for transparent images
                                // in Internet Explorer/Windows instead of default black.
@@ -173,6 +170,12 @@ class BitmapHandler extends ImageHandler {
                                " -depth 8 $sharpen" .
                                " {$animation_post} " .
                                wfEscapeShellArg( $this->escapeMagickOutput( $dstPath ) ) . " 2>&1";
+
+                       if ( !wfIsWindows() ) {
+                               // Assume we have a POSIX compliant shell which accepts variable assignments preceding the command
+                               $cmd = $tempEnv . $cmd;
+                       }
+
                        wfDebug( __METHOD__.": running ImageMagick: $cmd\n" );
                        wfProfileIn( 'convert' );
                        $err = wfShellExec( $cmd, $retval );