X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FMaintenance.php;h=44ce9a5d186a2ec2cf09311e14f9021577b44c79;hb=63f1b4ee690d7ea2d40c7e0873a24a4cb5bd60ff;hp=b3e958f745ce3c659672575ba7821642a5857cbd;hpb=2dc4c97a00ca9b7d20f0104b3d975e8dbdb0a18e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index b3e958f745..44ce9a5d18 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -42,6 +42,13 @@ define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless $maintClass = false; +// Some extensions rely on MW_INSTALL_PATH to find core files to include. Setting it here helps them +// if they're included by a core script (like DatabaseUpdater) after Maintenance.php has already +// been run. +if ( strval( getenv( 'MW_INSTALL_PATH' ) ) === '' ) { + putenv( 'MW_INSTALL_PATH=' . realpath( __DIR__ . '/..' ) ); +} + use Wikimedia\Rdbms\IDatabase; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; @@ -171,11 +178,8 @@ abstract class Maintenance { * their own constructors */ public function __construct() { - // Setup $IP, using MW_INSTALL_PATH if it exists global $IP; - $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== '' - ? getenv( 'MW_INSTALL_PATH' ) - : realpath( __DIR__ . '/..' ); + $IP = getenv( 'MW_INSTALL_PATH' ); $this->addDefaultParams(); register_shutdown_function( [ $this, 'outputChanneled' ], false ); @@ -336,6 +340,10 @@ abstract class Maintenance { * @return bool */ protected function hasArg( $argId = 0 ) { + if ( func_num_args() === 0 ) { + wfDeprecated( __METHOD__ . ' without an $argId', '1.33' ); + } + return isset( $this->mArgs[$argId] ); } @@ -346,7 +354,11 @@ abstract class Maintenance { * @return mixed */ protected function getArg( $argId = 0, $default = null ) { - return $this->hasArg( $argId ) ? $this->mArgs[$argId] : $default; + if ( func_num_args() === 0 ) { + wfDeprecated( __METHOD__ . ' without an $argId', '1.33' ); + } + + return $this->mArgs[$argId] ?? $default; } /** @@ -709,7 +721,7 @@ abstract class Maintenance { } /** - * @var $child Maintenance + * @var Maintenance $child */ $child = new $maintClass(); $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs ); @@ -1183,7 +1195,7 @@ abstract class Maintenance { if ( $wgDBservers ) { /** - * @var $wgDBservers array + * @var array $wgDBservers */ foreach ( $wgDBservers as $i => $server ) { $wgDBservers[$i]['user'] = $wgDBuser; @@ -1607,10 +1619,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;