jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/384430 )
Change subject: Convert the extension to the new execution framework ...................................................................... Convert the extension to the new execution framework Change-Id: I1c9e2d8775ba15988a7545a6448cae89b1371c02 --- M VipsScaler_body.php 1 file changed, 58 insertions(+), 36 deletions(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified diff --git a/VipsScaler_body.php b/VipsScaler_body.php index c5d6fd6..af4c101 100644 --- a/VipsScaler_body.php +++ b/VipsScaler_body.php @@ -21,6 +21,8 @@ * @file */ +use MediaWiki\Shell\Shell; + /** * Wrapper class for VIPS, a free image processing system good at handling * large pictures. @@ -343,10 +345,8 @@ public static function setJpegComment( $fileName, $comment ) { global $wgExiv2Command; - wfShellExec( wfEscapeShellArg( $wgExiv2Command ) . ' mo -c ' - . wfEscapeShellArg( $comment ) . ' ' - . wfEscapeShellArg( $fileName ) - ); + Shell::command( $wgExiv2Command, 'mo', '-c', $comment, $fileName ) + ->execute(); } /** @@ -404,6 +404,12 @@ /** @var bool */ protected $removeInput; + + /** @var string */ + protected $vips; + + /** @var array */ + protected $args; /** * Constructor @@ -463,22 +469,25 @@ * @return int Return value */ public function execute() { - # Build and escape the command string - $env = [ 'IM_CONCURRENCY' => '1' ]; - $limits = [ 'filesize' => 409600 ]; - $cmd = wfEscapeShellArg( - $this->vips, - array_shift( $this->args ), - $this->input, $this->output - ); + # Build the command line + $cmd = [ + $this->vips, + array_shift( $this->args ), + $this->input, + $this->output + ]; - foreach ( $this->args as $arg ) { - $cmd .= ' ' . wfEscapeShellArg( $arg ); - } + $cmd = array_merge( $cmd, $this->args ); # Execute - $retval = 0; - $this->err = wfShellExecWithStderr( $cmd, $retval, $env, $limits ); + $result = Shell::command( $cmd ) + ->environment( [ 'IM_CONCURRENCY' => '1' ] ) + ->limits( [ 'filesize' => 409600 ] ) + ->includeStderr() + ->execute(); + + $this->err = $result->getStdout(); + $retval = $result->getExitCode(); # Cleanup temp file if ( $retval != 0 && file_exists( $this->output ) ) { @@ -561,29 +570,40 @@ wfDebug( __METHOD__ . ": Convolving image [\n" . $convolutionString . "] \n" ); - $env = [ 'IM_CONCURRENCY' => '1' ]; $limits = [ 'filesize' => 409600 ]; - $cmd = wfEscapeShellArg( - $this->vips, - array_shift( $this->args ), - $this->input, $tmpOutputPath - ); + $env = [ 'IM_CONCURRENCY' => '1' ]; - foreach ( $this->args as $arg ) { - $cmd .= ' ' . wfEscapeShellArg( $arg ); - } + $cmd = [ + $this->vips, + array_shift( $this->args ), + $this->input, + $tmpOutputPath + ]; + $cmd = array_merge( $cmd, $this->args ); + // Execute - $retval = 0; - $this->err = wfShellExecWithStderr( $cmd, $retval, $env, $limits ); + $result = Shell::command( $cmd ) + ->environment( $env ) + ->limits( $limits ) + ->includeStderr() + ->execute(); + $retval = $result->getExitCode(); + $this->err = $result->getStdout(); if ( $retval === 0 ) { // vips seems to get confused about the bit depth after a convolution // so reset it. Without this step, 16-bit tiff files seem to become all // black when converted to pngs (https://github.com/jcupitt/libvips/issues/344) - $formatCmd = wfEscapeShellArg( + $formatCmd = [ $this->vips, 'im_clip2fmt', $tmpOutputPath, $this->output, $format - ); - $this->err .= wfShellExecWithStderr( $formatCmd, $retval, $env, $limits ); + ]; + $result = Shell::command( $formatCmd ) + ->environment( $env ) + ->limits( $limits ) + ->includeStderr() + ->execute(); + $retval = $result->getExitCode(); + $this->err .= $result->getStdout(); } // Cleanup temp file @@ -610,12 +630,14 @@ * (common value 0 = VIPS_FORMAT_UCHAR, 2 = VIPS_FORMAT_USHORT) */ function getFormat( $input ) { - $retval = 0; - $cmd = wfEscapeShellArg( $this->vips, 'im_header_int', 'format', $input ); - $res = wfShellExec( $cmd, $retval, [ 'IM_CONCURRENCY' => '1' ] ); - $res = trim( $res ); + $cmd = [ $this->vips, 'im_header_int', 'format', $input ]; + $result = Shell::command( $cmd ) + ->environment( [ 'IM_CONCURRENCY' => '1' ] ) + ->execute(); - if ( $retval !== 0 || !is_numeric( $res ) ) { + $res = trim( $result->getStdout() ); + + if ( $result->getExitCode() !== 0 || !is_numeric( $res ) ) { throw new Exception( "Cannot determine vips format of image" ); } -- To view, visit https://gerrit.wikimedia.org/r/384430 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1c9e2d8775ba15988a7545a6448cae89b1371c02 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/VipsScaler Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits