184 register_shutdown_function( [ $this,
'outputChanneled' ],
false );
197 if ( !function_exists(
'debug_backtrace' ) ) {
202 $bt = debug_backtrace();
203 $count = count( $bt );
207 if ( $bt[0][
'class'] !== self::class || $bt[0][
'function'] !==
'shouldExecute' ) {
210 $includeFuncs = [
'require_once',
'require',
'include',
'include_once' ];
211 for ( $i = 1; $i < $count; $i++ ) {
212 if ( !in_array( $bt[$i][
'function'], $includeFuncs ) ) {
237 return isset( $this->mParams[$name] );
251 protected function addOption( $name, $description, $required =
false,
252 $withArg =
false, $shortName =
false, $multiOccurrence =
false
254 $this->mParams[$name] = [
255 'desc' => $description,
256 'require' => $required,
257 'withArg' => $withArg,
258 'shortName' => $shortName,
259 'multiOccurrence' => $multiOccurrence
262 if ( $shortName !==
false ) {
263 $this->mShortParamsMap[$shortName] = $name;
274 return isset( $this->mOptions[$name] );
288 protected function getOption( $name, $default =
null ) {
290 return $this->mOptions[$name];
302 protected function addArg( $arg, $description, $required =
true ) {
303 $this->mArgList[] = [
305 'desc' => $description,
306 'require' => $required
315 unset( $this->mParams[$name] );
324 $this->mAllowUnregisteredOptions = $allow;
332 $this->mDescription = $text;
340 protected function hasArg( $argId = 0 ) {
341 if ( func_num_args() === 0 ) {
342 wfDeprecated( __METHOD__ .
' without an $argId',
'1.33' );
345 return isset( $this->mArgs[$argId] );
355 protected function getArg( $argId = 0, $default =
null ) {
356 if ( func_num_args() === 0 ) {
357 wfDeprecated( __METHOD__ .
' without an $argId',
'1.33' );
360 return $this->mArgs[$argId] ?? $default;
378 $this->mBatchSize =
$s;
385 if ( $this->mBatchSize ) {
386 $this->
addOption(
'batch-size',
'Run this many operations ' .
387 'per batch, default: ' . $this->mBatchSize,
false,
true );
388 if ( isset( $this->mParams[
'batch-size'] ) ) {
390 $this->mDependentParameters[
'batch-size'] = $this->mParams[
'batch-size'];
410 if ( $len == self::STDIN_ALL ) {
411 return file_get_contents(
'php://stdin' );
413 $f = fopen(
'php://stdin',
'rt' );
417 $input = fgets( $f, $len );
420 return rtrim( $input );
437 protected function output( $out, $channel =
null ) {
439 if ( class_exists( MediaWikiServices::class ) ) {
441 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
442 if ( $stats->getDataCount() > 1000 ) {
447 if ( $this->mQuiet ) {
450 if ( $channel ===
null ) {
454 $out = preg_replace(
'/\n\z/',
'', $out );
466 protected function error( $err, $die = 0 ) {
467 if ( intval( $die ) !== 0 ) {
473 ( PHP_SAPI ==
'cli' || PHP_SAPI ==
'phpdbg' ) &&
474 !defined(
'MW_PHPUNIT_TEST' )
476 fwrite( STDERR, $err .
"\n" );
492 $this->
error( $msg );
503 if ( !$this->atLineStart ) {
505 $this->atLineStart =
true;
518 if ( $msg ===
false ) {
525 if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
531 $this->atLineStart =
false;
532 if ( $channel ===
null ) {
535 $this->atLineStart =
true;
537 $this->lastChannel = $channel;
559 # Generic (non-script-dependent) options:
561 $this->
addOption(
'help',
'Display this help message',
false,
false,
'h' );
562 $this->
addOption(
'quiet',
'Whether to suppress non-error output',
false,
false,
'q' );
563 $this->
addOption(
'conf',
'Location of LocalSettings.php, if not default',
false,
true );
564 $this->
addOption(
'wiki',
'For specifying the wiki ID',
false,
true );
565 $this->
addOption(
'globals',
'Output globals at the end of processing for debugging' );
568 'Set a specific memory limit for the script, '
569 .
'"max" for no limit or "default" to avoid changing it',
573 $this->
addOption(
'server',
"The protocol and server name to use in URLs, e.g. " .
574 "http://en.wikipedia.org. This is sometimes necessary because " .
575 "server name detection may fail in command line scripts.",
false,
true );
576 $this->
addOption(
'profiler',
'Profiler output format (usually "text")',
false,
true );
578 # Save generic options to display them separately in help
581 # Script-dependent options:
585 $this->
addOption(
'dbuser',
'The DB user to use for this script',
false,
true );
586 $this->
addOption(
'dbpass',
'The password to use for this script',
false,
true );
587 $this->
addOption(
'dbgroupdefault',
'The default DB group to use.',
false,
true );
590 # Save additional script-dependent options to display
591 # them separately in help
592 $this->mDependentParameters = array_diff_key( $this->mParams, $this->mGenericParameters );
601 if ( $this->config ===
null ) {
602 $this->config = MediaWikiServices::getInstance()->getMainConfig();
626 $this->requiredExtensions[] = $name;
637 foreach ( $this->requiredExtensions as $name ) {
638 if ( !$registry->isLoaded( $name ) ) {
644 if ( count( $missing ) === 1 ) {
645 $msg =
'The "' . $missing[ 0 ] .
'" extension must be installed for this script to run. '
646 .
'Please enable it and then try again.';
648 $msg =
'The following extensions must be installed for this script to run: "'
649 . implode(
'", "', $missing ) .
'". Please enable them and then try again.';
679 require_once $classFile;
682 $this->
fatalError(
"Cannot spawn child: $maintClass" );
690 $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
691 if ( $this->mDb !==
null ) {
692 $child->setDB( $this->mDb );
704 # Abort if called from a web server
705 # wfIsCLI() is not available yet
706 if ( PHP_SAPI !==
'cli' && PHP_SAPI !==
'phpdbg' ) {
707 $this->
fatalError(
'This script must be run from the command line' );
710 if ( $IP ===
null ) {
711 $this->
fatalError(
"\$IP not set, aborting!\n" .
712 '(Did you forget to call parent::__construct() in your maintenance script?)' );
715 # Make sure we can handle script parameters
716 if ( !ini_get(
'register_argc_argv' ) ) {
717 $this->
fatalError(
'Cannot get command line arguments, register_argc_argv is set to false' );
723 if ( ini_get(
'display_errors' ) ) {
724 ini_set(
'display_errors',
'stderr' );
729 # Set the memory limit
730 # Note we need to set it again later in case LocalSettings changed it
733 # Set max execution time to 0 (no limit). PHP.net says that
734 # "When running PHP from the command line the default setting is 0."
735 # But sometimes this doesn't seem to be the case.
737 ini_set(
'max_execution_time', 0 );
741 # Turn off output buffering if it's on
742 while ( ob_get_level() > 0 ) {
758 $limit = $this->
getOption(
'memory-limit',
'max' );
759 $limit = trim( $limit,
"\" '" );
768 if ( $limit ==
'max' ) {
771 if ( $limit !=
'default' ) {
772 ini_set(
'memory_limit', $limit );
782 $output = $this->
getOption(
'profiler' );
790 $profiler =
new $class(
791 [
'sampling' => 1,
'output' => [ $output ] ]
793 + [
'threshold' => 0.0 ]
795 $profiler->setAllowOutput();
800 $trxProfiler->setLogger( LoggerFactory::getInstance(
'DBPerformance' ) );
808 $this->mOptions = [];
810 $this->mInputLoaded =
false;
823 $this->orderedOptions = [];
826 for ( $arg = reset( $argv ); $arg !==
false; $arg = next( $argv ) ) {
827 if ( $arg ==
'--' ) {
828 # End of options, remainder should be considered arguments
829 $arg = next( $argv );
830 while ( $arg !==
false ) {
832 $arg = next( $argv );
835 } elseif ( substr( $arg, 0, 2 ) ==
'--' ) {
837 $option = substr( $arg, 2 );
838 if ( isset( $this->mParams[$option] ) && $this->mParams[$option][
'withArg'] ) {
839 $param = next( $argv );
840 if ( $param ===
false ) {
841 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
845 $this->
setParam( $options, $option, $param );
847 $bits = explode(
'=', $option, 2 );
848 $this->
setParam( $options, $bits[0], $bits[1] ?? 1 );
850 } elseif ( $arg ==
'-' ) {
851 # Lonely "-", often used to indicate stdin or stdout.
853 } elseif ( substr( $arg, 0, 1 ) ==
'-' ) {
855 $argLength = strlen( $arg );
856 for ( $p = 1; $p < $argLength; $p++ ) {
858 if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
859 $option = $this->mShortParamsMap[$option];
862 if ( isset( $this->mParams[$option][
'withArg'] ) && $this->mParams[$option][
'withArg'] ) {
863 $param = next( $argv );
864 if ( $param ===
false ) {
865 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
868 $this->
setParam( $options, $option, $param );
870 $this->
setParam( $options, $option, 1 );
878 $this->mOptions = $options;
879 $this->mArgs =
$args;
881 $this->mInputLoaded =
true;
896 private function setParam( &$options, $option, $value ) {
897 $this->orderedOptions[] = [ $option, $value ];
899 if ( isset( $this->mParams[$option] ) ) {
900 $multi = $this->mParams[$option][
'multiOccurrence'];
904 $exists = array_key_exists( $option, $options );
905 if ( $multi && $exists ) {
906 $options[$option][] = $value;
907 } elseif ( $multi ) {
908 $options[$option] = [ $value ];
909 } elseif ( !$exists ) {
910 $options[$option] = $value;
912 $this->
error(
"\nERROR: $option parameter given twice\n" );
927 # If we were given opts or args, set those and return early
928 if (
$self !==
null ) {
929 $this->mSelf =
$self;
930 $this->mInputLoaded =
true;
932 if ( $opts !==
null ) {
933 $this->mOptions = $opts;
934 $this->mInputLoaded =
true;
936 if (
$args !==
null ) {
937 $this->mArgs =
$args;
938 $this->mInputLoaded =
true;
941 # If we've already loaded input (either by user values or from $argv)
942 # skip on loading it again. The array_shift() will corrupt values if
943 # it's run again and again
944 if ( $this->mInputLoaded ) {
951 $this->mSelf = $argv[0];
961 # Check to make sure we've got all the required options
962 foreach ( $this->mParams as $opt => $info ) {
963 if ( $info[
'require'] && !$this->
hasOption( $opt ) ) {
964 $this->
error(
"Param $opt required!" );
969 foreach ( $this->mArgList as $k => $info ) {
970 if ( $info[
'require'] && !$this->
hasArg( $k ) ) {
971 $this->
error(
'Argument <' . $info[
'name'] .
'> required!' );
975 if ( !$this->mAllowUnregisteredOptions ) {
976 # Check for unexpected options
977 foreach ( $this->mOptions as $opt => $val ) {
979 $this->
error(
"Unexpected option $opt!" );
994 $this->mDbUser = $this->
getOption(
'dbuser' );
997 $this->mDbPass = $this->
getOption(
'dbpass' );
1000 $this->mQuiet =
true;
1002 if ( $this->
hasOption(
'batch-size' ) ) {
1003 $this->mBatchSize = intval( $this->
getOption(
'batch-size' ) );
1013 if ( !$force && !$this->
hasOption(
'help' ) ) {
1026 $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
1028 ksort( $this->mParams );
1029 $this->mQuiet =
false;
1032 if ( $this->mDescription ) {
1033 $this->
output(
"\n" . wordwrap( $this->mDescription, $screenWidth ) .
"\n" );
1035 $output =
"\nUsage: php " . basename( $this->mSelf );
1038 if ( $this->mParams ) {
1039 $output .=
" [--" . implode(
"|--", array_keys( $this->mParams ) ) .
"]";
1043 if ( $this->mArgList ) {
1045 foreach ( $this->mArgList as $k => $arg ) {
1046 if ( $arg[
'require'] ) {
1047 $output .=
'<' . $arg[
'name'] .
'>';
1049 $output .=
'[' . $arg[
'name'] .
']';
1051 if ( $k < count( $this->mArgList ) - 1 ) {
1056 $this->
output(
"$output\n\n" );
1059 $this->mGenericParameters,
1060 'Generic maintenance parameters',
1065 $this->mDependentParameters,
1066 'Script dependent parameters',
1072 $scriptSpecificParams = array_diff_key(
1073 # all script parameters:
1076 $this->mGenericParameters,
1077 $this->mDependentParameters
1081 $scriptSpecificParams,
1082 'Script specific parameters',
1087 if ( count( $this->mArgList ) > 0 ) {
1088 $this->
output(
"Arguments:\n" );
1090 foreach ( $this->mArgList as $info ) {
1091 $openChar = $info[
'require'] ?
'<' :
'[';
1092 $closeChar = $info[
'require'] ?
'>' :
']';
1095 "$tab$openChar" . $info[
'name'] .
"$closeChar: " . $info[
'desc'],
1106 if ( $items === [] ) {
1110 $this->
output(
"$heading:\n" );
1112 foreach ( $items as $name => $info ) {
1113 if ( $info[
'shortName'] !==
false ) {
1114 $name .=
' (-' . $info[
'shortName'] .
')';
1118 "$tab--$name: " . strtr( $info[
'desc'], [
"\n" =>
"\n$tab$tab" ] ),
1136 if ( !$settingsBuilder ) {
1141 $settingsBuilder = $GLOBALS[
'wgSettings'];
1144 $config = $settingsBuilder->getConfig();
1146 $overrides[
'DBadminuser'] =
$config->
get( MainConfigNames::DBadminuser );
1147 $overrides[
'DBadminpassword'] =
$config->
get( MainConfigNames::DBadminpassword );
1149 # Turn off output buffering again, it might have been turned on in the settings files
1150 if ( ob_get_level() ) {
1154 $overrides[
'CommandLineMode'] =
true;
1156 # Override $wgServer
1158 $overrides[
'Server'] = $this->
getOption(
'server',
$config->
get( MainConfigNames::Server ) );
1161 # If these were passed, use them
1162 if ( $this->mDbUser ) {
1165 if ( $this->mDbPass ) {
1168 if ( $this->
hasOption(
'dbgroupdefault' ) ) {
1169 $overrides[
'DBDefaultGroup'] = $this->
getOption(
'dbgroupdefault',
null );
1174 if ( MediaWikiServices::hasInstance() ) {
1175 $service = MediaWikiServices::getInstance()->peekService(
'DBLoadBalancerFactory' );
1177 $service->destroy();
1182 if ( $this->
getDbType() == self::DB_ADMIN && isset( $overrides[
'DBadminuser' ] ) ) {
1183 $overrides[
'DBuser'] = $overrides[
'DBadminuser' ];
1184 $overrides[
'DBpassword'] = $overrides[
'DBadminpassword' ];
1187 $dbServers =
$config->
get( MainConfigNames::DBservers );
1189 foreach ( $dbServers as $i => $server ) {
1190 $dbServers[$i][
'user'] = $overrides[
'DBuser'];
1191 $dbServers[$i][
'password'] = $overrides[
'DBpassword'];
1193 $overrides[
'DBservers'] = $dbServers;
1196 $lbFactoryConf =
$config->
get( MainConfigNames::LBFactoryConf );
1197 if ( isset( $lbFactoryConf[
'serverTemplate'] ) ) {
1198 $lbFactoryConf[
'serverTemplate'][
'user'] = $overrides[
'DBuser'];
1199 $lbFactoryConf[
'serverTemplate'][
'password'] = $overrides[
'DBpassword'];
1200 $overrides[
'LBFactoryConf'] = $lbFactoryConf;
1207 if ( MediaWikiServices::hasInstance() ) {
1208 $service = MediaWikiServices::getInstance()->peekService(
'DBLoadBalancerFactory' );
1210 $service->destroy();
1220 $overrides[
'ShowExceptionDetails'] =
true;
1221 $overrides[
'ShowHostname'] =
true;
1224 'max_execution_time' => 0,
1229 $settingsBuilder->loadArray( [
'config' => $overrides,
'php-ini' => $ini ] );
1245 print_r( $GLOBALS );
1263 !MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancerFactory' )
1265 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1266 if ( $lbFactory->isReadyForRoundOperations() ) {
1267 $lbFactory->commitPrimaryChanges( get_class( $this ) );
1276 $profiler->logData();
1279 MediaWikiServices::getInstance()->getStatsdDataFactory(),
1284 if ( $lbFactory->isReadyForRoundOperations() ) {
1285 $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
1297 if ( isset( $this->mOptions[
'conf'] ) ) {
1301 define(
'MW_CONFIG_FILE', $this->mOptions[
'conf'] );
1305 if ( isset( $this->mOptions[
'wiki'] ) ) {
1306 $wikiName = $this->mOptions[
'wiki'];
1307 $bits = explode(
'-', $wikiName, 2 );
1308 define(
'MW_DB', $bits[0] );
1309 define(
'MW_PREFIX', $bits[1] ??
'' );
1310 define(
'MW_WIKI_NAME', $wikiName );
1311 } elseif ( isset( $this->mOptions[
'server'] ) ) {
1316 $_SERVER[
'SERVER_NAME'] = $this->mOptions[
'server'];
1319 if ( !is_readable( $settingsFile ) ) {
1320 $this->
fatalError(
"The file $settingsFile must exist and be readable.\n" .
1321 "Use --conf to specify it." );
1323 $wgCommandLineMode =
true;
1325 return $settingsFile;
1334 # Data should come off the master, wrapped in a transaction
1338 # Get "active" text records via the content table
1340 $this->
output(
'Searching for active text records via contents table...' );
1341 $res = $dbw->select(
'content',
'content_address', [], __METHOD__, [
'DISTINCT' ] );
1342 $blobStore = MediaWikiServices::getInstance()->getBlobStore();
1343 foreach (
$res as $row ) {
1345 $textId = $blobStore->getTextIdFromAddress( $row->content_address );
1350 $this->
output(
"done.\n" );
1352 # Get the IDs of all text records not in these sets
1353 $this->
output(
'Searching for inactive text records...' );
1354 $cond =
'old_id NOT IN ( ' . $dbw->makeList( $cur ) .
' )';
1355 $res = $dbw->select(
'text',
'old_id', [ $cond ], __METHOD__, [
'DISTINCT' ] );
1357 foreach (
$res as $row ) {
1358 $old[] = $row->old_id;
1360 $this->
output(
"done.\n" );
1362 # Inform the user of what we're going to do
1363 $count = count( $old );
1364 $this->
output(
"$count inactive items found.\n" );
1366 # Delete as appropriate
1367 if ( $delete && $count ) {
1368 $this->
output(
'Deleting...' );
1369 $dbw->delete(
'text', [
'old_id' => $old ], __METHOD__ );
1370 $this->
output(
"done.\n" );
1381 return __DIR__ .
'/../';
1398 protected function getDB( $db, $groups = [], $dbDomain =
false ) {
1399 if ( $this->mDb ===
null ) {
1400 return MediaWikiServices::getInstance()
1401 ->getDBLoadBalancerFactory()
1402 ->getMainLB( $dbDomain )
1403 ->getMaintenanceConnectionRef( $db, $groups, $dbDomain );
1430 $dbw->
begin( $fname );
1456 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1457 $waitSucceeded = $lbFactory->waitForReplication(
1458 [
'timeout' => 30,
'ifWritesSince' => $this->lastReplicationWait ]
1460 $this->lastReplicationWait = microtime(
true );
1461 return $waitSucceeded;
1492 for ( $i = $seconds; $i >= 0; $i-- ) {
1493 if ( $i != $seconds ) {
1494 $this->
output( str_repeat(
"\x08", strlen( (
string)( $i + 1 ) ) ) );
1496 $this->
output( (
string)$i );
1513 if ( !function_exists(
'posix_isatty' ) ) {
1526 static $isatty =
null;
1527 if ( $isatty ===
null ) {
1531 if ( $isatty && function_exists(
'readline' ) ) {
1532 return readline( $prompt );
1537 } elseif ( feof( STDIN ) ) {
1540 $st = fgets( STDIN, 1024 );
1542 if ( $st ===
false ) {
1557 $encPrompt = Shell::escape( $prompt );
1558 $command =
"read -er -p $encPrompt && echo \"\$REPLY\"";
1559 $result = Shell::command( $bash,
'-c',
$command )
1564 if ( $result->getExitCode() == 0 ) {
1565 return $result->getStdout();
1568 if ( $result->getExitCode() == 127 ) {
1579 if ( feof( STDIN ) ) {
1584 return fgets( STDIN, 1024 );
1595 static $termSize =
null;
1597 if ( $termSize !==
null ) {
1601 $default = [ 80, 50 ];
1604 $termSize = $default;
1616 $result = Shell::command(
'stty',
'size' )->passStdin()->execute();
1617 if ( $result->getExitCode() !== 0 ||
1618 !preg_match(
'/^(\d+) (\d+)$/', $result->getStdout(), $m )
1620 $termSize = $default;
1625 $termSize = [ intval( $m[2] ), intval( $m[1] ) ];
1635 require_once __DIR__ .
'/../../tests/common/TestsAutoLoader.php';
1645 if ( !$this->hookContainer ) {
1646 $this->hookContainer = MediaWikiServices::getInstance()->getHookContainer();
1660 if ( !$this->hookRunner ) {
1677 $ids = preg_split(
'/[\s,;:|]+/', $text );
1679 static function ( $id ) {
1684 return array_filter( $ids );
1699 } elseif ( $this->
hasOption(
"userid" ) ) {
1704 if ( !$user || !$user->getId() ) {
1707 } elseif ( $this->
hasOption(
"userid" ) ) {
wfDetectLocalSettingsFile(?string $installationPath=null)
Decide and remember where to load LocalSettings from.
array $wgProfiler
Variable for the Profiler setting, for use in LocalSettings.php.
array $wgTrxProfilerLimits
Variable for the TrxProfilerLimits setting, for use in LocalSettings.php.
global $wgCommandLineMode
wfIsWindows()
Check if the operating system is Windows.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined( 'MEDIAWIKI')) if(ini_get( 'mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
static doUpdates( $mode='run', $stage=self::ALL)
Consume and execute all pending updates.
static findInDefaultPaths( $names, $versionInfo=false)
Same as locateExecutable(), but checks in getPossibleBinPaths() by default.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
setup()
Do some checking and basic setup.
array[] $mParams
Array of desired/allowed params.
__construct()
Default constructor.
error( $err, $die=0)
Throw an error to the user.
getName()
Get the script's name.
array[] $mGenericParameters
Generic options added by addDefaultParams()
addArg( $arg, $description, $required=true)
Add some args that are needed.
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
showHelp()
Definitely show the help.
int null $mBatchSize
Batch size.
setAgentAndTriggers()
This method used to be for internal use by doMaintenance.php to apply some optional global state to L...
setAllowUnregisteredOptions( $allow)
Sets whether to allow unregistered options, which are options passed to a script that do not match an...
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB.
static getTermSize()
Get the terminal size as a two-element array where the first element is the width (number of columns)...
HookContainer null $hookContainer
clearParamsAndArgs()
Clear all params and arguments.
array $requiredExtensions
setParam(&$options, $option, $value)
Helper function used solely by loadParamsAndArgs to prevent code duplication.
const DB_NONE
Constants for DB access type.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
supportsOption( $name)
Checks to see if a particular option in supported.
array[] $mDependentParameters
Generic options which might or not be supported by the script.
getStdin( $len=null)
Return input from stdin.
cleanupChanneled()
Clean up channeled output.
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
array $mArgList
Desired/allowed args.
getHookRunner()
Get a HookRunner for running core hooks.
afterFinalSetup()
Override to perform any required operation at the end of initialisation.
finalSetup(SettingsBuilder $settingsBuilder=null)
Handle some last-minute setup here.
hasArg( $argId=0)
Does a given argument exist?
getDir()
Get the maintenance directory.
addDefaultParams()
Add the default parameters to the scripts.
bool $mInputLoaded
Have we already loaded our user input?
deleteOption( $name)
Remove an option.
static readlineEmulation( $prompt)
Emulate readline()
static requireTestsAutoloader()
Call this to set up the autoloader to allow classes to be used from the tests directory.
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
waitForReplication()
Wait for replica DBs to catch up.
outputChanneled( $msg, $channel=null)
Message outputter with channeled message support.
resource null $fileHandle
Used when creating separate schema files.
loadSpecialVars()
Handle the special variables that are global to all scripts @stable to override.
setDB(IMaintainableDatabase $db)
Sets database object to be returned by getDB().
float $lastReplicationWait
UNIX timestamp.
array $orderedOptions
Used to read the options in the order they were passed.
loadSettings()
Generic setup for most installs.
Config null $config
Accessible via getConfig()
hasOption( $name)
Checks to see if a particular option was set.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
IMaintainableDatabase null $mDb
Used by getDB() / setDB()
array $mOptions
This is the list of options that were actually passed.
execute()
Do the actual work.
static readconsole( $prompt='> ')
Prompt the console for input.
static posix_isatty( $fd)
Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but trea...
adjustMemoryLimit()
Adjusts PHP's memory limit to better suit our needs, if needed.
validateParamsAndArgs()
Run some validation checks on the params, etc.
getHookContainer()
Get a HookContainer, for running extension hooks or for hook metadata.
HookRunner null $hookRunner
validateUserOption( $errorMsg)
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
getBatchSize()
Returns batch size.
bool $mQuiet
Special vars for params that are always used.
parseIntList( $text)
Utility function to parse a string (perhaps from a command line option) into a list of integers (perh...
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
activateProfiler()
Activate the profiler (assuming $wgProfiler is set)
shutdown()
Call before exiting CLI process for the last DB commit, and flush any remaining buffers and other def...
maybeHelp( $force=false)
Maybe show the help.
bool $mAllowUnregisteredOptions
Allow arbitrary options to be passed, or only specified ones?
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
string null $mSelf
Name of the script currently running.
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
getOption( $name, $default=null)
Get an option, or return the default.
array $mShortParamsMap
Mapping short parameters to long ones.
checkRequiredExtensions()
Verify that the required extensions are installed.
rollbackTransaction(IDatabase $dbw, $fname)
Rollback the transaction on a DB handle.
string $mDescription
A description of the script, children should change this via addDescription()
globals()
Potentially debug globals.
setConfig(Config $config)
array $mArgs
This is the list of arguments that were actually passed.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
formatHelpItems(array $items, $heading, $descWidth, $tab)
A class containing constants representing the names of configuration variables.
static replaceStubInstance(Profiler $profiler)
Replace the current profiler with $profiler if no non-stub profiler is set.
static instance()
Singleton.
static newFromName( $name, $validate='valid')
static newFromId( $id)
Static factory method for creation from a given user ID.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
Advanced database interface for IDatabase handles that include maintenance methods.
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s