Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -2457,9 +2457,11 @@ |
2458 | 2458 | * @param $cmd Command line, properly escaped for shell. |
2459 | 2459 | * @param &$retval optional, will receive the program's exit code. |
2460 | 2460 | * (non-zero is usually failure) |
| 2461 | + * @param $environ Array optional environment variables which should be |
| 2462 | + * added to the executed command environment. |
2461 | 2463 | * @return collected stdout as a string (trailing newlines stripped) |
2462 | 2464 | */ |
2463 | | -function wfShellExec( $cmd, &$retval = null ) { |
| 2465 | +function wfShellExec( $cmd, &$retval = null, $environ = array() ) { |
2464 | 2466 | global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime; |
2465 | 2467 | |
2466 | 2468 | static $disabled; |
— | — | @@ -2487,6 +2489,25 @@ |
2488 | 2490 | |
2489 | 2491 | wfInitShellLocale(); |
2490 | 2492 | |
| 2493 | + $envcmd = ''; |
| 2494 | + foreach( $environ as $k => $v ) { |
| 2495 | + if ( wfIsWindows() ) { |
| 2496 | + /* Surrounding a set in quotes (method used by wfEscapeShellArg) makes the quotes themselves |
| 2497 | + * appear in the environment variable, so we must use carat escaping as documented in |
| 2498 | + * http://technet.microsoft.com/en-us/library/cc723564.aspx |
| 2499 | + * Note however that the quote isn't listed there, but is needed, and the parentheses |
| 2500 | + * are listed there but doesn't appear to need it. |
| 2501 | + */ |
| 2502 | + $envcmd .= "set $k=" . preg_replace( '/([&|()<>^"])/', '^\\1', $v ) . ' && '; |
| 2503 | + } else { |
| 2504 | + /* Assume this is a POSIX shell, thus required to accept variable assignments before the command |
| 2505 | + * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_01 |
| 2506 | + */ |
| 2507 | + $envcmd .= "$k=" . escapeshellarg( $v ) . ' '; |
| 2508 | + } |
| 2509 | + } |
| 2510 | + $cmd = $envcmd . $cmd; |
| 2511 | + |
2491 | 2512 | if ( wfIsWindows() ) { |
2492 | 2513 | if ( version_compare( PHP_VERSION, '5.3.0', '<' ) && /* Fixed in 5.3.0 :) */ |
2493 | 2514 | ( version_compare( PHP_VERSION, '5.2.1', '>=' ) || php_uname( 's' ) == 'Windows NT' ) ) |
Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -148,9 +148,9 @@ |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Use one thread only, to avoid deadlock bugs on OOM |
152 | | - $tempEnv = 'OMP_NUM_THREADS=1 '; |
| 152 | + $env = array( 'OMP_NUM_THREADS' => 1 ); |
153 | 153 | if ( strval( $wgImageMagickTempDir ) !== '' ) { |
154 | | - $tempEnv .= 'MAGICK_TMPDIR=' . wfEscapeShellArg( $wgImageMagickTempDir ) . ' '; |
| 154 | + $env['MAGICK_TMPDIR'] = $wgImageMagickTempDir; |
155 | 155 | } |
156 | 156 | |
157 | 157 | $cmd = |
— | — | @@ -171,14 +171,9 @@ |
172 | 172 | " {$animation_post} " . |
173 | 173 | wfEscapeShellArg( $this->escapeMagickOutput( $dstPath ) ) . " 2>&1"; |
174 | 174 | |
175 | | - if ( !wfIsWindows() ) { |
176 | | - // Assume we have a POSIX compliant shell which accepts variable assignments preceding the command |
177 | | - $cmd = $tempEnv . $cmd; |
178 | | - } |
179 | | - |
180 | 175 | wfDebug( __METHOD__.": running ImageMagick: $cmd\n" ); |
181 | 176 | wfProfileIn( 'convert' ); |
182 | | - $err = wfShellExec( $cmd, $retval ); |
| 177 | + $err = wfShellExec( $cmd, $retval, $env ); |
183 | 178 | wfProfileOut( 'convert' ); |
184 | 179 | } elseif( $scaler == 'custom' ) { |
185 | 180 | # Use a custom convert command |