25require_once __DIR__ .
'/../includes/PHPVersionCheck.php';
36define(
'RUN_MAINTENANCE_IF_MAIN', __DIR__ .
'/doMaintenance.php' );
164 $IP = strval( getenv(
'MW_INSTALL_PATH' ) ) !==
''
165 ? getenv(
'MW_INSTALL_PATH' )
166 : realpath( __DIR__ .
'/..' );
169 register_shutdown_function( [ $this,
'outputChanneled' ],
false );
182 if ( !function_exists(
'debug_backtrace' ) ) {
187 $bt = debug_backtrace();
188 $count = count( $bt );
192 if ( $bt[0][
'class'] !== self::class || $bt[0][
'function'] !==
'shouldExecute' ) {
195 $includeFuncs = [
'require_once',
'require',
'include',
'include_once' ];
196 for ( $i = 1; $i < $count; $i++ ) {
197 if ( !in_array( $bt[$i][
'function'], $includeFuncs ) ) {
222 return isset( $this->mParams[$name] );
236 protected function addOption( $name, $description, $required =
false,
237 $withArg =
false, $shortName =
false, $multiOccurrence =
false
239 $this->mParams[
$name] = [
240 'desc' => $description,
241 'require' => $required,
242 'withArg' => $withArg,
243 'shortName' => $shortName,
244 'multiOccurrence' => $multiOccurrence
247 if ( $shortName !==
false ) {
248 $this->mShortParamsMap[$shortName] =
$name;
258 return isset( $this->mOptions[$name] );
271 protected function getOption( $name, $default =
null ) {
273 return $this->mOptions[
$name];
276 $this->mOptions[
$name] = $default;
278 return $this->mOptions[
$name];
288 protected function addArg( $arg, $description, $required =
true ) {
289 $this->mArgList[] = [
291 'desc' => $description,
292 'require' => $required
301 unset( $this->mParams[$name] );
310 $this->mAllowUnregisteredOptions = $allow;
318 $this->mDescription = $text;
326 protected function hasArg( $argId = 0 ) {
327 return isset( $this->mArgs[$argId] );
336 protected function getArg( $argId = 0, $default =
null ) {
337 return $this->
hasArg( $argId ) ? $this->mArgs[$argId] : $default;
356 $this->mBatchSize =
$s;
363 if ( $this->mBatchSize ) {
364 $this->
addOption(
'batch-size',
'Run this many operations ' .
365 'per batch, default: ' . $this->mBatchSize,
false,
true );
366 if ( isset( $this->mParams[
'batch-size'] ) ) {
368 $this->mDependantParameters[
'batch-size'] = $this->mParams[
'batch-size'];
388 if ( $len == self::STDIN_ALL ) {
389 return file_get_contents(
'php://stdin' );
391 $f = fopen(
'php://stdin',
'rt' );
395 $input = fgets( $f, $len );
416 if ( class_exists( MediaWikiServices::class ) ) {
418 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
419 if ( $stats->getDataCount() > 1000 ) {
420 MediaWiki::emitBufferedStatsdData( $stats, $this->
getConfig() );
424 if ( $this->mQuiet ) {
427 if ( $channel ===
null ) {
431 $out = preg_replace(
'/\n\z/',
'',
$out );
442 protected function error( $err, $die = 0 ) {
443 if ( intval( $die ) !== 0 ) {
449 ( PHP_SAPI ==
'cli' || PHP_SAPI ==
'phpdbg' ) &&
450 !defined(
'MW_PHPUNIT_TEST' )
452 fwrite( STDERR, $err .
"\n" );
466 $this->
error( $msg );
477 if ( !$this->atLineStart ) {
479 $this->atLineStart =
true;
492 if ( $msg ===
false ) {
499 if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
505 $this->atLineStart =
false;
506 if ( $channel ===
null ) {
509 $this->atLineStart =
true;
511 $this->lastChannel = $channel;
532 # Generic (non script dependant) options:
534 $this->
addOption(
'help',
'Display this help message',
false,
false,
'h' );
535 $this->
addOption(
'quiet',
'Whether to suppress non-error output',
false,
false,
'q' );
536 $this->
addOption(
'conf',
'Location of LocalSettings.php, if not default',
false,
true );
537 $this->
addOption(
'wiki',
'For specifying the wiki ID',
false,
true );
538 $this->
addOption(
'globals',
'Output globals at the end of processing for debugging' );
541 'Set a specific memory limit for the script, '
542 .
'"max" for no limit or "default" to avoid changing it',
546 $this->
addOption(
'server',
"The protocol and server name to use in URLs, e.g. " .
547 "http://en.wikipedia.org. This is sometimes necessary because " .
548 "server name detection may fail in command line scripts.",
false,
true );
549 $this->
addOption(
'profiler',
'Profiler output format (usually "text")',
false,
true );
551 $this->
addOption(
'mwdebug',
'Enable built-in MediaWiki development settings',
false,
true );
553 # Save generic options to display them separately in help
556 # Script dependant options:
560 $this->
addOption(
'dbuser',
'The DB user to use for this script',
false,
true );
561 $this->
addOption(
'dbpass',
'The password to use for this script',
false,
true );
562 $this->
addOption(
'dbgroupdefault',
'The default DB group to use.',
false,
true );
565 # Save additional script dependant options to display
566 # Â them separately in help
567 $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters );
575 if ( $this->config ===
null ) {
576 $this->config = MediaWikiServices::getInstance()->getMainConfig();
600 $this->requiredExtensions[] =
$name;
611 foreach ( $this->requiredExtensions as $name ) {
612 if ( !$registry->isLoaded( $name ) ) {
618 $joined = implode(
', ', $missing );
619 $msg =
"The following extensions are required to be installed "
620 .
"for this script to run: $joined. Please enable them and then try again.";
630 if ( function_exists(
'posix_getpwuid' ) ) {
631 $agent = posix_getpwuid( posix_geteuid() )[
'name'];
637 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
639 $lbFactory->setAgentName(
640 mb_strlen( $agent ) > 15 ? mb_substr( $agent, 0, 15 ) .
'...' : $agent
651 $services = MediaWikiServices::getInstance();
652 $stats =
$services->getStatsdDataFactory();
654 $lbFactory =
$services->getDBLoadBalancerFactory();
655 $lbFactory->setWaitForReplicationListener(
657 function () use ( $stats,
$config ) {
660 DeferredUpdates::tryOpportunisticExecute(
'run' );
663 MediaWiki::emitBufferedStatsdData( $stats,
$config );
668 $lbFactory->getMainLB()->setTransactionListener(
670 function ( $trigger )
use ( $stats,
$config ) {
672 if (
$config->
get(
'CommandLineMode' ) && $trigger === IDatabase::TRIGGER_COMMIT ) {
673 DeferredUpdates::tryOpportunisticExecute(
'run' );
676 MediaWiki::emitBufferedStatsdData( $stats,
$config );
692 require_once $classFile;
695 $this->
error(
"Cannot spawn child: $maintClass" );
703 $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
704 if ( !is_null( $this->mDb ) ) {
705 $child->setDB( $this->mDb );
717 # Abort if called from a web server
718 # wfIsCLI() is not available yet
719 if ( PHP_SAPI !==
'cli' && PHP_SAPI !==
'phpdbg' ) {
720 $this->
fatalError(
'This script must be run from the command line' );
723 if ( $IP ===
null ) {
724 $this->
fatalError(
"\$IP not set, aborting!\n" .
725 '(Did you forget to call parent::__construct() in your maintenance script?)' );
728 # Make sure we can handle script parameters
729 if ( !defined(
'HPHP_VERSION' ) && !ini_get(
'register_argc_argv' ) ) {
730 $this->
fatalError(
'Cannot get command line arguments, register_argc_argv is set to false' );
736 if ( ini_get(
'display_errors' ) ) {
737 ini_set(
'display_errors',
'stderr' );
743 # Set the memory limit
744 # Note we need to set it again later in cache LocalSettings changed it
747 # Set max execution time to 0 (no limit). PHP.net says that
748 # "When running PHP from the command line the default setting is 0."
749 # But sometimes this doesn't seem to be the case.
750 ini_set(
'max_execution_time', 0 );
752 # Define us as being in MediaWiki
753 define(
'MEDIAWIKI',
true );
757 # Turn off output buffering if it's on
758 while ( ob_get_level() > 0 ) {
775 $limit = $this->
getOption(
'memory-limit',
'max' );
776 $limit = trim( $limit,
"\" '" );
785 if ( $limit ==
'max' ) {
788 if ( $limit !=
'default' ) {
789 ini_set(
'memory_limit', $limit );
807 $profiler =
new $class(
808 [
'sampling' => 1,
'output' => [
$output ] ]
812 $profiler->setTemplated(
true );
813 Profiler::replaceStubInstance( $profiler );
816 $trxProfiler = Profiler::instance()->getTransactionProfiler();
817 $trxProfiler->setLogger( LoggerFactory::getInstance(
'DBPerformance' ) );
825 $this->mOptions = [];
827 $this->mInputLoaded =
false;
840 $this->orderedOptions = [];
843 for ( $arg = reset( $argv ); $arg !==
false; $arg = next( $argv ) ) {
844 if ( $arg ==
'--' ) {
845 # End of options, remainder should be considered arguments
846 $arg = next( $argv );
847 while ( $arg !==
false ) {
849 $arg = next( $argv );
852 } elseif ( substr( $arg, 0, 2 ) ==
'--' ) {
854 $option = substr( $arg, 2 );
855 if ( isset( $this->mParams[$option] ) && $this->mParams[$option][
'withArg'] ) {
856 $param = next( $argv );
857 if ( $param ===
false ) {
858 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
864 $bits = explode(
'=', $option, 2 );
865 if ( count( $bits ) > 1 ) {
874 } elseif ( $arg ==
'-' ) {
875 # Lonely "-", often used to indicate stdin or stdout.
877 } elseif ( substr( $arg, 0, 1 ) ==
'-' ) {
879 $argLength = strlen( $arg );
880 for ( $p = 1; $p < $argLength; $p++ ) {
882 if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
883 $option = $this->mShortParamsMap[$option];
886 if ( isset( $this->mParams[$option][
'withArg'] ) && $this->mParams[$option][
'withArg'] ) {
887 $param = next( $argv );
888 if ( $param ===
false ) {
889 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
903 $this->mArgs =
$args;
905 $this->mInputLoaded =
true;
921 $this->orderedOptions[] = [ $option,
$value ];
923 if ( isset( $this->mParams[$option] ) ) {
924 $multi = $this->mParams[$option][
'multiOccurrence'];
928 $exists = array_key_exists( $option,
$options );
929 if ( $multi && $exists ) {
931 } elseif ( $multi ) {
933 } elseif ( !$exists ) {
936 $this->
error(
"\nERROR: $option parameter given twice\n" );
951 # If we were given opts or args, set those and return early
953 $this->mSelf =
$self;
954 $this->mInputLoaded =
true;
957 $this->mOptions = $opts;
958 $this->mInputLoaded =
true;
961 $this->mArgs =
$args;
962 $this->mInputLoaded =
true;
965 # If we've already loaded input (either by user values or from $argv)
966 # skip on loading it again. The array_shift() will corrupt values if
967 # it's run again and again
968 if ( $this->mInputLoaded ) {
975 $this->mSelf = $argv[0];
984 # Check to make sure we've got all the required options
985 foreach ( $this->mParams as
$opt => $info ) {
987 $this->
error(
"Param $opt required!" );
992 foreach ( $this->mArgList as $k => $info ) {
993 if ( $info[
'require'] && !$this->
hasArg( $k ) ) {
994 $this->
error(
'Argument <' . $info[
'name'] .
'> required!' );
998 if ( !$this->mAllowUnregisteredOptions ) {
999 # Check for unexpected options
1000 foreach ( $this->mOptions as
$opt => $val ) {
1002 $this->
error(
"Unexpected option $opt!" );
1018 $this->mDbUser = $this->
getOption(
'dbuser' );
1021 $this->mDbPass = $this->
getOption(
'dbpass' );
1024 $this->mQuiet =
true;
1026 if ( $this->
hasOption(
'batch-size' ) ) {
1027 $this->mBatchSize = intval( $this->
getOption(
'batch-size' ) );
1036 if ( !$force && !$this->
hasOption(
'help' ) ) {
1042 $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
1044 ksort( $this->mParams );
1045 $this->mQuiet =
false;
1048 if ( $this->mDescription ) {
1049 $this->
output(
"\n" . wordwrap( $this->mDescription, $screenWidth ) .
"\n" );
1051 $output =
"\nUsage: php " . basename( $this->mSelf );
1054 if ( $this->mParams ) {
1055 $output .=
" [--" . implode(
"|--", array_keys( $this->mParams ) ) .
"]";
1059 if ( $this->mArgList ) {
1061 foreach ( $this->mArgList as $k => $arg ) {
1062 if ( $arg[
'require'] ) {
1063 $output .=
'<' . $arg[
'name'] .
'>';
1065 $output .=
'[' . $arg[
'name'] .
']';
1067 if ( $k < count( $this->mArgList ) - 1 ) {
1072 $this->
output(
"$output\n\n" );
1074 # TODO abstract some repetitive code below
1077 $this->
output(
"Generic maintenance parameters:\n" );
1078 foreach ( $this->mGenericParameters as $par => $info ) {
1079 if ( $info[
'shortName'] !==
false ) {
1080 $par .=
" (-{$info['shortName']})";
1083 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1084 "\n$tab$tab" ) .
"\n"
1090 if ( count( $scriptDependantParams ) > 0 ) {
1091 $this->
output(
"Script dependant parameters:\n" );
1093 foreach ( $scriptDependantParams as $par => $info ) {
1094 if ( $info[
'shortName'] !==
false ) {
1095 $par .=
" (-{$info['shortName']})";
1098 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1099 "\n$tab$tab" ) .
"\n"
1107 $scriptSpecificParams = array_diff_key(
1108 # all script parameters:
1110 # remove the Maintenance default parameters:
1114 if ( count( $scriptSpecificParams ) > 0 ) {
1115 $this->
output(
"Script specific parameters:\n" );
1117 foreach ( $scriptSpecificParams as $par => $info ) {
1118 if ( $info[
'shortName'] !==
false ) {
1119 $par .=
" (-{$info['shortName']})";
1122 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1123 "\n$tab$tab" ) .
"\n"
1130 if ( count( $this->mArgList ) > 0 ) {
1131 $this->
output(
"Arguments:\n" );
1133 foreach ( $this->mArgList as $info ) {
1134 $openChar = $info[
'require'] ?
'<' :
'[';
1135 $closeChar = $info[
'require'] ?
'>' :
']';
1137 wordwrap(
"$tab$openChar" . $info[
'name'] .
"$closeChar: " .
1138 $info[
'desc'], $descWidth,
"\n$tab$tab" ) .
"\n"
1155 # Turn off output buffering again, it might have been turned on in the settings files
1156 if ( ob_get_level() ) {
1162 # Override $wgServer
1164 $wgServer = $this->
getOption(
'server', $wgServer );
1167 # If these were passed, use them
1168 if ( $this->mDbUser ) {
1171 if ( $this->mDbPass ) {
1174 if ( $this->
hasOption(
'dbgroupdefault' ) ) {
1175 $wgDBDefaultGroup = $this->
getOption(
'dbgroupdefault',
null );
1177 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
1197 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
1200 # Apply debug settings
1202 require __DIR__ .
'/../includes/DevelopmentSettings.php';
1210 $wgShowExceptionDetails =
true;
1213 Wikimedia\suppressWarnings();
1214 set_time_limit( 0 );
1215 Wikimedia\restoreWarnings();
1224 if ( defined(
'MW_CMDLINE_CALLBACK' ) ) {
1225 call_user_func( MW_CMDLINE_CALLBACK );
1246 if ( isset( $this->mOptions[
'conf'] ) ) {
1247 $settingsFile = $this->mOptions[
'conf'];
1248 } elseif ( defined(
"MW_CONFIG_FILE" ) ) {
1249 $settingsFile = MW_CONFIG_FILE;
1251 $settingsFile =
"$IP/LocalSettings.php";
1253 if ( isset( $this->mOptions[
'wiki'] ) ) {
1254 $bits = explode(
'-', $this->mOptions[
'wiki'] );
1255 if ( count( $bits ) == 1 ) {
1258 define(
'MW_DB', $bits[0] );
1259 define(
'MW_PREFIX', $bits[1] );
1260 } elseif ( isset( $this->mOptions[
'server'] ) ) {
1265 $_SERVER[
'SERVER_NAME'] = $this->mOptions[
'server'];
1268 if ( !is_readable( $settingsFile ) ) {
1269 $this->
fatalError(
"A copy of your installation's LocalSettings.php\n" .
1270 "must exist and be readable in the source directory.\n" .
1271 "Use --conf to specify it." );
1273 $wgCommandLineMode =
true;
1275 return $settingsFile;
1284 # Data should come off the master, wrapped in a transaction
1288 # Get "active" text records from the revisions table
1290 $this->
output(
'Searching for active text records in revisions table...' );
1291 $res = $dbw->select(
'revision',
'rev_text_id', [], __METHOD__, [
'DISTINCT' ] );
1292 foreach (
$res as $row ) {
1293 $cur[] = $row->rev_text_id;
1295 $this->
output(
"done.\n" );
1297 # Get "active" text records from the archive table
1298 $this->
output(
'Searching for active text records in archive table...' );
1299 $res = $dbw->select(
'archive',
'ar_text_id', [], __METHOD__, [
'DISTINCT' ] );
1300 foreach (
$res as $row ) {
1301 # old pre-MW 1.5 records can have null ar_text_id's.
1302 if ( $row->ar_text_id !==
null ) {
1303 $cur[] = $row->ar_text_id;
1306 $this->
output(
"done.\n" );
1308 # Get the IDs of all text records not in these sets
1309 $this->
output(
'Searching for inactive text records...' );
1310 $cond =
'old_id NOT IN ( ' . $dbw->makeList( $cur ) .
' )';
1311 $res = $dbw->select(
'text',
'old_id', [ $cond ], __METHOD__, [
'DISTINCT' ] );
1313 foreach (
$res as $row ) {
1314 $old[] = $row->old_id;
1316 $this->
output(
"done.\n" );
1318 # Inform the user of what we're going to do
1319 $count = count( $old );
1320 $this->
output(
"$count inactive items found.\n" );
1322 # Delete as appropriate
1323 if ( $delete && $count ) {
1324 $this->
output(
'Deleting...' );
1325 $dbw->delete(
'text', [
'old_id' => $old ], __METHOD__ );
1326 $this->
output(
"done.\n" );
1351 protected function getDB( $db, $groups = [], $wiki =
false ) {
1352 if ( is_null( $this->mDb ) ) {
1353 return wfGetDB( $db, $groups, $wiki );
1395 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1396 $waitSucceeded = $lbFactory->waitForReplication(
1397 [
'timeout' => 30,
'ifWritesSince' => $this->lastReplicationWait ]
1399 $this->lastReplicationWait = microtime(
true );
1400 return $waitSucceeded;
1422 $write = [
'searchindex' ];
1432 $db->lockTables( $read, $write, __CLASS__ .
'::' . __METHOD__ );
1440 $db->unlockTables( __CLASS__ .
'::' . __METHOD__ );
1464 if ( $maxLockTime ) {
1465 $this->
output(
" --- Waiting for lock ---" );
1471 # Loop through the results and do a search update
1472 foreach ( $results as $row ) {
1473 # Allow reads to be processed
1474 if ( $maxLockTime && time() > $lockTime + $maxLockTime ) {
1475 $this->
output(
" --- Relocking ---" );
1480 call_user_func( $callback, $dbw, $row );
1483 # Unlock searchindex
1484 if ( $maxLockTime ) {
1485 $this->
output(
" --- Unlocking --" );
1502 $titleObj =
$rev->getTitle();
1503 $title = $titleObj->getPrefixedDBkey();
1504 $this->
output(
"$title..." );
1505 # Update searchindex
1506 $u =
new SearchUpdate( $pageId, $titleObj->getText(),
$rev->getContent() );
1528 for ( $i = $seconds; $i >= 0; $i-- ) {
1529 if ( $i != $seconds ) {
1530 $this->
output( str_repeat(
"\x08", strlen( $i + 1 ) ) );
1549 if ( !function_exists(
'posix_isatty' ) ) {
1562 static $isatty =
null;
1563 if ( is_null( $isatty ) ) {
1567 if ( $isatty && function_exists(
'readline' ) ) {
1568 return readline( $prompt );
1573 if ( feof( STDIN ) ) {
1576 $st = fgets( STDIN, 1024 );
1579 if ( $st ===
false ) {
1582 $resp = trim( $st );
1594 $bash = ExecutableFinder::findInDefaultPaths(
'bash' );
1598 $command =
"read -er -p $encPrompt && echo \"\$REPLY\"";
1615 if ( feof( STDIN ) ) {
1620 return fgets( STDIN, 1024 );
1631 $default = [ 80, 50 ];
1635 if ( Shell::isDisabled() ) {
1645 $result = Shell::command(
'stty',
'size' )
1647 if ( $result->getExitCode() !== 0 ) {
1650 if ( !preg_match(
'/^(\d+) (\d+)$/', $result->getStdout(), $m ) ) {
1653 return [ intval( $m[2] ), intval( $m[1] ) ];
1661 require_once __DIR__ .
'/../tests/common/TestsAutoLoader.php';
1681 parent::__construct();
1682 $this->
addOption(
'force',
'Run the update even if it was completed already' );
1691 && $db->selectRow(
'updatelog',
'1', [
'ul_key' => $key ], __METHOD__ )
1702 if ( $db->insert(
'updatelog', [
'ul_key' => $key ], __METHOD__,
'IGNORE' ) ) {
1718 return "Update '{$key}' already logged as completed.";
1728 return "Unable to log update '{$key}' as completed.";
$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.
$wgProfileLimit
Only record profiling info for pages that took longer than this.
$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-master wiki farm, set the class here to somethi...
$wgDBpassword
Database user's password.
global $wgCommandLineMode
wfEscapeShellArg(... $args)
Version of escapeshellarg() that works better on Windows.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
wfHostname()
Fetch server name for use in error reporting etc.
wfIsWindows()
Check if the operating system is Windows.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
const RUN_MAINTENANCE_IF_MAIN
wfEntryPointCheck( $entryPoint)
Check php version and that external dependencies are installed, and display an informative error if e...
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Fake maintenance wrapper, mostly used for the web installer/updater.
execute()
Do the actual work.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
__construct()
Default constructor.
doDBUpdates()
Do the actual work.
updatelogFailedMessage()
Message to show that the update log was unable to log the completion of this update.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
getUpdateKey()
Get the update key name to go in the update log table.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
setup()
Do some sanity checking and basic setup.
__construct()
Default constructor.
error( $err, $die=0)
Throw an error to the user.
getName()
Get the script's name.
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.
relockSearchindex( $db)
Unlock and lock again Since the lock is low-priority, queued reads will be able to complete.
int $mBatchSize
Batch size.
setAgentAndTriggers()
Set triggers like when to try to run deferred updates.
$mAllowUnregisteredOptions
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 transcation on a DB.
static getTermSize()
Get the terminal size as a two-element array where the first element is the width (number of columns)...
clearParamsAndArgs()
Clear all params and arguments.
static setLBFactoryTriggers(LBFactory $LBFactory, Config $config)
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 transcation 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.
getStdin( $len=null)
Return input from stdin.
cleanupChanneled()
Clean up channeled output.
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
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.
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...
outputChanneled( $msg, $channel=null)
Message outputter with channeled message support.
finalSetup()
Handle some last-minute setup here.
loadSpecialVars()
Handle the special variables that are global to all scripts.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
float $lastReplicationWait
UNIX timestamp.
array $orderedOptions
Used to read the options in the order they were passed.
loadSettings()
Generic setup for most installs.
setDB(IDatabase $db)
Sets database object to be returned by getDB().
hasOption( $name)
Checks to see if a particular option exists.
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 $mDb
Used by getDB() / setDB()
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.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
getBatchSize()
Returns batch size.
unlockSearchindex( $db)
Unlock the tables.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
activateProfiler()
Activate the profiler (assuming $wgProfiler is set)
maybeHelp( $force=false)
Maybe show the help.
updateSearchIndexForPage( $dbw, $pageId)
Update the searchindex table for a given pageid.
resource $fileHandle
Used when creating separate schema files.
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.
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.
Config $config
Accessible via getConfig()
lockSearchindex( $db)
Lock the search index.
checkRequiredExtensions()
Verify that the required extensions are installed.
rollbackTransaction(IDatabase $dbw, $fname)
Rollback the transcation on a DB handle.
updateSearchIndex( $maxLockTime, $callback, $dbw, $results)
Perform a search index update with locking.
globals()
Potentially debug globals.
setConfig(Config $config)
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static loadFromPageId( $db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Database independant search index updater.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
namespace and then decline to actually register it file or subcat img or subcat $title
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Allows to change the fields on the form that will be generated $name
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
while(( $__line=Maintenance::readconsole()) !==false) print
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
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.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(is_array($mode)) switch( $mode) $input