return new Result( $retval, $buffers[1], $buffers[2] );
}
+
+ /**
+ * Returns the final command line before environment/limiting, etc are applied.
+ * Use string conversion only for debugging, don't try to pass this to
+ * some other execution medium.
+ *
+ * @return string
+ */
+ public function __toString() {
+ return "#Command: {$this->command}";
+ }
}
* @author Neil Kandalgaonkar <neilk@wikimedia.org>
*/
+use MediaWiki\Shell\Shell;
+
/**
* RandomImageGenerator: does what it says on the tin.
* Can fetch a random image, or also write a number of them to disk with random filenames.
// for now (only works if you have exiv2 installed, a program to read
// and manipulate exif).
if ( $wgExiv2Command ) {
- $cmd = wfEscapeShellArg( $wgExiv2Command )
- . " -M "
- . wfEscapeShellArg( "set Exif.Image.Orientation " . $orientation['exifCode'] )
- . " "
- . wfEscapeShellArg( $filename );
-
- $retval = 0;
- $err = wfShellExec( $cmd, $retval );
+ $command = Shell::command( $wgExiv2Command,
+ '-M',
+ "set Exif.Image.Orientation {$orientation['exifCode']}",
+ $filename
+ )->includeStderr();
+
+ $result = $command->execute();
+ $retval = $result->getExitCode();
if ( $retval !== 0 ) {
- print "Error with $cmd: $retval, $err\n";
+ print "Error with $command: $retval, {$result->getStdout()}\n";
}
}
}
*/
public function writeImageWithCommandLine( $spec, $format, $filename ) {
global $wgImageMagickConvertCommand;
- $args = [];
- $args[] = "-size " . wfEscapeShellArg( $spec['width'] . 'x' . $spec['height'] );
- $args[] = wfEscapeShellArg( "xc:" . $spec['fill'] );
+
+ $args = [
+ $wgImageMagickConvertCommand,
+ '-size',
+ $spec['width'] . 'x' . $spec['height'],
+ "xc:{$spec['fill']}",
+ ];
foreach ( $spec['draws'] as $draw ) {
$fill = $draw['fill'];
$polygon = self::shapePointsToString( $draw['shape'] );
$drawCommand = "fill $fill polygon $polygon";
- $args[] = '-draw ' . wfEscapeShellArg( $drawCommand );
+ $args[] = '-draw';
+ $args[] = $drawCommand;
}
- $args[] = wfEscapeShellArg( $filename );
+ $args[] = $filename;
- $command = wfEscapeShellArg( $wgImageMagickConvertCommand ) . " " . implode( " ", $args );
- $retval = null;
- wfShellExec( $command, $retval );
+ $result = Shell::command( $args )->execute();
- return ( $retval === 0 );
+ return ( $result->getExitCode() === 0 );
}
/**