X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=blobdiff_plain;f=maintenance%2FMaintenance.php;h=9685177b96ba144e7034ed014482d9f69abf5801;hb=e2f61aa44095d56af0d4b25a59e25b55a6c297bc;hp=617071b25fc2b680e39613cdf780b0b95f4bbf8f;hpb=261e5e64a582b91e672854e24d6d01d66d0d3fdb;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 617071b25f..9685177b96 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -25,6 +25,7 @@ require_once __DIR__ . '/../includes/PHPVersionCheck.php'; wfEntryPointCheck( 'cli' ); +use MediaWiki\Shell\Shell; use Wikimedia\Rdbms\DBReplicationWaitError; /** @@ -508,12 +509,16 @@ abstract class Maintenance { $this->addOption( 'memory-limit', 'Set a specific memory limit for the script, ' - . '"max" for no limit or "default" to avoid changing it' + . '"max" for no limit or "default" to avoid changing it', + false, + true ); $this->addOption( 'server', "The protocol and server name to use in URLs, e.g. " . "http://en.wikipedia.org. This is sometimes necessary because " . "server name detection may fail in command line scripts.", false, true ); $this->addOption( 'profiler', 'Profiler output format (usually "text")', false, true ); + // This is named --mwdebug, because --debug would conflict in the phpunit.php CLI script. + $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, true ); # Save generic options to display them separately in help $this->mGenericParameters = $this->mParams; @@ -676,7 +681,7 @@ abstract class Maintenance { * Do some sanity checking and basic setup */ public function setup() { - global $IP, $wgCommandLineMode, $wgRequestTime; + global $IP, $wgCommandLineMode; # Abort if called from a web server # wfIsCLI() is not available yet @@ -713,8 +718,6 @@ abstract class Maintenance { # But sometimes this doesn't seem to be the case. ini_set( 'max_execution_time', 0 ); - $wgRequestTime = microtime( true ); - # Define us as being in MediaWiki define( 'MEDIAWIKI', true ); @@ -1009,7 +1012,7 @@ abstract class Maintenance { // ... append parameters ... if ( $this->mParams ) { - $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]"; + $output .= " [--" . implode( "|--", array_keys( $this->mParams ) ) . "]"; } // ... and append arguments. @@ -1149,6 +1152,11 @@ abstract class Maintenance { MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy(); } + # Apply debug settings + if ( $this->hasOption( 'mwdebug' ) ) { + require __DIR__ . '/../includes/DevelopmentSettings.php'; + } + // Per-script profiling; useful for debugging $this->activateProfiler(); @@ -1287,7 +1295,7 @@ abstract class Maintenance { * This function has the same parameters as wfGetDB() * * @param int $db DB index (DB_REPLICA/DB_MASTER) - * @param array $groups default: empty array + * @param string|string[] $groups default: empty array * @param string|bool $wiki default: current wiki * @return IMaintainableDatabase */ @@ -1587,12 +1595,12 @@ abstract class Maintenance { // something that can do the relevant syscalls. There are a few // options. Linux and Mac OS X both have "stty size" which does the // job directly. - $retval = false; - $size = wfShellExec( 'stty size', $retval ); - if ( $retval !== 0 ) { + $result = Shell::command( 'stty', 'size' ) + ->execute(); + if ( $result->getExitCode() !== 0 ) { return $default; } - if ( !preg_match( '/^(\d+) (\d+)$/', $size, $m ) ) { + if ( !preg_match( '/^(\d+) (\d+)$/', $result->getStdout(), $m ) ) { return $default; } return [ intval( $m[2] ), intval( $m[1] ) ];