Go to the documentation of this file.
25 require_once __DIR__ .
'/../includes/PHPVersionCheck.php';
36 define(
'RUN_MAINTENANCE_IF_MAIN', __DIR__ .
'/doMaintenance.php' );
158 $IP = strval( getenv(
'MW_INSTALL_PATH' ) ) !==
''
159 ? getenv(
'MW_INSTALL_PATH' )
160 : realpath( __DIR__ .
'/..' );
163 register_shutdown_function( [ $this,
'outputChanneled' ],
false );
176 if ( !function_exists(
'debug_backtrace' ) ) {
181 $bt = debug_backtrace();
182 $count =
count( $bt );
186 if ( $bt[0][
'class'] !==
'Maintenance' || $bt[0][
'function'] !==
'shouldExecute' ) {
189 $includeFuncs = [
'require_once',
'require',
'include',
'include_once' ];
190 for ( $i = 1; $i < $count; $i++ ) {
191 if ( !in_array( $bt[$i][
'function'], $includeFuncs ) ) {
202 abstract public function execute();
216 $withArg =
false, $shortName =
false, $multiOccurrence =
false
218 $this->mParams[
$name] = [
219 'desc' => $description,
220 'require' => $required,
221 'withArg' => $withArg,
222 'shortName' => $shortName,
223 'multiOccurrence' => $multiOccurrence
226 if ( $shortName !==
false ) {
227 $this->mShortParamsMap[$shortName] =
$name;
237 return isset( $this->mOptions[
$name] );
252 return $this->mOptions[
$name];
255 $this->mOptions[
$name] = $default;
257 return $this->mOptions[
$name];
267 protected function addArg( $arg, $description, $required =
true ) {
268 $this->mArgList[] = [
270 'desc' => $description,
271 'require' => $required
280 unset( $this->mParams[
$name] );
288 $this->mDescription = $text;
296 protected function hasArg( $argId = 0 ) {
297 return isset( $this->mArgs[$argId] );
306 protected function getArg( $argId = 0, $default =
null ) {
307 return $this->
hasArg( $argId ) ? $this->mArgs[$argId] : $default;
315 $this->mBatchSize =
$s;
322 if ( $this->mBatchSize ) {
323 $this->
addOption(
'batch-size',
'Run this many operations ' .
324 'per batch, default: ' . $this->mBatchSize,
false,
true );
325 if ( isset( $this->mParams[
'batch-size'] ) ) {
327 $this->mDependantParameters[
'batch-size'] = $this->mParams[
'batch-size'];
347 if ( $len == self::STDIN_ALL ) {
348 return file_get_contents(
'php://stdin' );
350 $f = fopen(
'php://stdin',
'rt' );
354 $input = fgets( $f, $len );
374 if ( $this->mQuiet ) {
377 if ( $channel ===
null ) {
381 $out = preg_replace(
'/\n\z/',
'',
$out );
392 protected function error( $err, $die = 0 ) {
394 if ( PHP_SAPI ==
'cli' ) {
395 fwrite( STDERR, $err .
"\n" );
399 $die = intval( $die );
412 if ( !$this->atLineStart ) {
414 $this->atLineStart =
true;
427 if ( $msg ===
false ) {
434 if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
440 $this->atLineStart =
false;
441 if ( $channel ===
null ) {
444 $this->atLineStart =
true;
446 $this->lastChannel = $channel;
467 # Generic (non script dependant) options:
469 $this->
addOption(
'help',
'Display this help message',
false,
false,
'h' );
470 $this->
addOption(
'quiet',
'Whether to supress non-error output',
false,
false,
'q' );
471 $this->
addOption(
'conf',
'Location of LocalSettings.php, if not default',
false,
true );
472 $this->
addOption(
'wiki',
'For specifying the wiki ID',
false,
true );
473 $this->
addOption(
'globals',
'Output globals at the end of processing for debugging' );
476 'Set a specific memory limit for the script, '
477 .
'"max" for no limit or "default" to avoid changing it'
479 $this->
addOption(
'server',
"The protocol and server name to use in URLs, e.g. " .
480 "http://en.wikipedia.org. This is sometimes necessary because " .
481 "server name detection may fail in command line scripts.",
false,
true );
482 $this->
addOption(
'profiler',
'Profiler output format (usually "text")',
false,
true );
484 # Save generic options to display them separately in help
487 # Script dependant options:
491 $this->
addOption(
'dbuser',
'The DB user to use for this script',
false,
true );
492 $this->
addOption(
'dbpass',
'The password to use for this script',
false,
true );
495 # Save additional script dependant options to display
496 # them separately in help
497 $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters );
505 if ( $this->config ===
null ) {
506 $this->config = MediaWikiServices::getInstance()->getMainConfig();
530 $this->requiredExtensions[] =
$name;
541 foreach ( $this->requiredExtensions
as $name ) {
542 if ( !$registry->isLoaded(
$name ) ) {
548 $joined = implode(
', ', $missing );
549 $msg =
"The following extensions are required to be installed "
550 .
"for this script to run: $joined. Please enable them and then try again.";
551 $this->
error( $msg, 1 );
560 if ( function_exists(
'posix_getpwuid' ) ) {
561 $agent = posix_getpwuid( posix_geteuid() )[
'name'];
567 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
569 $lbFactory->setAgentName(
570 mb_strlen( $agent ) > 15 ? mb_substr( $agent, 0, 15 ) .
'...' : $agent
581 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
582 $lbFactory->setWaitForReplicationListener(
594 $lbFactory->getMainLB()->setTransactionListener(
596 function ( $trigger ) {
617 require_once $classFile;
620 $this->
error(
"Cannot spawn child: $maintClass" );
628 $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
629 if ( !is_null( $this->mDb ) ) {
630 $child->setDB( $this->mDb );
642 # Abort if called from a web server
643 if ( isset( $_SERVER ) && isset( $_SERVER[
'REQUEST_METHOD'] ) ) {
644 $this->
error(
'This script must be run from the command line',
true );
647 if ( $IP ===
null ) {
648 $this->
error(
"\$IP not set, aborting!\n" .
649 '(Did you forget to call parent::__construct() in your maintenance script?)', 1 );
652 # Make sure we can handle script parameters
653 if ( !defined(
'HPHP_VERSION' ) && !ini_get(
'register_argc_argv' ) ) {
654 $this->
error(
'Cannot get command line arguments, register_argc_argv is set to false',
true );
660 if ( ini_get(
'display_errors' ) ) {
661 ini_set(
'display_errors',
'stderr' );
667 # Set the memory limit
668 # Note we need to set it again later in cache LocalSettings changed it
671 # Set max execution time to 0 (no limit). PHP.net says that
672 # "When running PHP from the command line the default setting is 0."
673 # But sometimes this doesn't seem to be the case.
674 ini_set(
'max_execution_time', 0 );
678 # Define us as being in MediaWiki
679 define(
'MEDIAWIKI',
true );
683 # Turn off output buffering if it's on
684 while ( ob_get_level() > 0 ) {
701 $limit = $this->
getOption(
'memory-limit',
'max' );
702 $limit = trim( $limit,
"\" '" );
711 if ( $limit ==
'max' ) {
714 if ( $limit !=
'default' ) {
715 ini_set(
'memory_limit', $limit );
733 $profiler =
new $class(
734 [
'sampling' => 1,
'output' => [
$output ] ]
738 $profiler->setTemplated(
true );
743 $trxProfiler->setLogger( LoggerFactory::getInstance(
'DBPerformance' ) );
751 $this->mOptions = [];
753 $this->mInputLoaded =
false;
766 $this->orderedOptions = [];
769 for ( $arg = reset(
$argv ); $arg !==
false; $arg = next(
$argv ) ) {
770 if ( $arg ==
'--' ) {
771 # End of options, remainder should be considered arguments
772 $arg = next(
$argv );
773 while ( $arg !==
false ) {
775 $arg = next(
$argv );
778 } elseif ( substr( $arg, 0, 2 ) ==
'--' ) {
780 $option = substr( $arg, 2 );
781 if ( isset( $this->mParams[$option] ) && $this->mParams[$option][
'withArg'] ) {
782 $param = next(
$argv );
783 if ( $param ===
false ) {
784 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
790 $bits = explode(
'=', $option, 2 );
791 if (
count( $bits ) > 1 ) {
800 } elseif ( $arg ==
'-' ) {
801 # Lonely "-", often used to indicate stdin or stdout.
803 } elseif ( substr( $arg, 0, 1 ) ==
'-' ) {
805 $argLength = strlen( $arg );
806 for ( $p = 1; $p < $argLength; $p++ ) {
808 if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
809 $option = $this->mShortParamsMap[$option];
812 if ( isset( $this->mParams[$option][
'withArg'] ) && $this->mParams[$option][
'withArg'] ) {
813 $param = next(
$argv );
814 if ( $param ===
false ) {
815 $this->
error(
"\nERROR: $option parameter needs a value after it\n" );
829 $this->mArgs =
$args;
831 $this->mInputLoaded =
true;
847 $this->orderedOptions[] = [ $option,
$value ];
849 if ( isset( $this->mParams[$option] ) ) {
850 $multi = $this->mParams[$option][
'multiOccurrence'];
854 $exists = array_key_exists( $option,
$options );
855 if ( $multi && $exists ) {
857 } elseif ( $multi ) {
859 } elseif ( !$exists ) {
862 $this->
error(
"\nERROR: $option parameter given twice\n" );
877 # If we were given opts or args, set those and return early
879 $this->mSelf =
$self;
880 $this->mInputLoaded =
true;
883 $this->mOptions = $opts;
884 $this->mInputLoaded =
true;
887 $this->mArgs =
$args;
888 $this->mInputLoaded =
true;
891 # If we've already loaded input (either by user values or from $argv)
892 # skip on loading it again. The array_shift() will corrupt values if
893 # it's run again and again
894 if ( $this->mInputLoaded ) {
901 $this->mSelf =
$argv[0];
910 # Check to make sure we've got all the required options
911 foreach ( $this->mParams
as $opt => $info ) {
913 $this->
error(
"Param $opt required!" );
918 foreach ( $this->mArgList
as $k => $info ) {
919 if ( $info[
'require'] && !$this->
hasArg( $k ) ) {
920 $this->
error(
'Argument <' . $info[
'name'] .
'> required!' );
935 $this->mDbUser = $this->
getOption(
'dbuser' );
938 $this->mDbPass = $this->
getOption(
'dbpass' );
941 $this->mQuiet =
true;
943 if ( $this->
hasOption(
'batch-size' ) ) {
944 $this->mBatchSize = intval( $this->
getOption(
'batch-size' ) );
953 if ( !$force && !$this->
hasOption(
'help' ) ) {
959 $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
961 ksort( $this->mParams );
962 $this->mQuiet =
false;
965 if ( $this->mDescription ) {
966 $this->
output(
"\n" . wordwrap( $this->mDescription, $screenWidth ) .
"\n" );
968 $output =
"\nUsage: php " . basename( $this->mSelf );
971 if ( $this->mParams ) {
972 $output .=
" [--" . implode( array_keys( $this->mParams ),
"|--" ) .
"]";
976 if ( $this->mArgList ) {
978 foreach ( $this->mArgList
as $k => $arg ) {
979 if ( $arg[
'require'] ) {
980 $output .=
'<' . $arg[
'name'] .
'>';
982 $output .=
'[' . $arg[
'name'] .
']';
984 if ( $k <
count( $this->mArgList ) - 1 ) {
989 $this->
output(
"$output\n\n" );
991 # TODO abstract some repetitive code below
994 $this->
output(
"Generic maintenance parameters:\n" );
995 foreach ( $this->mGenericParameters
as $par => $info ) {
996 if ( $info[
'shortName'] !==
false ) {
997 $par .=
" (-{$info['shortName']})";
1000 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1001 "\n$tab$tab" ) .
"\n"
1007 if (
count( $scriptDependantParams ) > 0 ) {
1008 $this->
output(
"Script dependant parameters:\n" );
1010 foreach ( $scriptDependantParams
as $par => $info ) {
1011 if ( $info[
'shortName'] !==
false ) {
1012 $par .=
" (-{$info['shortName']})";
1015 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1016 "\n$tab$tab" ) .
"\n"
1024 $scriptSpecificParams = array_diff_key(
1028 $this->mGenericParameters,
1029 $this->mDependantParameters
1031 if (
count( $scriptSpecificParams ) > 0 ) {
1032 $this->
output(
"Script specific parameters:\n" );
1034 foreach ( $scriptSpecificParams
as $par => $info ) {
1035 if ( $info[
'shortName'] !==
false ) {
1036 $par .=
" (-{$info['shortName']})";
1039 wordwrap(
"$tab--$par: " . $info[
'desc'], $descWidth,
1040 "\n$tab$tab" ) .
"\n"
1047 if (
count( $this->mArgList ) > 0 ) {
1048 $this->
output(
"Arguments:\n" );
1050 foreach ( $this->mArgList
as $info ) {
1051 $openChar = $info[
'require'] ?
'<' :
'[';
1052 $closeChar = $info[
'require'] ?
'>' :
']';
1054 wordwrap(
"$tab$openChar" . $info[
'name'] .
"$closeChar: " .
1055 $info[
'desc'], $descWidth,
"\n$tab$tab" ) .
"\n"
1072 # Turn off output buffering again, it might have been turned on in the settings files
1073 if ( ob_get_level() ) {
1079 # Override $wgServer
1081 $wgServer = $this->
getOption(
'server', $wgServer );
1084 # If these were passed, use them
1085 if ( $this->mDbUser ) {
1088 if ( $this->mDbPass ) {
1109 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->destroy();
1117 $wgShowSQLErrors =
true;
1119 MediaWiki\suppressWarnings();
1120 set_time_limit( 0 );
1121 MediaWiki\restoreWarnings();
1130 if ( defined(
'MW_CMDLINE_CALLBACK' ) ) {
1131 call_user_func( MW_CMDLINE_CALLBACK );
1152 if ( isset( $this->mOptions[
'conf'] ) ) {
1153 $settingsFile = $this->mOptions[
'conf'];
1154 } elseif ( defined(
"MW_CONFIG_FILE" ) ) {
1155 $settingsFile = MW_CONFIG_FILE;
1157 $settingsFile =
"$IP/LocalSettings.php";
1159 if ( isset( $this->mOptions[
'wiki'] ) ) {
1160 $bits = explode(
'-', $this->mOptions[
'wiki'] );
1161 if (
count( $bits ) == 1 ) {
1164 define(
'MW_DB', $bits[0] );
1165 define(
'MW_PREFIX', $bits[1] );
1168 if ( !is_readable( $settingsFile ) ) {
1169 $this->
error(
"A copy of your installation's LocalSettings.php\n" .
1170 "must exist and be readable in the source directory.\n" .
1171 "Use --conf to specify it.",
true );
1173 $wgCommandLineMode =
true;
1175 return $settingsFile;
1184 # Data should come off the master, wrapped in a transaction
1188 # Get "active" text records from the revisions table
1190 $this->
output(
'Searching for active text records in revisions table...' );
1191 $res = $dbw->select(
'revision',
'rev_text_id', [], __METHOD__, [
'DISTINCT' ] );
1192 foreach (
$res as $row ) {
1193 $cur[] = $row->rev_text_id;
1195 $this->
output(
"done.\n" );
1197 # Get "active" text records from the archive table
1198 $this->
output(
'Searching for active text records in archive table...' );
1199 $res = $dbw->select(
'archive',
'ar_text_id', [], __METHOD__, [
'DISTINCT' ] );
1200 foreach (
$res as $row ) {
1201 # old pre-MW 1.5 records can have null ar_text_id's.
1202 if ( $row->ar_text_id !==
null ) {
1203 $cur[] = $row->ar_text_id;
1206 $this->
output(
"done.\n" );
1208 # Get the IDs of all text records not in these sets
1209 $this->
output(
'Searching for inactive text records...' );
1210 $cond =
'old_id NOT IN ( ' . $dbw->makeList( $cur ) .
' )';
1211 $res = $dbw->select(
'text',
'old_id', [ $cond ], __METHOD__, [
'DISTINCT' ] );
1213 foreach (
$res as $row ) {
1214 $old[] = $row->old_id;
1216 $this->
output(
"done.\n" );
1218 # Inform the user of what we're going to do
1219 $count =
count( $old );
1220 $this->
output(
"$count inactive items found.\n" );
1222 # Delete as appropriate
1223 if ( $delete && $count ) {
1224 $this->
output(
'Deleting...' );
1225 $dbw->delete(
'text', [
'old_id' => $old ], __METHOD__ );
1226 $this->
output(
"done.\n" );
1251 protected function getDB( $db, $groups = [], $wiki =
false ) {
1252 if ( is_null( $this->mDb ) ) {
1253 return wfGetDB( $db, $groups, $wiki );
1296 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
1297 $lbFactory->waitForReplication(
1298 [
'timeout' => 30,
'ifWritesSince' => $this->lastReplicationWait ]
1300 $this->lastReplicationWait = microtime(
true );
1327 $write = [
'searchindex' ];
1337 $db->lockTables( $read, $write, __CLASS__ .
'::' . __METHOD__ );
1345 $db->unlockTables( __CLASS__ .
'::' . __METHOD__ );
1369 if ( $maxLockTime ) {
1370 $this->
output(
" --- Waiting for lock ---" );
1376 # Loop through the results and do a search update
1377 foreach ( $results
as $row ) {
1378 # Allow reads to be processed
1379 if ( $maxLockTime && time() > $lockTime + $maxLockTime ) {
1380 $this->
output(
" --- Relocking ---" );
1385 call_user_func( $callback, $dbw, $row );
1388 # Unlock searchindex
1389 if ( $maxLockTime ) {
1390 $this->
output(
" --- Unlocking --" );
1407 $titleObj =
$rev->getTitle();
1408 $title = $titleObj->getPrefixedDBkey();
1409 $this->
output(
"$title..." );
1410 # Update searchindex
1411 $u =
new SearchUpdate( $pageId, $titleObj->getText(),
$rev->getContent() );
1428 if ( !function_exists(
'posix_isatty' ) ) {
1441 static $isatty =
null;
1442 if ( is_null( $isatty ) ) {
1446 if ( $isatty && function_exists(
'readline' ) ) {
1447 $resp = readline( $prompt );
1448 if ( $resp ===
null ) {
1458 if ( feof( STDIN ) ) {
1461 $st = fgets( STDIN, 1024 );
1464 if ( $st ===
false ) {
1467 $resp = trim( $st );
1483 $command =
"read -er -p $encPrompt && echo \"\$REPLY\"";
1500 if ( feof( STDIN ) ) {
1505 return fgets( STDIN, 1024 );
1516 $default = [ 80, 50 ];
1532 if ( !preg_match(
'/^(\d+) (\d+)$/', $size, $m ) ) {
1535 return [ intval( $m[2] ), intval( $m[1] ) ];
1543 require_once __DIR__ .
'/../tests/common/TestsAutoLoader.php';
1564 parent::__construct();
1565 $this->
addOption(
'force',
'Run the update even if it was completed already' );
1574 && $db->selectRow(
'updatelog',
'1', [
'ul_key' => $key ], __METHOD__ )
1585 if ( $db->insert(
'updatelog', [
'ul_key' => $key ], __METHOD__,
'IGNORE' ) ) {
1601 return "Update '{$key}' already logged as completed.";
1611 return "Unable to log update '{$key}' as completed.";
$wgProfileLimit
Only record profiling info for pages that took longer than this.
const RUN_MAINTENANCE_IF_MAIN
int $mBatchSize
Batch size.
__construct()
Default constructor.
setParam(&$options, $option, $value)
Helper function used solely by loadParamsAndArgs to prevent code duplication.
static getTermSize()
Get the terminal size as a two-element array where the first element is the width (number of columns)...
$wgShowSQLErrors
Whether to show "we're sorry, but there has been a database error" pages.
getStdin( $len=null)
Return input from stdin.
static replaceStubInstance(Profiler $profiler)
Replace the current profiler with $profiler if no non-stub profiler is set.
static instance()
Singleton.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
maybeHelp( $force=false)
Maybe show the help.
addDescription( $text)
Set the description text.
setup()
Do some sanity checking and basic setup.
array $requiredExtensions
runChild( $maintClass, $classFile=null)
Run a child maintenance script.
static readconsole( $prompt='> ')
Prompt the console for input.
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
loadParamsAndArgs( $self=null, $opts=null, $args=null)
Process command line arguments $mOptions becomes an array with keys set to the option names $mArgs be...
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
relockSearchindex( $db)
Unlock and lock again Since the lock is low-priority, queued reads will be able to complete.
getName()
Get the script's name.
wfHostname()
Fetch server name for use in error reporting etc.
$wgLBFactoryConf
Load balancer factory configuration To set up a multi-master wiki farm, set the class here to somethi...
hasArg( $argId=0)
Does a given argument exist?
setDB(IDatabase $db)
Sets database object to be returned by getDB().
Allows to change the fields on the form that will be generated $name
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
setConfig(Config $config)
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
$wgDBpassword
Database user's password.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
checkRequiredExtensions()
Verify that the required extensions are installed.
static locateExecutableInDefaultPaths( $names, $versionInfo=false)
Same as locateExecutable(), but checks in getPossibleBinPaths() by default.
finalSetup()
Handle some last-minute setup here.
rollbackTransaction(IDatabase $dbw, $fname)
Rollback the transcation on a DB handle.
wfEntryPointCheck( $entryPoint)
Check php version and that external dependencies are installed, and display an informative error if e...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
afterFinalSetup()
Execute a callback function at the end of initialisation.
$wgDBadminuser
Separate username for maintenance tasks.
unlockSearchindex( $db)
Unlock the tables.
clearParamsAndArgs()
Clear all params and arguments.
$wgDBservers
Database load balancer This is a two-dimensional array, an array of server info structures Fields are...
updateSearchIndex( $maxLockTime, $callback, $dbw, $results)
Perform a search index update with locking.
namespace and then decline to actually register it file or subcat img or subcat $title
loadSpecialVars()
Handle the special variables that are global to all scripts.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
script(document.cookie)%253c/script%253e</pre ></div > !! end !! test XSS is escaped(inline) !!input< source lang
global $wgCommandLineMode
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
float $lastReplicationWait
UNIX timestamp.
if(is_array( $mode)) switch( $mode) $input
static loadFromPageId( $db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
array $orderedOptions
Used to read the options in the order they were passed.
globals()
Potentially debug globals.
updatelogFailedMessage()
Message to show that the update log was unable to log the completion of this update.
when a variable name is used in a it is silently declared as a new masking the global
Fake maintenance wrapper, mostly used for the web installer/updater.
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
addDefaultParams()
Add the default parameters to the scripts.
static readlineEmulation( $prompt)
Emulate readline()
deleteOption( $name)
Remove an option.
static shouldExecute()
Should we execute the maintenance script, or just allow it to be included as a standalone class?...
execute()
Do the actual work.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
updateSearchIndexForPage( $dbw, $pageId)
Update the searchindex table for a given pageid.
activateProfiler()
Activate the profiler (assuming $wgProfiler is set)
static tryOpportunisticExecute( $mode='run')
Run all deferred updates immediately if there are no DB writes active.
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 account incomplete not yet checked for validity & $retval
wfIsWindows()
Check if the operating system is Windows.
$wgServer
URL of the server.
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
static requireTestsAutoloader()
Call this to set up the autoloader to allow classes to be used from the tests directory.
static posix_isatty( $fd)
Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but trea...
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
validateParamsAndArgs()
Run some validation checks on the params, etc.
Config $config
Accessible via getConfig()
cleanupChanneled()
Clean up channeled output.
const DB_NONE
Constants for DB access type.
loadSettings()
Generic setup for most installs.
doDBUpdates()
Do the actual work.
adjustMemoryLimit()
Adjusts PHP's memory limit to better suit our needs, if needed.
static setLBFactoryTriggers(LBFactory $LBFactory)
getUpdateKey()
Get the update key name to go in the update log table.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
resource $fileHandle
Used when creating separate schema files.
getOption( $name, $default=null)
Get an option, or return the default.
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
float $wgRequestTime
Request start time as fractional seconds since epoch.
addArg( $arg, $description, $required=true)
Add some args that are needed.
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
setAgentAndTriggers()
Set triggers like when to try to run deferred updates.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
getDir()
Get the maintenance directory.
$wgDBuser
Database username.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
hasOption( $name)
Checks to see if a particular param exists.
getArg( $argId=0, $default=null)
Get an argument.
public function execute()
$wgDBadminpassword
Separate password for maintenance tasks.
outputChanneled( $msg, $channel=null)
Message outputter with channeled message support.
__construct()
Default constructor.
Advanced database interface for IDatabase handles that include maintenance methods.
execute()
Do the actual work.
$wgTrxProfilerLimits
Performance expectations for DB usage.
lockSearchindex( $db)
Lock the search index.
the array() calling protocol came about after MediaWiki 1.4rc1.
setBatchSize( $s=0)
Set the batch size.
IMaintainableDatabase $mDb
Used by getDB() / setDB()
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
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