182 register_shutdown_function( [ $this,
'outputChanneled' ],
false );
195 if ( !function_exists(
'debug_backtrace' ) ) {
200 $bt = debug_backtrace();
201 $count = count( $bt );
205 if ( $bt[0][
'class'] !== self::class || $bt[0][
'function'] !==
'shouldExecute' ) {
208 $includeFuncs = [
'require_once',
'require',
'include',
'include_once' ];
209 for ( $i = 1; $i < $count; $i++ ) {
210 if ( !in_array( $bt[$i][
'function'], $includeFuncs ) ) {
235 return isset( $this->mParams[$name] );
249 protected function addOption( $name, $description, $required =
false,
250 $withArg =
false, $shortName =
false, $multiOccurrence =
false
252 $this->mParams[$name] = [
253 'desc' => $description,
254 'require' => $required,
255 'withArg' => $withArg,
256 'shortName' => $shortName,
257 'multiOccurrence' => $multiOccurrence
260 if ( $shortName !==
false ) {
261 $this->mShortParamsMap[$shortName] = $name;
272 return isset( $this->mOptions[$name] );
286 protected function getOption( $name, $default =
null ) {
288 return $this->mOptions[$name];
300 protected function addArg( $arg, $description, $required =
true ) {
301 $this->mArgList[] = [
303 'desc' => $description,
304 'require' => $required
313 unset( $this->mParams[$name] );
322 $this->mAllowUnregisteredOptions = $allow;
330 $this->mDescription = $text;
338 protected function hasArg( $argId = 0 ) {
339 if ( func_num_args() === 0 ) {
340 wfDeprecated( __METHOD__ .
' without an $argId',
'1.33' );
343 return isset( $this->mArgs[$argId] );
353 protected function getArg( $argId = 0, $default =
null ) {
354 if ( func_num_args() === 0 ) {
355 wfDeprecated( __METHOD__ .
' without an $argId',
'1.33' );
358 return $this->mArgs[$argId] ?? $default;
376 $this->mBatchSize =
$s;
383 if ( $this->mBatchSize ) {
384 $this->
addOption(
'batch-size',
'Run this many operations ' .
385 'per batch, default: ' . $this->mBatchSize,
false,
true );
386 if ( isset( $this->mParams[
'batch-size'] ) ) {
388 $this->mDependentParameters[
'batch-size'] = $this->mParams[
'batch-size'];
408 if ( $len == self::STDIN_ALL ) {
409 return file_get_contents(
'php://stdin' );
411 $f = fopen(
'php://stdin',
'rt' );
415 $input = fgets( $f, $len );
418 return rtrim( $input );
435 protected function output( $out, $channel =
null ) {
437 if ( class_exists( MediaWikiServices::class ) ) {
439 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
440 if ( $stats->getDataCount() > 1000 ) {
441 MediaWiki::emitBufferedStatsdData( $stats, $this->
getConfig() );
445 if ( $this->mQuiet ) {
448 if ( $channel ===
null ) {
452 $out = preg_replace(
'/\n\z/',
'', $out );
464 protected function error( $err, $die = 0 ) {
465 if ( intval( $die ) !== 0 ) {
471 ( PHP_SAPI ==
'cli' || PHP_SAPI ==
'phpdbg' ) &&
472 !defined(
'MW_PHPUNIT_TEST' )
474 fwrite( STDERR, $err .
"\n" );
490 $this->
error( $msg );
501 if ( !$this->atLineStart ) {
503 $this->atLineStart =
true;
516 if ( $msg ===
false ) {
523 if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
529 $this->atLineStart =
false;
530 if ( $channel ===
null ) {
533 $this->atLineStart =
true;
535 $this->lastChannel = $channel;
557 # Generic (non-script-dependent) options:
559 $this->
addOption(
'help',
'Display this help message',
false,
false,
'h' );
560 $this->
addOption(
'quiet',
'Whether to suppress non-error output',
false,
false,
'q' );
561 $this->
addOption(
'conf',
'Location of LocalSettings.php, if not default',
false,
true );
562 $this->
addOption(
'wiki',
'For specifying the wiki ID',
false,
true );
563 $this->
addOption(
'globals',
'Output globals at the end of processing for debugging' );
566 'Set a specific memory limit for the script, '
567 .
'"max" for no limit or "default" to avoid changing it',
571 $this->
addOption(
'server',
"The protocol and server name to use in URLs, e.g. " .
572 "http://en.wikipedia.org. This is sometimes necessary because " .
573 "server name detection may fail in command line scripts.",
false,
true );
574 $this->
addOption(
'profiler',
'Profiler output format (usually "text")',
false,
true );
576 # Save generic options to display them separately in help
579 # Script-dependent options:
583 $this->
addOption(
'dbuser',
'The DB user to use for this script',
false,
true );
584 $this->
addOption(
'dbpass',
'The password to use for this script',
false,
true );
585 $this->
addOption(
'dbgroupdefault',
'The default DB group to use.',
false,
true );
588 # Save additional script-dependent options to display
589 # Â them separately in help
590 $this->mDependentParameters = array_diff_key( $this->mParams, $this->mGenericParameters );
599 if ( $this->config ===
null ) {
600 $this->config = MediaWikiServices::getInstance()->getMainConfig();
624 $this->requiredExtensions[] = $name;
633 $registry = ExtensionRegistry::getInstance();
635 foreach ( $this->requiredExtensions as $name ) {
636 if ( !$registry->isLoaded( $name ) ) {
642 if ( count( $missing ) === 1 ) {
643 $msg =
'The "' . $missing[ 0 ] .
'" extension must be installed for this script to run. '
644 .
'Please enable it and then try again.';
646 $msg =
'The following extensions must be installed for this script to run: "'
647 . implode(
'", "', $missing ) .
'". Please enable them and then try again.';
677 require_once $classFile;
680 $this->
fatalError(
"Cannot spawn child: $maintClass" );
688 $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
689 if ( $this->mDb !==
null ) {
690 $child->setDB( $this->mDb );
702 # Abort if called from a web server
703 # wfIsCLI() is not available yet
704 if ( PHP_SAPI !==
'cli' && PHP_SAPI !==
'phpdbg' ) {
705 $this->
fatalError(
'This script must be run from the command line' );
708 if ( $IP ===
null ) {
709 $this->
fatalError(
"\$IP not set, aborting!\n" .
710 '(Did you forget to call parent::__construct() in your maintenance script?)' );
713 # Make sure we can handle script parameters
714 if ( !ini_get(
'register_argc_argv' ) ) {
715 $this->
fatalError(
'Cannot get command line arguments, register_argc_argv is set to false' );
721 if ( ini_get(
'display_errors' ) ) {
722 ini_set(
'display_errors',
'stderr' );
727 # Set the memory limit
728 # Note we need to set it again later in cache LocalSettings changed it
731 # Set max execution time to 0 (no limit). PHP.net says that
732 # "When running PHP from the command line the default setting is 0."
733 # But sometimes this doesn't seem to be the case.
734 ini_set(
'max_execution_time', 0 );
738 # Turn off output buffering if it's on
739 while ( ob_get_level() > 0 ) {
755 $limit = $this->
getOption(
'memory-limit',
'max' );
756 $limit = trim( $limit,
"\" '" );
765 if ( $limit ==
'max' ) {
768 if ( $limit !=
'default' ) {
769 ini_set(
'memory_limit', $limit );
779 $output = $this->
getOption(
'profiler' );
787 $profiler =
new $class(
788 [
'sampling' => 1,
'output' => [ $output ] ]
790 + [
'threshold' => 0.0 ]
792 $profiler->setAllowOutput();
793 Profiler::replaceStubInstance( $profiler );
796 $trxProfiler = Profiler::instance()->getTransactionProfiler();
797 $trxProfiler->setLogger( LoggerFactory::getInstance(
'DBPerformance' ) );
805 $this->mOptions = [];
807 $this->mInputLoaded =
false;
820 $this->orderedOptions = [];
823 for ( $arg = reset( $argv ); $arg !==
false; $arg = next( $argv ) ) {
824 if ( $arg ==
'--' ) {
825 # End of options, remainder should be considered arguments
826 $arg = next( $argv );
827 while ( $arg !==
false ) {
829 $arg = next( $argv );
832 } elseif ( substr( $arg, 0, 2 ) ==
'--' ) {
834 $option = substr( $arg, 2 );
835 if ( isset( $this->mParams[$option] ) && $this->mParams[$option][
'withArg'] ) {
836 $param = next( $argv );
837 if ( $param ===
false ) {
838 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
842 $this->
setParam( $options, $option, $param );
844 $bits = explode(
'=', $option, 2 );
845 $this->
setParam( $options, $bits[0], $bits[1] ?? 1 );
847 } elseif ( $arg ==
'-' ) {
848 # Lonely "-", often used to indicate stdin or stdout.
850 } elseif ( substr( $arg, 0, 1 ) ==
'-' ) {
852 $argLength = strlen( $arg );
853 for ( $p = 1; $p < $argLength; $p++ ) {
855 if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
856 $option = $this->mShortParamsMap[$option];
859 if ( isset( $this->mParams[$option][
'withArg'] ) && $this->mParams[$option][
'withArg'] ) {
860 $param = next( $argv );
861 if ( $param ===
false ) {
862 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
865 $this->
setParam( $options, $option, $param );
867 $this->
setParam( $options, $option, 1 );
875 $this->mOptions = $options;
876 $this->mArgs =
$args;
878 $this->mInputLoaded =
true;
893 private function setParam( &$options, $option, $value ) {
894 $this->orderedOptions[] = [ $option, $value ];
896 if ( isset( $this->mParams[$option] ) ) {
897 $multi = $this->mParams[$option][
'multiOccurrence'];
901 $exists = array_key_exists( $option, $options );
902 if ( $multi && $exists ) {
903 $options[$option][] = $value;
904 } elseif ( $multi ) {
905 $options[$option] = [ $value ];
906 } elseif ( !$exists ) {
907 $options[$option] = $value;
909 $this->
error(
"\nERROR: $option parameter given twice\n" );
924 # If we were given opts or args, set those and return early
926 $this->mSelf =
$self;
927 $this->mInputLoaded =
true;
930 $this->mOptions = $opts;
931 $this->mInputLoaded =
true;
934 $this->mArgs =
$args;
935 $this->mInputLoaded =
true;
938 # If we've already loaded input (either by user values or from $argv)
939 # skip on loading it again. The array_shift() will corrupt values if
940 # it's run again and again
941 if ( $this->mInputLoaded ) {
948 $this->mSelf = $argv[0];
958 # Check to make sure we've got all the required options
959 foreach ( $this->mParams as $opt => $info ) {
960 if ( $info[
'require'] && !$this->
hasOption( $opt ) ) {
961 $this->
error(
"Param $opt required!" );
966 foreach ( $this->mArgList as $k => $info ) {
967 if ( $info[
'require'] && !$this->
hasArg( $k ) ) {
968 $this->
error(
'Argument <' . $info[
'name'] .
'> required!' );
972 if ( !$this->mAllowUnregisteredOptions ) {
973 # Check for unexpected options
974 foreach ( $this->mOptions as $opt => $val ) {
976 $this->
error(
"Unexpected option $opt!" );
991 $this->mDbUser = $this->
getOption(
'dbuser' );
994 $this->mDbPass = $this->
getOption(
'dbpass' );
997 $this->mQuiet =
true;
999 if ( $this->
hasOption(
'batch-size' ) ) {
1000 $this->mBatchSize = intval( $this->
getOption(
'batch-size' ) );
1010 if ( !$force && !$this->
hasOption(
'help' ) ) {
1023 $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
1025 ksort( $this->mParams );
1026 $this->mQuiet =
false;
1029 if ( $this->mDescription ) {
1030 $this->
output(
"\n" . wordwrap( $this->mDescription, $screenWidth ) .
"\n" );
1032 $output =
"\nUsage: php " . basename( $this->mSelf );
1035 if ( $this->mParams ) {
1036 $output .=
" [--" . implode(
"|--", array_keys( $this->mParams ) ) .
"]";
1040 if ( $this->mArgList ) {
1042 foreach ( $this->mArgList as $k => $arg ) {
1043 if ( $arg[
'require'] ) {
1044 $output .=
'<' . $arg[
'name'] .
'>';
1046 $output .=
'[' . $arg[
'name'] .
']';
1048 if ( $k < count( $this->mArgList ) - 1 ) {
1053 $this->
output(
"$output\n\n" );
1056 $this->mGenericParameters,
1057 'Generic maintenance parameters',
1062 $this->mDependentParameters,
1063 'Script dependent parameters',
1069 $scriptSpecificParams = array_diff_key(
1070 # all script parameters:
1072 # remove the Maintenance default parameters:
1078 $scriptSpecificParams,
1079 'Script specific parameters',
1084 if ( count( $this->mArgList ) > 0 ) {
1085 $this->
output(
"Arguments:\n" );
1087 foreach ( $this->mArgList as $info ) {
1088 $openChar = $info[
'require'] ?
'<' :
'[';
1089 $closeChar = $info[
'require'] ?
'>' :
']';
1092 "$tab$openChar" . $info[
'name'] .
"$closeChar: " . $info[
'desc'],
1103 if ( $items === [] ) {
1107 $this->
output(
"$heading:\n" );
1109 foreach ( $items as $name => $info ) {
1110 if ( $info[
'shortName'] !==
false ) {
1111 $name .=
' (-' . $info[
'shortName'] .
')';
1115 "$tab--$name: " . strtr( $info[
'desc'], [
"\n" =>
"\n$tab$tab" ] ),
1134 # Turn off output buffering again, it might have been turned on in the settings files
1135 if ( ob_get_level() ) {
1141 # Override $wgServer
1143 $wgServer = $this->
getOption(
'server', $wgServer );
1146 # If these were passed, use them
1147 if ( $this->mDbUser ) {
1150 if ( $this->mDbPass ) {
1153 if ( $this->
hasOption(
'dbgroupdefault' ) ) {
1154 $wgDBDefaultGroup = $this->
getOption(
'dbgroupdefault',
null );
1159 if ( MediaWikiServices::hasInstance() ) {
1160 $service = MediaWikiServices::getInstance()->peekService(
'DBLoadBalancerFactory' );
1162 $service->destroy();
1188 if ( MediaWikiServices::hasInstance() ) {
1189 $service = MediaWikiServices::getInstance()->peekService(
'DBLoadBalancerFactory' );
1191 $service->destroy();
1201 $wgShowExceptionDetails =
true;
1204 Wikimedia\suppressWarnings();
1205 set_time_limit( 0 );
1206 Wikimedia\restoreWarnings();
1216 if ( defined(
'MW_CMDLINE_CALLBACK' ) ) {
1217 call_user_func( MW_CMDLINE_CALLBACK );
1227 print_r( $GLOBALS );
1240 !MediaWikiServices::getInstance()->isServiceDisabled(
'DBLoadBalancerFactory' )
1242 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1243 $lbFactory->commitPrimaryChanges( get_class( $this ) );
1245 DeferredUpdates::doUpdates();
1251 $lbFactory->commitPrimaryChanges(
'doMaintenance' );
1252 $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
1263 if ( isset( $this->mOptions[
'conf'] ) ) {
1264 $settingsFile = $this->mOptions[
'conf'];
1265 } elseif ( defined(
"MW_CONFIG_FILE" ) ) {
1266 $settingsFile = MW_CONFIG_FILE;
1268 $settingsFile =
"$IP/LocalSettings.php";
1270 if ( isset( $this->mOptions[
'wiki'] ) ) {
1271 $bits = explode(
'-', $this->mOptions[
'wiki'], 2 );
1272 define(
'MW_DB', $bits[0] );
1273 define(
'MW_PREFIX', $bits[1] ??
'' );
1274 } elseif ( isset( $this->mOptions[
'server'] ) ) {
1279 $_SERVER[
'SERVER_NAME'] = $this->mOptions[
'server'];
1282 if ( !is_readable( $settingsFile ) ) {
1283 $this->
fatalError(
"A copy of your installation's LocalSettings.php\n" .
1284 "must exist and be readable in the source directory.\n" .
1285 "Use --conf to specify it." );
1287 $wgCommandLineMode =
true;
1289 return $settingsFile;
1298 # Data should come off the master, wrapped in a transaction
1302 # Get "active" text records via the content table
1304 $this->
output(
'Searching for active text records via contents table...' );
1305 $res = $dbw->select(
'content',
'content_address', [], __METHOD__, [
'DISTINCT' ] );
1306 $blobStore = MediaWikiServices::getInstance()->getBlobStore();
1307 foreach (
$res as $row ) {
1309 $textId = $blobStore->getTextIdFromAddress( $row->content_address );
1314 $this->
output(
"done.\n" );
1316 # Get the IDs of all text records not in these sets
1317 $this->
output(
'Searching for inactive text records...' );
1318 $cond =
'old_id NOT IN ( ' . $dbw->makeList( $cur ) .
' )';
1319 $res = $dbw->select(
'text',
'old_id', [ $cond ], __METHOD__, [
'DISTINCT' ] );
1321 foreach (
$res as $row ) {
1322 $old[] = $row->old_id;
1324 $this->
output(
"done.\n" );
1326 # Inform the user of what we're going to do
1327 $count = count( $old );
1328 $this->
output(
"$count inactive items found.\n" );
1330 # Delete as appropriate
1331 if ( $delete && $count ) {
1332 $this->
output(
'Deleting...' );
1333 $dbw->delete(
'text', [
'old_id' => $old ], __METHOD__ );
1334 $this->
output(
"done.\n" );
1345 return __DIR__ .
'/../';
1362 protected function getDB( $db, $groups = [], $dbDomain =
false ) {
1363 if ( $this->mDb ===
null ) {
1364 return MediaWikiServices::getInstance()
1365 ->getDBLoadBalancerFactory()
1366 ->getMainLB( $dbDomain )
1367 ->getMaintenanceConnectionRef( $db, $groups, $dbDomain );
1394 $dbw->
begin( $fname );
1420 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1421 $waitSucceeded = $lbFactory->waitForReplication(
1422 [
'timeout' => 30,
'ifWritesSince' => $this->lastReplicationWait ]
1424 $this->lastReplicationWait = microtime(
true );
1425 return $waitSucceeded;
1456 for ( $i = $seconds; $i >= 0; $i-- ) {
1457 if ( $i != $seconds ) {
1458 $this->
output( str_repeat(
"\x08", strlen( $i + 1 ) ) );
1477 if ( !function_exists(
'posix_isatty' ) ) {
1490 static $isatty =
null;
1491 if ( $isatty ===
null ) {
1495 if ( $isatty && function_exists(
'readline' ) ) {
1496 return readline( $prompt );
1501 if ( feof( STDIN ) ) {
1504 $st = fgets( STDIN, 1024 );
1507 if ( $st ===
false ) {
1510 $resp = trim( $st );
1522 $bash = ExecutableFinder::findInDefaultPaths(
'bash' );
1524 $encPrompt = Shell::escape( $prompt );
1525 $command =
"read -er -p $encPrompt && echo \"\$REPLY\"";
1526 $result = Shell::command( $bash,
'-c',
$command )
1531 if ( $result->getExitCode() == 0 ) {
1532 return $result->getStdout();
1533 } elseif ( $result->getExitCode() == 127 ) {
1544 if ( feof( STDIN ) ) {
1549 return fgets( STDIN, 1024 );
1560 static $termSize =
null;
1562 if ( $termSize !==
null ) {
1566 $default = [ 80, 50 ];
1569 $termSize = $default;
1581 $result = Shell::command(
'stty',
'size' )->passStdin()->execute();
1582 if ( $result->getExitCode() !== 0 ||
1583 !preg_match(
'/^(\d+) (\d+)$/', $result->getStdout(), $m )
1585 $termSize = $default;
1590 $termSize = [ intval( $m[2] ), intval( $m[1] ) ];
1600 require_once __DIR__ .
'/../../tests/common/TestsAutoLoader.php';
1610 if ( !$this->hookContainer ) {
1611 $this->hookContainer = MediaWikiServices::getInstance()->getHookContainer();
1625 if ( !$this->hookRunner ) {
1642 $ids = preg_split(
'/[\s,;:|]+/', $text );
1644 static function ( $id ) {
1649 return array_filter( $ids );
1664 } elseif ( $this->
hasOption(
"userid" ) ) {
1669 if ( !$user || !$user->getId() ) {
1672 } elseif ( $this->
hasOption(
"userid" ) ) {
$wgDBuser
Database username.
$wgDBadminuser
Separate username for maintenance tasks.
$wgTrxProfilerLimits
Performance expectations for DB usage.
$wgDBservers
Database load balancer This is a two-dimensional array, an array of server info structures Fields are...
$wgShowHostnames
Expose backend server host names through the API and various HTML comments.
$wgDBDefaultGroup
Default group to use when getting database connections.
$wgDBadminpassword
Separate password for maintenance tasks.
$wgProfiler
Profiler configuration.
$wgShowExceptionDetails
If set to true, uncaught exceptions will print the exception message and a complete stack trace to ou...
$wgServer
URL of the server.
$wgLBFactoryConf
Load balancer factory configuration To set up a multi-primary wiki farm, set the class here to someth...
$wgDBpassword
Database user's password.
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.
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 sanity 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()
Execute a callback function at the end of initialisation.
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.
finalSetup()
Handle some last-minute setup here.
loadSpecialVars()
Handle the special variables that are global to all scripts.
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 shutdown to run any deferred updates.
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)
static newFromName( $name, $validate='valid')
static newFromId( $id)
Static factory method for creation from a given user ID.
while(( $__line=Maintenance::readconsole()) !==false) print
Interface for configuration instances.
Advanced database interface for IDatabase handles that include maintenance methods.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s