From 84292b772882f114c3e3750fe025f067117f4e57 Mon Sep 17 00:00:00 2001 From: Derick Alangi Date: Sun, 7 Apr 2019 12:36:22 +0100 Subject: [PATCH] Replace deprecated function wfEscapeShellArg with Shell::escape() Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4 --- includes/GlobalFunctions.php | 2 +- includes/export/Dump7ZipOutput.php | 6 ++++-- includes/export/DumpPipeOutput.php | 6 ++++-- includes/media/BitmapHandler.php | 20 ++++++++++--------- includes/media/DjVuHandler.php | 5 +++-- includes/media/DjVuImage.php | 10 ++++++---- includes/media/SvgHandler.php | 8 +++++--- .../media/TransformationalImageHandler.php | 3 ++- .../resourceloader/ResourceLoaderImage.php | 4 +++- includes/upload/UploadBase.php | 5 +++-- maintenance/7zip.inc | 4 +++- maintenance/Maintenance.php | 6 +++--- maintenance/dumpTextPass.php | 5 +++-- maintenance/hhvm/makeRepo.php | 4 +++- maintenance/hhvm/run-server | 6 ++++-- maintenance/mwdocgen.php | 4 +++- maintenance/populateImageSha1.php | 8 +++++--- maintenance/storage/checkStorage.php | 3 ++- maintenance/storage/recompressTracked.php | 9 +++++---- 19 files changed, 73 insertions(+), 45 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b0a79e8d5c..cdbc27a9e9 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2136,7 +2136,7 @@ function wfStringToBool( $val ) { * @param string|string[] ...$args strings to escape and glue together, * or a single array of strings parameter * @return string - * @deprecated since 1.30 use MediaWiki\Shell::escape() + * @deprecated since 1.30 use MediaWiki\Shell\Shell::escape() */ function wfEscapeShellArg( ...$args ) { return Shell::escape( ...$args ); diff --git a/includes/export/Dump7ZipOutput.php b/includes/export/Dump7ZipOutput.php index 31c945c05e..a50150e085 100644 --- a/includes/export/Dump7ZipOutput.php +++ b/includes/export/Dump7ZipOutput.php @@ -23,6 +23,8 @@ * @file */ +use MediaWiki\Shell\Shell; + /** * @ingroup Dump */ @@ -49,8 +51,8 @@ class Dump7ZipOutput extends DumpPipeOutput { */ function setup7zCommand( $file ) { $command = "7za a -bd -si -mx="; - $command .= wfEscapeShellArg( $this->compressionLevel ) . ' '; - $command .= wfEscapeShellArg( $file ); + $command .= Shell::escape( $this->compressionLevel ) . ' '; + $command .= Shell::escape( $file ); // Suppress annoying useless crap from p7zip // Unfortunately this could suppress real error messages too $command .= ' >' . wfGetNull() . ' 2>&1'; diff --git a/includes/export/DumpPipeOutput.php b/includes/export/DumpPipeOutput.php index 26010dae9e..a353c44761 100644 --- a/includes/export/DumpPipeOutput.php +++ b/includes/export/DumpPipeOutput.php @@ -25,6 +25,8 @@ * @file */ +use MediaWiki\Shell\Shell; + /** * @ingroup Dump */ @@ -38,7 +40,7 @@ class DumpPipeOutput extends DumpFileOutput { */ function __construct( $command, $file = null ) { if ( !is_null( $file ) ) { - $command .= " > " . wfEscapeShellArg( $file ); + $command .= " > " . Shell::escape( $file ); } $this->startCommand( $command ); @@ -94,7 +96,7 @@ class DumpPipeOutput extends DumpFileOutput { $this->renameOrException( $newname ); if ( $open ) { $command = $this->command; - $command .= " > " . wfEscapeShellArg( $this->filename ); + $command .= " > " . Shell::escape( $this->filename ); $this->startCommand( $command ); } } diff --git a/includes/media/BitmapHandler.php b/includes/media/BitmapHandler.php index f003554727..2d1c3b2b51 100644 --- a/includes/media/BitmapHandler.php +++ b/includes/media/BitmapHandler.php @@ -21,6 +21,8 @@ * @ingroup Media */ +use MediaWiki\Shell\Shell; + /** * Generic handler for bitmap images * @@ -228,7 +230,7 @@ class BitmapHandler extends TransformationalImageHandler { $rotation = isset( $params['disableRotation'] ) ? 0 : $this->getRotation( $image ); list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation ); - $cmd = wfEscapeShellArg( ...array_merge( + $cmd = Shell::escape( ...array_merge( [ $wgImageMagickConvertCommand ], $quality, // Specify white background color, will be used for transparent images @@ -373,12 +375,12 @@ class BitmapHandler extends TransformationalImageHandler { global $wgCustomConvertCommand; # Variables: %s %d %w %h - $src = wfEscapeShellArg( $params['srcPath'] ); - $dst = wfEscapeShellArg( $params['dstPath'] ); + $src = Shell::escape( $params['srcPath'] ); + $dst = Shell::escape( $params['dstPath'] ); $cmd = $wgCustomConvertCommand; $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames - $cmd = str_replace( '%h', wfEscapeShellArg( $params['physicalHeight'] ), - str_replace( '%w', wfEscapeShellArg( $params['physicalWidth'] ), $cmd ) ); # Size + $cmd = str_replace( '%h', Shell::escape( $params['physicalHeight'] ), + str_replace( '%w', Shell::escape( $params['physicalWidth'] ), $cmd ) ); # Size wfDebug( __METHOD__ . ": Running custom convert command $cmd\n" ); $retval = 0; $err = wfShellExecWithStderr( $cmd, $retval ); @@ -569,10 +571,10 @@ class BitmapHandler extends TransformationalImageHandler { $scaler = $this->getScalerType( null, false ); switch ( $scaler ) { case 'im': - $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) . " " . - wfEscapeShellArg( $this->escapeMagickInput( $params['srcPath'], $scene ) ) . - " -rotate " . wfEscapeShellArg( "-$rotation" ) . " " . - wfEscapeShellArg( $this->escapeMagickOutput( $params['dstPath'] ) ); + $cmd = Shell::escape( $wgImageMagickConvertCommand ) . " " . + Shell::escape( $this->escapeMagickInput( $params['srcPath'], $scene ) ) . + " -rotate " . Shell::escape( "-$rotation" ) . " " . + Shell::escape( $this->escapeMagickOutput( $params['dstPath'] ) ); wfDebug( __METHOD__ . ": running ImageMagick: $cmd\n" ); $retval = 0; $err = wfShellExecWithStderr( $cmd, $retval ); diff --git a/includes/media/DjVuHandler.php b/includes/media/DjVuHandler.php index a0e7f2caee..3b904e8418 100644 --- a/includes/media/DjVuHandler.php +++ b/includes/media/DjVuHandler.php @@ -21,6 +21,7 @@ * @ingroup Media */ use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; /** * Handler for DjVu images @@ -204,7 +205,7 @@ class DjVuHandler extends ImageHandler { # Use a subshell (brackets) to aggregate stderr from both pipeline commands # before redirecting it to the overall stdout. This works in both Linux and Windows XP. - $cmd = '(' . wfEscapeShellArg( + $cmd = '(' . Shell::escape( $wgDjvuRenderer, "-format=ppm", "-page={$page}", @@ -213,7 +214,7 @@ class DjVuHandler extends ImageHandler { if ( $wgDjvuPostProcessor ) { $cmd .= " | {$wgDjvuPostProcessor}"; } - $cmd .= ' > ' . wfEscapeShellArg( $dstPath ) . ') 2>&1'; + $cmd .= ' > ' . Shell::escape( $dstPath ) . ') 2>&1'; wfDebug( __METHOD__ . ": $cmd\n" ); $retval = ''; $err = wfShellExec( $cmd, $retval ); diff --git a/includes/media/DjVuImage.php b/includes/media/DjVuImage.php index 35cbc434e9..7189179db5 100644 --- a/includes/media/DjVuImage.php +++ b/includes/media/DjVuImage.php @@ -24,6 +24,8 @@ * @ingroup Media */ +use MediaWiki\Shell\Shell; + /** * Support for detecting/validating DjVu image files and getting * some basic file metadata (resolution etc) @@ -253,19 +255,19 @@ class DjVuImage { if ( isset( $wgDjvuDump ) ) { # djvudump is faster as of version 3.5 # https://sourceforge.net/p/djvu/bugs/71/ - $cmd = wfEscapeShellArg( $wgDjvuDump ) . ' ' . wfEscapeShellArg( $this->mFilename ); + $cmd = Shell::escape( $wgDjvuDump ) . ' ' . Shell::escape( $this->mFilename ); $dump = wfShellExec( $cmd ); $xml = $this->convertDumpToXML( $dump ); } elseif ( isset( $wgDjvuToXML ) ) { - $cmd = wfEscapeShellArg( $wgDjvuToXML ) . ' --without-anno --without-text ' . - wfEscapeShellArg( $this->mFilename ); + $cmd = Shell::escape( $wgDjvuToXML ) . ' --without-anno --without-text ' . + Shell::escape( $this->mFilename ); $xml = wfShellExec( $cmd ); } else { $xml = null; } # Text layer if ( isset( $wgDjvuTxt ) ) { - $cmd = wfEscapeShellArg( $wgDjvuTxt ) . ' --detail=page ' . wfEscapeShellArg( $this->mFilename ); + $cmd = Shell::escape( $wgDjvuTxt ) . ' --detail=page ' . Shell::escape( $this->mFilename ); wfDebug( __METHOD__ . ": $cmd\n" ); $retval = ''; $txt = wfShellExec( $cmd, $retval, [], [ 'memory' => self::DJVUTXT_MEMORY_LIMIT ] ); diff --git a/includes/media/SvgHandler.php b/includes/media/SvgHandler.php index 4d75d04449..bdda674f0d 100644 --- a/includes/media/SvgHandler.php +++ b/includes/media/SvgHandler.php @@ -20,6 +20,8 @@ * @file * @ingroup Media */ + +use MediaWiki\Shell\Shell; use Wikimedia\ScopedCallback; /** @@ -335,11 +337,11 @@ class SvgHandler extends ImageHandler { // External command $cmd = str_replace( [ '$path/', '$width', '$height', '$input', '$output' ], - [ $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "", + [ $wgSVGConverterPath ? Shell::escape( "$wgSVGConverterPath/" ) : "", intval( $width ), intval( $height ), - wfEscapeShellArg( $srcPath ), - wfEscapeShellArg( $dstPath ) ], + Shell::escape( $srcPath ), + Shell::escape( $dstPath ) ], $wgSVGConverters[$wgSVGConverter] ); diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index 38dc3905b9..dbeca0be38 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -26,6 +26,7 @@ * @ingroup Media */ use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; /** * Handler for images that need to be transformed @@ -517,7 +518,7 @@ abstract class TransformationalImageHandler extends ImageHandler { function () use ( $method ) { global $wgImageMagickConvertCommand; - $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) . ' -version'; + $cmd = Shell::escape( $wgImageMagickConvertCommand ) . ' -version'; wfDebug( $method . ": Running convert -version\n" ); $retval = ''; $return = wfShellExecWithStderr( $cmd, $retval ); diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index d10be12fe3..27fa5adcf5 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\Shell\Shell; + /** * Class encapsulating an image used in a ResourceLoaderImageModule. * @@ -373,7 +375,7 @@ class ResourceLoaderImage { if ( strpos( $wgSVGConverter, 'rsvg' ) === 0 ) { $command = 'rsvg-convert'; if ( $wgSVGConverterPath ) { - $command = wfEscapeShellArg( "$wgSVGConverterPath/" ) . $command; + $command = Shell::escape( "$wgSVGConverterPath/" ) . $command; } $process = proc_open( diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 9e92e78772..2bbe7c36e9 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -21,6 +21,7 @@ * @ingroup Upload */ use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; /** * @defgroup Upload Upload related @@ -1863,10 +1864,10 @@ abstract class UploadBase { if ( strpos( $command, "%f" ) === false ) { # simple pattern: append file to scan - $command .= " " . wfEscapeShellArg( $file ); + $command .= " " . Shell::escape( $file ); } else { # complex pattern: replace "%f" with file to scan - $command = str_replace( "%f", wfEscapeShellArg( $file ), $command ); + $command = str_replace( "%f", Shell::escape( $file ), $command ); } wfDebug( __METHOD__ . ": running virus scan: $command \n" ); diff --git a/maintenance/7zip.inc b/maintenance/7zip.inc index 9c1093becb..6a763f2e1b 100644 --- a/maintenance/7zip.inc +++ b/maintenance/7zip.inc @@ -24,6 +24,8 @@ * @ingroup Maintenance */ +use MediaWiki\Shell\Shell; + /** * Stream wrapper around 7za filter program. * Required since we can't pass an open file resource to XMLReader->open() @@ -48,7 +50,7 @@ class SevenZipStream { } else { return false; } - $arg = wfEscapeShellArg( $this->stripPath( $path ) ); + $arg = Shell::escape( $this->stripPath( $path ) ); $command = "7za $options $arg"; if ( !wfIsWindows() ) { // Suppress the stupid messages on stderr diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 6e545a69e4..0d4f14c812 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1615,10 +1615,10 @@ abstract class Maintenance { $bash = ExecutableFinder::findInDefaultPaths( 'bash' ); if ( !wfIsWindows() && $bash ) { $retval = false; - $encPrompt = wfEscapeShellArg( $prompt ); + $encPrompt = Shell::escape( $prompt ); $command = "read -er -p $encPrompt && echo \"\$REPLY\""; - $encCommand = wfEscapeShellArg( $command ); - $line = wfShellExec( "$bash -c $encCommand", $retval, [], [ 'walltime' => 0 ] ); + $encCommand = Shell::escape( $command ); + $line = Shell::escape( "$bash -c $encCommand", $retval, [], [ 'walltime' => 0 ] ); if ( $retval == 0 ) { return $line; diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 61c63e996b..7566fe0ce8 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -29,6 +29,7 @@ require_once __DIR__ . '/7zip.inc'; require_once __DIR__ . '/../includes/export/WikiExporter.php'; use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; use MediaWiki\Storage\BlobAccessException; use MediaWiki\Storage\SqlBlobStore; use Wikimedia\Rdbms\IMaintainableDatabase; @@ -756,7 +757,7 @@ TEXT if ( file_exists( "$IP/../multiversion/MWScript.php" ) ) { $cmd = implode( " ", - array_map( 'wfEscapeShellArg', + array_map( [ Shell::class, 'escape' ], [ $this->php, "$IP/../multiversion/MWScript.php", @@ -764,7 +765,7 @@ TEXT '--wiki', wfWikiID() ] ) ); } else { $cmd = implode( " ", - array_map( 'wfEscapeShellArg', + array_map( [ Shell::class, 'escape' ], [ $this->php, "$IP/maintenance/fetchText.php", diff --git a/maintenance/hhvm/makeRepo.php b/maintenance/hhvm/makeRepo.php index a8a0c7130d..9502cdcb16 100644 --- a/maintenance/hhvm/makeRepo.php +++ b/maintenance/hhvm/makeRepo.php @@ -1,5 +1,7 @@ getOption( 'hhvm', 'hhvm' ); $verbose = $this->getOption( 'verbose', 3 ); - $cmd = wfEscapeShellArg( + $cmd = Shell::escape( $hhvm, '--hphp', '--target', 'hhbc', diff --git a/maintenance/hhvm/run-server b/maintenance/hhvm/run-server index d84e02f2f0..e1deb4c396 100755 --- a/maintenance/hhvm/run-server +++ b/maintenance/hhvm/run-server @@ -1,6 +1,8 @@ #!/usr/bin/hhvm -f inputFilter = wfEscapeShellArg( [ + $this->inputFilter = Shell::escape( [ $wgPhpCli, $IP . '/maintenance/mwdoc-filter.php' ] ); diff --git a/maintenance/populateImageSha1.php b/maintenance/populateImageSha1.php index 212a20de89..a71abb61ec 100644 --- a/maintenance/populateImageSha1.php +++ b/maintenance/populateImageSha1.php @@ -21,6 +21,8 @@ * @ingroup Maintenance */ +use MediaWiki\Shell\Shell; + require_once __DIR__ . '/Maintenance.php'; /** @@ -107,9 +109,9 @@ class PopulateImageSha1 extends LoggedUpdateMaintenance { // in the pipe buffer. This can improve performance by up to a // factor of 2. global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname; - $cmd = 'mysql -u' . wfEscapeShellArg( $wgDBuser ) . - ' -h' . wfEscapeShellArg( $wgDBserver ) . - ' -p' . wfEscapeShellArg( $wgDBpassword, $wgDBname ); + $cmd = 'mysql -u' . Shell::escape( $wgDBuser ) . + ' -h' . Shell::escape( $wgDBserver ) . + ' -p' . Shell::escape( $wgDBpassword, $wgDBname ); $this->output( "Using pipe method\n" ); $pipe = popen( $cmd, 'w' ); } diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 26d4e79787..68184ea242 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -22,6 +22,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; if ( !defined( 'MEDIAWIKI' ) ) { $optionsWithoutArgs = [ 'fix' ]; @@ -451,7 +452,7 @@ class CheckStorage { echo "Filtering XML dump...\n"; $exitStatus = 0; passthru( 'mwdumper ' . - wfEscapeShellArg( + Shell::escape( "--output=file:$filteredXmlFileName", "--filter=revlist:$revFileName", $xml diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 7f89ce9e6e..de52e7aa21 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -24,6 +24,7 @@ use MediaWiki\Logger\LegacyLogger; use MediaWiki\MediaWikiServices; +use MediaWiki\Shell\Shell; use Wikimedia\Rdbms\IDatabase; $optionsWithArgs = RecompressTracked::getOptionsWithArgs(); @@ -215,19 +216,19 @@ class RecompressTracked { * writing are all slow. */ function startReplicaProcs() { - $cmd = 'php ' . wfEscapeShellArg( __FILE__ ); + $cmd = 'php ' . Shell::escape( __FILE__ ); foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) { if ( $cmdOption == 'replica-id' ) { continue; } elseif ( in_array( $cmdOption, self::$optionsWithArgs ) && isset( $this->$classOption ) ) { - $cmd .= " --$cmdOption " . wfEscapeShellArg( $this->$classOption ); + $cmd .= " --$cmdOption " . Shell::escape( $this->$classOption ); } elseif ( $this->$classOption ) { $cmd .= " --$cmdOption"; } } $cmd .= ' --child' . - ' --wiki ' . wfEscapeShellArg( wfWikiID() ) . - ' ' . wfEscapeShellArg( ...$this->destClusters ); + ' --wiki ' . Shell::escape( wfWikiID() ) . + ' ' . Shell::escape( ...$this->destClusters ); $this->replicaPipes = $this->replicaProcs = []; for ( $i = 0; $i < $this->numProcs; $i++ ) { -- 2.20.1