From: Max Semenik Date: Sun, 17 Mar 2019 05:45:17 +0000 (-0700) Subject: media: Convert JpegHandler to shell execution framework X-Git-Tag: 1.34.0-rc.0~2144^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=0dc749e0a8c13cce4789c23b313671700f185623 media: Convert JpegHandler to shell execution framework Change-Id: I99dbdf9108d3b3dc82acd0ca7ba5da9645f41790 --- diff --git a/includes/media/JpegHandler.php b/includes/media/JpegHandler.php index 4bcb53dd56..4aca5b3b80 100644 --- a/includes/media/JpegHandler.php +++ b/includes/media/JpegHandler.php @@ -21,6 +21,8 @@ * @ingroup Media */ +use MediaWiki\Shell\Shell; + /** * JPEG specific handler. * Inherits most stuff from BitmapHandler, just here to do the metadata handler differently. @@ -140,17 +142,23 @@ class JpegHandler extends ExifBitmapHandler { $rotation = ( $params['rotation'] + $this->getRotation( $file ) ) % 360; if ( $wgJpegTran && is_executable( $wgJpegTran ) ) { - $cmd = wfEscapeShellArg( $wgJpegTran ) . - " -rotate " . wfEscapeShellArg( $rotation ) . - " -outfile " . wfEscapeShellArg( $params['dstPath'] ) . - " " . wfEscapeShellArg( $params['srcPath'] ); - wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" ); - $retval = 0; - $err = wfShellExecWithStderr( $cmd, $retval ); - if ( $retval !== 0 ) { - $this->logErrorForExternalProcess( $retval, $err, $cmd ); - - return new MediaTransformError( 'thumbnail_error', 0, 0, $err ); + $command = Shell::command( $wgJpegTran, + '-rotate', + $rotation, + '-outfile', + $params['dstPath'], + $params['srcPath'] + ); + $result = $command + ->includeStderr() + ->execute(); + if ( $result->getExitCode() !== 0 ) { + $this->logErrorForExternalProcess( $result->getExitCode(), + $result->getStdout(), + $command + ); + + return new MediaTransformError( 'thumbnail_error', 0, 0, $result->getStdout() ); } return false; @@ -240,20 +248,21 @@ class JpegHandler extends ExifBitmapHandler { return false; } - $cmd = wfEscapeShellArg( $wgExiftool, + $result = Shell::command( + $wgExiftool, '-EXIF:ColorSpace', '-ICC_Profile:ProfileDescription', '-S', '-T', $filepath - ); - - $output = wfShellExecWithStderr( $cmd, $retval ); + ) + ->includeStderr() + ->execute(); // Explode EXIF data into an array with [0 => Color Space, 1 => Device Model Desc] - $data = explode( "\t", trim( $output ) ); + $data = explode( "\t", trim( $result->getStdout() ) ); - if ( $retval !== 0 ) { + if ( $result->getExitCode() !== 0 ) { return false; } @@ -271,16 +280,20 @@ class JpegHandler extends ExifBitmapHandler { return false; } - $cmd = wfEscapeShellArg( $wgExiftool, + $command = Shell::command( $wgExiftool, '-overwrite_original', '-icc_profile<=' . $profileFilepath, $filepath ); - - $output = wfShellExecWithStderr( $cmd, $retval ); - - if ( $retval !== 0 ) { - $this->logErrorForExternalProcess( $retval, $output, $cmd ); + $result = $command + ->includeStderr() + ->execute(); + + if ( $result->getExitCode() !== 0 ) { + $this->logErrorForExternalProcess( $result->getExitCode(), + $result->getStdout(), + $command + ); return false; }