Replace deprecated function wfEscapeShellArg with Shell::escape()
Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4
This commit is contained in:
parent
603740b43b
commit
84292b7728
19 changed files with 73 additions and 45 deletions
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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 ] );
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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" );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Shell\Shell;
|
||||
|
||||
require __DIR__ . '/../Maintenance.php';
|
||||
|
||||
class HHVMMakeRepo extends Maintenance {
|
||||
|
|
@ -103,7 +105,7 @@ class HHVMMakeRepo extends Maintenance {
|
|||
|
||||
$hhvm = $this->getOption( 'hhvm', 'hhvm' );
|
||||
$verbose = $this->getOption( 'verbose', 3 );
|
||||
$cmd = wfEscapeShellArg(
|
||||
$cmd = Shell::escape(
|
||||
$hhvm,
|
||||
'--hphp',
|
||||
'--target', 'hhbc',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/hhvm -f
|
||||
<?php
|
||||
|
||||
use MediaWiki\Shell\Shell;
|
||||
|
||||
require __DIR__ . '/../Maintenance.php';
|
||||
|
||||
class RunHipHopServer extends Maintenance {
|
||||
|
|
@ -12,8 +14,8 @@ class RunHipHopServer extends Maintenance {
|
|||
global $IP;
|
||||
|
||||
passthru(
|
||||
'cd ' . wfEscapeShellArg( $IP ) . " && " .
|
||||
wfEscapeShellArg(
|
||||
'cd ' . Shell::escape( $IP ) . " && " .
|
||||
Shell::escape(
|
||||
'hhvm',
|
||||
'-c', __DIR__."/server.conf",
|
||||
'--mode=server',
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@
|
|||
* @version first release
|
||||
*/
|
||||
|
||||
use MediaWiki\Shell\Shell;
|
||||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
/**
|
||||
|
|
@ -88,7 +90,7 @@ class MWDocGen extends Maintenance {
|
|||
|
||||
// Do not use wfShellWikiCmd, because mwdoc-filter.php is not
|
||||
// a Maintenance script.
|
||||
$this->inputFilter = wfEscapeShellArg( [
|
||||
$this->inputFilter = Shell::escape( [
|
||||
$wgPhpCli,
|
||||
$IP . '/maintenance/mwdoc-filter.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' );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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++ ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue