X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=blobdiff_plain;f=includes%2Fmedia%2FJpegHandler.php;h=4aca5b3b804b48ff75b4bd12fdb0bd341a636616;hb=424eb75d77f7a7513cd59083198f5b3a407a8715;hp=91bed4a82cd0c36058942301be3aa0727307ac4c;hpb=a4120368bb7797df25004613feed9406eac1c9d0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/JpegHandler.php b/includes/media/JpegHandler.php index 91bed4a82c..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. @@ -34,7 +36,7 @@ class JpegHandler extends ExifBitmapHandler { const SRGB_EXIF_COLOR_SPACE = 'sRGB'; const SRGB_ICC_PROFILE_DESCRIPTION = 'sRGB IEC61966-2.1'; - function normaliseParams( $image, &$params ) { + public function normaliseParams( $image, &$params ) { if ( !parent::normaliseParams( $image, $params ) ) { return false; } @@ -90,7 +92,7 @@ class JpegHandler extends ExifBitmapHandler { return $res; } - function getScriptParams( $params ) { + protected function getScriptParams( $params ) { $res = parent::getScriptParams( $params ); if ( isset( $params['quality'] ) ) { $res['quality'] = $params['quality']; @@ -98,7 +100,7 @@ class JpegHandler extends ExifBitmapHandler { return $res; } - function getMetadata( $image, $filename ) { + public function getMetadata( $image, $filename ) { try { $meta = BitmapMetadataHandler::Jpeg( $filename ); if ( !is_array( $meta ) ) { @@ -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; @@ -232,7 +240,7 @@ class JpegHandler extends ExifBitmapHandler { * @return bool */ public function swapICCProfile( $filepath, array $colorSpaces, - array $oldProfileStrings, $profileFilepath + array $oldProfileStrings, $profileFilepath ) { global $wgExiftool; @@ -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; }