* (bug 6086) Remove vestigial attempt to call Article::validate()
* wfHostname() function for consistent server hostname use in debug messages
* Send thumbnailing error messages to 'thumbnail' log group
+* wfShellexec() now accepts an optional parameter to receive the exit code
+* Failed, but not zero-length, thumbnail renderings are now removed.
+ Should help clean up when rsvg fails in weird ways.
== Compatibility ==
}
/**
- * shell_exec() with time and memory limits mirrored from the PHP configuration,
- * if supported.
- */
-function wfShellExec( $cmd )
-{
+ * Execute a shell command, with time and memory limits mirrored from the PHP
+ * configuration if supported.
+ * @param $cmd Command line, properly escaped for shell.
+ * @param &$retval optional, will receive the program's exit code.
+ * (non-zero is usually failure)
+ * @return collected stdout as a string (trailing newlines stripped)
+ */
+function wfShellExec( $cmd, &$retval=null ) {
global $IP;
+
+ if( ini_get( 'safe_mode' ) ) {
+ wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" );
+ $retval = 1;
+ return "Unable to run external programs in safe mode.";
+ }
if ( php_uname( 's' ) == 'Linux' ) {
$time = ini_get( 'max_execution_time' );
$cmd = '"' . $cmd . '"';
}
wfDebug( "wfShellExec: $cmd\n" );
- return shell_exec( $cmd );
+
+ $output = array();
+ $retval = 1; // error by default?
+ $lastline = exec( $cmd, $output, $retval );
+ return implode( "\n", $output );
+
}
/**
$this->load();
$err = false;
+ $cmd = "";
+ $retval = 0;
+
if( $this->mime === "image/svg" ) {
#Right now we have only SVG
$wgSVGConverters[$wgSVGConverter] );
wfProfileIn( 'rsvg' );
wfDebug( "reallyRenderThumb SVG: $cmd\n" );
- $err = wfShellExec( $cmd );
+ $err = wfShellExec( $cmd, $retval );
wfProfileOut( 'rsvg' );
}
} elseif ( $wgUseImageMagick ) {
wfEscapeShellArg($thumbPath) . " 2>&1";
wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
wfProfileIn( 'convert' );
- $err = wfShellExec( $cmd );
+ $err = wfShellExec( $cmd, $retval );
wfProfileOut( 'convert' );
} elseif( $wgCustomConvertCommand ) {
# Use a custom convert command
$cmd = str_replace( '%h', $height, str_replace( '%w', $width, $cmd ) ); # Size
wfDebug( "reallyRenderThumb: Running custom convert command $cmd\n" );
wfProfileIn( 'convert' );
- $err = wfShellExec( $cmd );
+ $err = wfShellExec( $cmd, $retval );
wfProfileOut( 'convert' );
} else {
# Use PHP's builtin GD library functions.
#
if( file_exists( $thumbPath ) ) {
$thumbstat = stat( $thumbPath );
- if( $thumbstat['size'] == 0 ) {
+ if( $thumbstat['size'] == 0 || $retval != 0 ) {
+ wfDebugLog( 'thumbnail',
+ sprintf( 'Removing bad %d-byte thumbnail "%s"',
+ $thumbstat['size'], $thumbPath ) );
unlink( $thumbPath );
- } else {
- // All good
- $err = true;
}
}
- if ( $err !== true ) {
+ if ( $retval != 0 ) {
wfDebugLog( 'thumbnail',
- sprintf( 'thumbnail failed on %s: "%s" from "%s"',
- wfHostname(), trim($err), $cmd ) );
+ sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
+ wfHostname(), $retval, trim($err), $cmd ) );
return wfMsg( 'thumbnail_error', $err );
} else {
return true;