|
MediaWiki master
|
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effort. More...
Inherited by MediaWiki\Maintenance\ApplyChangeTag, MediaWiki\Maintenance\BackupDumper, MediaWiki\Maintenance\Benchmarker, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\FakeMaintenance, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, MediaWiki\Maintenance\UpdateCredits, and MediaWiki\Maintenance\Version.

Public Member Functions | |
| __construct () | |
| Default constructor. | |
| canExecuteWithoutLocalSettings () | |
| Whether this script can run without LocalSettings.php. | |
| checkRequiredExtensions () | |
| Verify that the required extensions are installed. | |
| cleanupChanneled () | |
| Clean up channeled output. | |
| clearParamsAndArgs () | |
| Clear all params and arguments. | |
| createChild (string $maintClass, ?string $classFile=null) | |
| Returns an instance of the given maintenance script, with all of the current arguments passed to it. | |
| execute () | |
| Do the actual work. | |
| finalSetup (SettingsBuilder $settingsBuilder) | |
| Handle some last-minute setup here. | |
| getConfig () | |
| getDbType () | |
| Does the script need different DB access? | |
| getName () | |
| Get the script's name. | |
| getParameters () | |
| isQuiet () | |
| loadParamsAndArgs ( $self=null, $opts=null, $args=null) | |
| Process command line arguments when running as a child script. | |
| loadWithArgv ( $argv) | |
| Load params and arguments from a given array of command-line arguments. | |
| memoryLimit () | |
| Override memory_limit from php.ini on maintenance scripts. | |
| outputChanneled ( $msg, $channel=null) | |
| Message outputter with channeled message support. | |
| purgeRedundantText ( $delete=true) | |
| Support function for cleaning up redundant text records. | |
| setArg ( $argId, $value) | |
| Programmatically set the value of the given argument. | |
| setConfig (Config $config) | |
| setDB (IMaintainableDatabase $db) | |
| Sets database object to be returned by getDB(). | |
| setLBFactory (ILBFactory $lbFactory) | |
| setName (string $name) | |
| setOption (string $name, $value) | |
| Programmatically set the value of the given option. | |
| setup () | |
| Provides subclasses with an opportunity to perform initial checks. | |
| validateParamsAndArgs () | |
| Run some validation checks on the params, etc. | |
Static Public Member Functions | |
| static | getTermSize () |
| Get the terminal size as a two-element array where the first element is the width (number of columns) and the second element is the height (number of rows). | |
| static | posix_isatty ( $fd) |
| Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but treating stout as not a tty to avoid color codes. | |
| static | readconsole ( $prompt='> ') |
| Prompt the console for input. | |
| static | requireTestsAutoloader () |
| Call this to set up the autoloader to allow classes to be used from the tests directory. | |
Public Attributes | |
| resource null | $fileHandle |
| Used when creating separate schema files. | |
| array | $orderedOptions = [] |
| Used to read the options in the order they were passed. | |
| const | DB_ADMIN = 2 |
| const | DB_NONE = 0 |
| Constants for DB access type. | |
| const | DB_STD = 1 |
| const | GENERIC_MAINTENANCE_PARAMETERS = 'Script runner options' |
| const | SCRIPT_DEPENDENT_PARAMETERS = 'Common options' |
| const | STDIN_ALL = -1 |
Protected Member Functions | |
| addArg ( $arg, $description, $required=true, $multi=false) | |
| Add some args that are needed. | |
| addDefaultParams () | |
| Add the default parameters to the scripts. | |
| addDescription ( $text) | |
| Set the description text. | |
| addOption ( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false) | |
| Add a parameter to the script. | |
| afterFinalSetup () | |
| Override to perform any required operation at the end of initialisation. | |
| beginTransaction (IDatabase $dbw, $fname) | |
| Begin a transaction on a DB handle. | |
| beginTransactionRound ( $fname) | |
| Start a transactional batch of DB operations. | |
| commitTransaction (IDatabase $dbw, $fname) | |
| Commit the transaction on a DB handle and wait for replica DB servers to catch up. | |
| commitTransactionRound ( $fname) | |
| Commit a transactional batch of DB operations and wait for replica DB servers to catch up. | |
| countDown ( $seconds) | |
| Count down from $seconds to zero on the terminal, with a one-second pause between showing each number. | |
| deleteOption ( $name) | |
| Remove an option. | |
| error ( $err) | |
| Throw an error to the user. | |
| fatalError ( $msg, $exitCode=1) | |
| Output a message and terminate the current script. | |
| getAnalyticsReplica (string|false $virtualDomain=false) | |
| Get a replica connection meant for slow, long-running or analytics-style queries (the "vslow" query group, which also covers "dump"). | |
| getArg ( $argId=0, $default=null) | |
| Get an argument. | |
| getArgName (int $argId) | |
| Get the name of an argument. | |
| getArgs ( $offset=0) | |
| Get arguments. | |
| getBatchSize () | |
| Returns batch size. | |
| getDB ( $db, $groups=[], $dbDomain=false) | |
| Returns a database to be used by current maintenance script. | |
| getDir () | |
| Get the maintenance directory. | |
| getHookContainer () | |
| Get a HookContainer, for running extension hooks or for hook metadata. | |
| getHookRunner () | |
| Get a HookRunner for running core hooks. | |
| getOption ( $name, $default=null) | |
| Get an option, or return the default. | |
| getPrimaryDB (string|false $virtualDomain=false) | |
| getReplicaDB (string|false $virtualDomain=false) | |
| getServiceContainer () | |
| Returns the main service container. | |
| getStdin ( $len=null) | |
| Return input from stdin. | |
| hasArg ( $argId=0) | |
| Does a given argument exist? | |
| hasOption ( $name) | |
| Checks to see if a particular option was set. | |
| loadSpecialVars () | |
| Handle the special variables that are global to all scripts. | |
| maybeHelp ( $force=false) | |
| Maybe show the help. | |
| newBatchIterator ( $source) | |
| Wrap an entry iterator into a generator that returns batches of said entries. | |
| output ( $out, $channel=null) | |
| Throw some output to the user. | |
| parseIntList ( $text) | |
| Utility function to parse a string (perhaps from a command line option) into a list of integers (perhaps some kind of numeric IDs). | |
| prompt (string $prompt, ?string $default=null) | |
| promptYesNo ( $prompt, $default=null) | |
| requireExtension ( $name) | |
| Indicate that the specified extension must be loaded before the script can run. | |
| rollbackTransaction (IDatabase $dbw, $fname) | |
| Rollback the transaction on a DB handle. | |
| rollbackTransactionRound ( $fname) | |
| Rollback a transactional batch of DB operations. | |
| setAllowUnregisteredOptions ( $allow) | |
| Sets whether to allow unregistered options, which are options passed to a script that do not match an expected parameter. | |
| setBatchSize ( $s=0) | |
| showHelp () | |
| Definitely show the help. | |
| supportsOption ( $name) | |
| Checks to see if a particular option in supported. | |
| validateUserOption ( $errorMsg) | |
| waitForReplication () | |
| Wait for replica DB servers to catch up. | |
Protected Attributes | |
| array | $mArgs = [] |
| This is the list of arguments that were actually passed. | |
| int null | $mBatchSize = null |
| Batch size. | |
| string | $mDbPass = null |
| string | $mDbUser = null |
| string | $mDescription = '' |
| A description of the script, children should change this via addDescription(). | |
| bool | $mInputLoaded = false |
| Have we already loaded our user input? | |
| array | $mOptions = [] |
| This is the list of options that were actually passed. | |
| array[] | $mParams = [] |
| Empty. | |
| bool | $mQuiet = false |
| Special vars for params that are always used. | |
| string null | $mSelf |
| Name of the script currently running. | |
| MaintenanceParameters | $parameters |
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effort.
All that must be defined is the execute() method. See docs/maintenance.txt for more info and a quick demo of how to use it.
Terminology: params: registry of named values that may be passed to the script arg list: registry of positional values that may be passed to the script options: passed param values args: passed positional values
In the command: mwscript somescript.php –foo=bar baz foo is a param bar is the option value of the option for param foo baz is the arg value at index 0 in the arg list
WARNING: the constructor, MaintenanceRunner::shouldExecute(), setup(), finalSetup(), and getName() are called before Setup.php is complete, which means most of the common infrastructure, like logging or autoloading, is not available. Be careful when changing these methods or the ones called from them. Likewise, be careful with the constructor when subclassing. MediaWikiServices instance is not yet available at this point.
Definition at line 64 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::__construct | ( | ) |
Default constructor.
Children should call this first if implementing their own constructors
Reimplemented in BenchmarkCommentFormatter, BenchmarkEval, BenchmarkGlobalVarConfig, BenchmarkHooks, BenchmarkJsonCodec, BenchmarkJsValidate, BenchmarkLCStore, BenchmarkLruHash, BenchmarkPurge, BenchmarkRebuildLocalisationCache, BenchmarkSanitizer, BenchmarkSettings, BenchmarkTidy, BenchmarkTitleValue, CleanupEmptyCategories, CleanupWatchlistLabelMember, CleanupWatchlistTemporaryAccountRows, FixWrongPasswordPrefixes, GenerateSchemaChangeSql, GenerateSchemaSql, MediaWiki\Maintenance\ApplyChangeTag, MediaWiki\Maintenance\Benchmarker, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\FixAutoblockLogTitles, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, MediaWiki\Maintenance\UpdateCredits, MediaWiki\Maintenance\UpdateRestrictions, MediaWiki\Maintenance\Version, MigrateBlocks, MigrateLinksTable, and PopulateUserIsTemp.
Definition at line 198 of file Maintenance.php.
References addDefaultParams().
|
protected |
Add some args that are needed.
| string | $arg | Name of the arg, like 'start' |
| string | $description | Short description of the arg |
| bool | $required | Is this required? |
| bool | $multi | Does it allow multiple values? (Last arg only) |
Definition at line 310 of file Maintenance.php.
Referenced by BenchmarkEval\__construct().
|
protected |
Add the default parameters to the scripts.
Definition at line 627 of file Maintenance.php.
References addOption(), and getDbType().
Referenced by __construct().
|
protected |
Set the description text.
| string | $text | The text of the description |
Definition at line 335 of file Maintenance.php.
Referenced by BenchmarkCommentFormatter\__construct(), BenchmarkGlobalVarConfig\__construct(), BenchmarkHooks\__construct(), BenchmarkJsonCodec\__construct(), BenchmarkJsValidate\__construct(), BenchmarkLCStore\__construct(), BenchmarkLruHash\__construct(), BenchmarkPurge\__construct(), BenchmarkRebuildLocalisationCache\__construct(), BenchmarkSanitizer\__construct(), BenchmarkSettings\__construct(), BenchmarkTitleValue\__construct(), CleanupEmptyCategories\__construct(), CleanupWatchlistLabelMember\__construct(), CleanupWatchlistTemporaryAccountRows\__construct(), DumpBackup\__construct(), GenerateSchemaChangeSql\__construct(), GenerateSchemaSql\__construct(), MediaWiki\Maintenance\ApplyChangeTag\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), MediaWiki\Maintenance\FixAutoblockLogTitles\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), MediaWiki\Maintenance\UpdateCredits\__construct(), MediaWiki\Maintenance\UpdateRestrictions\__construct(), MediaWiki\Maintenance\Version\__construct(), MigrateBlocks\__construct(), MigrateLinksTable\__construct(), and PopulateUserIsTemp\__construct().
|
protected |
Add a parameter to the script.
Will be displayed on –help with the associated description
| string | $name | The name of the param (help, version, etc) |
| string | $description | The description of the param to show on –help |
| bool | $required | Is the param required? |
| bool | $withArg | Is an argument required with this option? |
| string | bool | $shortName | Character to use as short name |
| bool | $multiOccurrence | Can this option be passed multiple times? |
Definition at line 265 of file Maintenance.php.
Referenced by BenchmarkCommentFormatter\__construct(), BenchmarkEval\__construct(), BenchmarkJsonCodec\__construct(), BenchmarkJsValidate\__construct(), BenchmarkLCStore\__construct(), BenchmarkLruHash\__construct(), BenchmarkRebuildLocalisationCache\__construct(), BenchmarkSanitizer\__construct(), BenchmarkTidy\__construct(), DumpBackup\__construct(), MediaWiki\Maintenance\ApplyChangeTag\__construct(), MediaWiki\Maintenance\BackupDumper\__construct(), MediaWiki\Maintenance\Benchmarker\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), MediaWiki\Maintenance\LoggedUpdateMaintenance\__construct(), MediaWiki\Maintenance\SchemaMaintenance\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), MigrateBlocks\__construct(), MigrateLinksTable\__construct(), addDefaultParams(), MediaWiki\Maintenance\BackupDumper\finalSetup(), and setBatchSize().
|
protected |
Override to perform any required operation at the end of initialisation.
Definition at line 1001 of file Maintenance.php.
Referenced by finalSetup().
|
protected |
Begin a transaction on a DB handle.
Maintenance scripts should call this method instead of IDatabase::begin(). Use of this method makes it clear that the caller is a maintenance script, which has the outermost transaction scope needed to explicitly begin transactions.
This method makes it clear that begin() is called from a maintenance script, which has outermost scope. This is safe, unlike $dbw->begin() called in other places.
Use this method for scripts with direct, straightforward, control of all writes.
| IDatabase | $dbw | |
| string | $fname | Caller name |
beginTransactionRound() instead Definition at line 1189 of file Maintenance.php.
References Wikimedia\Rdbms\IDatabase\begin().
|
protected |
Start a transactional batch of DB operations.
Use this method for scripts that split up their work into logical transactions.
This method is suitable even for scripts lacking direct, straightforward, control of all writes. Such scripts might invoke complex methods of service objects, which might easily touch multiple DB servers. This method proves the usual best-effort distributed transactions that DBO_DEFAULT provides during web requests.
| string | $fname | Caller name |
Definition at line 1304 of file Maintenance.php.
Referenced by purgeRedundantText().
| MediaWiki\Maintenance\Maintenance::canExecuteWithoutLocalSettings | ( | ) |
Whether this script can run without LocalSettings.php.
Scripts that need to be able to run when MediaWiki has not been installed should override this to return true. Scripts that return true from this method must be able to function without a storage backend. When no LocalSettings.php file is present, any attempt to access the database will fail with a fatal error.
Reimplemented in MediaWiki\Maintenance\SchemaMaintenance, and MediaWiki\Maintenance\Version.
Definition at line 240 of file Maintenance.php.
References return.
| MediaWiki\Maintenance\Maintenance::checkRequiredExtensions | ( | ) |
Verify that the required extensions are installed.
Definition at line 701 of file Maintenance.php.
References fatalError().
| MediaWiki\Maintenance\Maintenance::cleanupChanneled | ( | ) |
Clean up channeled output.
Output a newline if necessary.
Definition at line 565 of file Maintenance.php.
Referenced by output(), and outputChanneled().
| MediaWiki\Maintenance\Maintenance::clearParamsAndArgs | ( | ) |
Clear all params and arguments.
Definition at line 791 of file Maintenance.php.
|
protected |
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
This method also triggers DeferredUpdates::tryOpportunisticExecute().
Maintenance scripts should call this method instead of IDatabase::commit(). Use of this method makes it clear that the caller is a maintenance script, which has the outermost transaction scope needed to explicitly commit transactions.
Use this method for scripts with direct, straightforward, control of all writes.
| IDatabase | $dbw | |
| string | $fname | Caller name |
commitTransactionRound() instead Definition at line 1210 of file Maintenance.php.
References Wikimedia\Rdbms\IDatabase\commit(), and waitForReplication().
|
protected |
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
Use this method for scripts that split up their work into logical transactions.
This method also triggers DeferredUpdates::tryOpportunisticExecute().
| string | $fname | Caller name |
Definition at line 1323 of file Maintenance.php.
References MediaWiki\MediaWikiEntryPoint\emitBufferedStats(), and getServiceContainer().
Referenced by purgeRedundantText().
|
protected |
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number.
If the maintenance script is in quiet mode, this function does nothing.
| int | $seconds |
Definition at line 1403 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::createChild | ( | string | $maintClass, |
| ?string | $classFile = null ) |
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
Callers are expected to run the returned maintenance script instance by calling Maintenance::execute
| class-string<Maintenance> | $maintClass A name of a child maintenance class | |
| string | null | $classFile | Full path of where the child is |
Maintenance::execute on the returned object. Definition at line 734 of file Maintenance.php.
References MediaWiki\Maintenance\$maintClass, fatalError(), and if.
|
protected |
Remove an option.
Useful for removing options that won't be used in your script.
| string | $name | The option to remove. |
Definition at line 318 of file Maintenance.php.
|
protected |
Throw an error to the user.
Doesn't respect –quiet, so don't use this for non-error output
| string | StatusValue | $err | The error to display |
Definition at line 511 of file Maintenance.php.
References error(), outputChanneled(), and wfMessage().
Referenced by error(), BenchmarkPurge\execute(), MediaWiki\Maintenance\SchemaMaintenance\execute(), fatalError(), and maybeHelp().
|
abstract |
Do the actual work.
All child classes will need to implement this
Reimplemented in BenchmarkCommentFormatter, BenchmarkEval, BenchmarkGlobalVarConfig, BenchmarkHooks, BenchmarkJsonCodec, BenchmarkJsValidate, BenchmarkLCStore, BenchmarkLruHash, BenchmarkPurge, BenchmarkRebuildLocalisationCache, BenchmarkSanitizer, BenchmarkSettings, BenchmarkTidy, BenchmarkTitleValue, BenchmarkTruncate, DumpBackup, MediaWiki\Maintenance\ApplyChangeTag, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\FakeMaintenance, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, MediaWiki\Maintenance\TextPassDumper, MediaWiki\Maintenance\UpdateCredits, and MediaWiki\Maintenance\Version.
|
protected |
Output a message and terminate the current script.
| string | StatusValue | $msg | Error message |
| int | $exitCode | PHP exit status. Should be in range 1-254. |
Definition at line 545 of file Maintenance.php.
References error().
Referenced by checkRequiredExtensions(), createChild(), MediaWiki\Maintenance\UpdateRestrictions\doDBUpdates(), BenchmarkCommentFormatter\execute(), BenchmarkEval\execute(), BenchmarkJsValidate\execute(), BenchmarkLCStore\execute(), BenchmarkTidy\execute(), DumpBackup\execute(), MediaWiki\Maintenance\ApplyChangeTag\execute(), MediaWiki\Maintenance\SchemaMaintenance\execute(), MediaWiki\Maintenance\UpdateCredits\execute(), MediaWiki\Maintenance\Version\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), maybeHelp(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), and validateUserOption().
| MediaWiki\Maintenance\Maintenance::finalSetup | ( | SettingsBuilder | $settingsBuilder | ) |
Handle some last-minute setup here.
| SettingsBuilder | $settingsBuilder |
Reimplemented in BenchmarkLCStore, MediaWiki\Maintenance\BackupDumper, and MediaWiki\Maintenance\TextPassDumper.
Definition at line 931 of file Maintenance.php.
References afterFinalSetup(), MediaWiki\MainConfigNames\DBadminpassword, MediaWiki\MainConfigNames\DBadminuser, MediaWiki\MainConfigNames\DBpassword, MediaWiki\MainConfigNames\DBservers, MediaWiki\MainConfigNames\DBuser, MediaWiki\Settings\SettingsBuilder\getConfig(), getDbType(), getOption(), getServiceContainer(), MediaWiki\MediaWikiServices\hasInstance(), hasOption(), MediaWiki\MainConfigNames\LBFactoryConf, MediaWiki\Settings\SettingsBuilder\putConfigValues(), MediaWiki\MainConfigNames\Server, MediaWiki\MainConfigNames\ShowExceptionDetails, and MediaWiki\MainConfigNames\ShowHostnames.
|
protected |
Get a replica connection meant for slow, long-running or analytics-style queries (the "vslow" query group, which also covers "dump").
| string | false | $virtualDomain |
Definition at line 1134 of file Maintenance.php.
References return.
Referenced by MediaWiki\Maintenance\BackupDumper\initProgress().
|
protected |
Get an argument.
| int | string | $argId | The index (from zero) of the argument, or the name declared for the argument by addArg(). |
| mixed | null | $default | The default if it doesn't exist |
Definition at line 357 of file Maintenance.php.
Referenced by BenchmarkEval\execute().
|
protected |
Get the name of an argument.
| int | $argId | The index (from zero) of the argument. |
Definition at line 381 of file Maintenance.php.
References getArgName(), and return.
Referenced by getArgName().
|
protected |
Get arguments.
| int | string | $offset | The index (from zero) of the first argument, or the name declared for the argument by addArg(). |
Definition at line 369 of file Maintenance.php.
|
protected |
Returns batch size.
Definition at line 418 of file Maintenance.php.
Referenced by CleanupWatchlistLabelMember\doDBUpdates(), FixWrongPasswordPrefixes\doDBUpdates(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), MediaWiki\Maintenance\UpdateRestrictions\doDBUpdates(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), and newBatchIterator().
| MediaWiki\Maintenance\Maintenance::getConfig | ( | ) |
Definition at line 660 of file Maintenance.php.
References getServiceContainer().
Referenced by BenchmarkRebuildLocalisationCache\execute(), and purgeRedundantText().
|
protected |
Returns a database to be used by current maintenance script.
This uses the main LBFactory instance by default unless overridden via setDB().
This function has the same parameters as LoadBalancer::getConnection().
For simple cases, use ::getReplicaDB() or ::getPrimaryDB() instead.
| int | $db | DB index (DB_REPLICA/DB_PRIMARY) |
| string | string[] | $groups | default: empty array |
| string | bool | $dbDomain | default: current wiki |
Definition at line 1097 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\UpdateRestrictions\doDBUpdates(), MigrateBlocks\doDBUpdates(), MigrateLinksTable\doDBUpdates(), and BenchmarkTruncate\execute().
| MediaWiki\Maintenance\Maintenance::getDbType | ( | ) |
Does the script need different DB access?
By default, we give Maintenance scripts normal rights to the DB. Sometimes, a script needs admin rights access for a reason and sometimes they want no access. Subclasses should override and return one of the following values, as needed: Maintenance::DB_NONE - For no DB access at all Maintenance::DB_STD - For normal DB access, default Maintenance::DB_ADMIN - For admin DB access
Definition at line 620 of file Maintenance.php.
Referenced by addDefaultParams(), and finalSetup().
|
protected |
|
protected |
Get a HookContainer, for running extension hooks or for hook metadata.
Definition at line 1559 of file Maintenance.php.
References getServiceContainer().
Referenced by BenchmarkHooks\execute(), and getHookRunner().
|
protected |
Get a HookRunner for running core hooks.
Definition at line 1574 of file Maintenance.php.
References getHookContainer().
| MediaWiki\Maintenance\Maintenance::getName | ( | ) |
|
protected |
Get an option, or return the default.
If the option was added to support multiple occurrences, this will return an array.
| string | $name | The name of the param |
| mixed | null | $default | Anything you want, default null |
Definition at line 299 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\Benchmarker\bench(), MigrateLinksTable\doDBUpdates(), BenchmarkCommentFormatter\execute(), BenchmarkEval\execute(), BenchmarkJsonCodec\execute(), BenchmarkJsValidate\execute(), BenchmarkLCStore\execute(), BenchmarkLruHash\execute(), BenchmarkPurge\execute(), BenchmarkRebuildLocalisationCache\execute(), BenchmarkSanitizer\execute(), BenchmarkTidy\execute(), MediaWiki\Maintenance\ApplyChangeTag\execute(), MediaWiki\Maintenance\SchemaMaintenance\execute(), finalSetup(), MigrateLinksTable\getUpdateKey(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), loadSpecialVars(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), MediaWiki\Maintenance\TextPassDumper\processOptions(), MediaWiki\Maintenance\DeleteLocalPasswords\processUsers(), and validateUserOption().
| MediaWiki\Maintenance\Maintenance::getParameters | ( | ) |
|
protected |
| string | false | $virtualDomain |
Definition at line 1143 of file Maintenance.php.
References return.
Referenced by CleanupWatchlistTemporaryAccountRows\doDBUpdates(), FixWrongPasswordPrefixes\doDBUpdates(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserDB(), PopulateUserIsTemp\initServices(), MediaWiki\Maintenance\LoggedUpdateMaintenance\isAlreadyCompleted(), and purgeRedundantText().
|
protected |
| string | false | $virtualDomain |
Definition at line 1122 of file Maintenance.php.
References return.
Referenced by CleanupWatchlistTemporaryAccountRows\doDBUpdates(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), and PopulateUserIsTemp\initServices().
|
protected |
Returns the main service container.
Definition at line 671 of file Maintenance.php.
References MediaWiki\MediaWikiServices\getInstance().
Referenced by commitTransactionRound(), CleanupWatchlistLabelMember\doDBUpdates(), CleanupWatchlistTemporaryAccountRows\doDBUpdates(), MediaWiki\Maintenance\BackupDumper\dump(), BenchmarkCommentFormatter\execute(), BenchmarkLCStore\execute(), BenchmarkRebuildLocalisationCache\execute(), BenchmarkTitleValue\execute(), MediaWiki\Maintenance\ApplyChangeTag\execute(), MediaWiki\Maintenance\Version\execute(), finalSetup(), getConfig(), getHookContainer(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), PopulateUserIsTemp\initServices(), output(), purgeRedundantText(), and waitForReplication().
|
protected |
Return input from stdin.
| int | null | $len | The number of bytes to read. If null, just return the handle. Maintenance::STDIN_ALL returns the full content |
Definition at line 457 of file Maintenance.php.
|
static |
Get the terminal size as a two-element array where the first element is the width (number of columns) and the second element is the height (number of rows).
Definition at line 1507 of file Maintenance.php.
References MediaWiki\Message\Message\isDisabled(), and wfIsWindows().
|
protected |
Does a given argument exist?
| int | string | $argId | The index (from zero) of the argument, or the name declared for the argument by addArg(). |
Definition at line 345 of file Maintenance.php.
Referenced by BenchmarkEval\execute().
|
protected |
Checks to see if a particular option was set.
| string | $name | The name of the option |
Definition at line 284 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\Benchmarker\bench(), BenchmarkEval\execute(), BenchmarkLCStore\execute(), BenchmarkPurge\execute(), DumpBackup\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), MediaWiki\Maintenance\SchemaMaintenance\execute(), finalSetup(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), loadSpecialVars(), maybeHelp(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), MediaWiki\Maintenance\TextPassDumper\processOptions(), and validateUserOption().
| MediaWiki\Maintenance\Maintenance::isQuiet | ( | ) |
| MediaWiki\Maintenance\Maintenance::loadParamsAndArgs | ( | $self = null, | |
| $opts = null, | |||
| $args = null ) |
Process command line arguments when running as a child script.
| string | null | $self | The name of the script, if any |
| array | null | $opts | An array of options, in form of key=>value |
| array | null | $args | An array of command line arguments |
Definition at line 836 of file Maintenance.php.
References $self, loadSpecialVars(), and loadWithArgv().
|
protected |
Handle the special variables that are global to all scripts.
Definition at line 875 of file Maintenance.php.
References getOption(), and hasOption().
Referenced by loadParamsAndArgs(), and loadWithArgv().
| MediaWiki\Maintenance\Maintenance::loadWithArgv | ( | $argv | ) |
Load params and arguments from a given array of command-line arguments.
| array | $argv | The argument array, not including the script itself. |
Definition at line 813 of file Maintenance.php.
References loadSpecialVars(), and maybeHelp().
Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\BackupDumper\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), and loadParamsAndArgs().
|
protected |
Maybe show the help.
If the help is shown, exit.
| bool | $force | Whether to force the help to show, default false |
Definition at line 895 of file Maintenance.php.
References error(), fatalError(), hasOption(), and showHelp().
Referenced by loadWithArgv(), and validateParamsAndArgs().
| MediaWiki\Maintenance\Maintenance::memoryLimit | ( | ) |
Override memory_limit from php.ini on maintenance scripts.
This defaults to max/unlimited, but some scripts may wish to set a lower limit, to avoid blowing up unexpectedly and/or taking available memory for other processes.
Definition at line 784 of file Maintenance.php.
|
finalprotected |
Wrap an entry iterator into a generator that returns batches of said entries.
The batch size is determined by getBatchSize().
| iterable | Generator | Closure | $source | An iterable or a callback to get one |
Definition at line 1372 of file Maintenance.php.
References $source, and getBatchSize().
|
protected |
Throw some output to the user.
Scripts can call this with no fears, as we handle all –quiet stuff here
| string | $out | The text to show to the user |
| string | null | $channel | Unique identifier for the channel. See function outputChanneled. |
Definition at line 485 of file Maintenance.php.
References cleanupChanneled(), getServiceContainer(), and outputChanneled().
Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), MediaWiki\Maintenance\Benchmarker\addResult(), countDown(), CleanupWatchlistLabelMember\doDBUpdates(), CleanupWatchlistTemporaryAccountRows\doDBUpdates(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), MigrateBlocks\doDBUpdates(), MigrateLinksTable\doDBUpdates(), BenchmarkLCStore\execute(), BenchmarkPurge\execute(), BenchmarkRebuildLocalisationCache\execute(), MediaWiki\Maintenance\ApplyChangeTag\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), MediaWiki\Maintenance\SchemaMaintenance\execute(), MediaWiki\Maintenance\UpdateCredits\execute(), MediaWiki\Maintenance\Version\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), purgeRedundantText(), showHelp(), MediaWiki\Maintenance\Benchmarker\startBench(), and MediaWiki\Maintenance\Benchmarker\verboseRun().
| MediaWiki\Maintenance\Maintenance::outputChanneled | ( | $msg, | |
| $channel = null ) |
Message outputter with channeled message support.
Messages on the same channel are concatenated, but any intervening messages in another channel start a new line.
| string | false | $msg | The message without trailing newline |
| string | null | $channel | Channel identifier or null for no channel. Channel comparison uses ===. |
Definition at line 580 of file Maintenance.php.
References cleanupChanneled().
|
protected |
Utility function to parse a string (perhaps from a command line option) into a list of integers (perhaps some kind of numeric IDs).
| string | $text |
Definition at line 1591 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\ApplyChangeTag\execute().
|
static |
Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but treating stout as not a tty to avoid color codes.
| mixed | $fd | File descriptor |
Definition at line 1427 of file Maintenance.php.
References posix_isatty().
Referenced by posix_isatty().
|
protected |
| string | $prompt | The prompt to display to the user |
| string | null | $default | The default value to return if the user just presses enter |
Definition at line 1636 of file Maintenance.php.
|
protected |
| string | $prompt | The prompt to display to the user |
| bool | null | $default | The default value to return if the user just presses enter |
Definition at line 1658 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::purgeRedundantText | ( | $delete = true | ) |
Support function for cleaning up redundant text records.
| bool | $delete | Whether or not to actually delete the records |
Definition at line 1009 of file Maintenance.php.
References beginTransactionRound(), commitTransactionRound(), getConfig(), getPrimaryDB(), getServiceContainer(), MediaWiki\MainConfigNames\MiserMode, and output().
|
static |
Prompt the console for input.
| string | $prompt | What to begin the line with, like '> ' |
Definition at line 1440 of file Maintenance.php.
|
protected |
Indicate that the specified extension must be loaded before the script can run.
This must be called in the constructor.
| string | $name |
Definition at line 692 of file Maintenance.php.
|
static |
Call this to set up the autoloader to allow classes to be used from the tests directory.
Definition at line 1549 of file Maintenance.php.
|
protected |
Rollback the transaction on a DB handle.
Maintenance scripts should call this method instead of IDatabase::rollback(). Use of this method makes it clear that the caller is a maintenance script, which has the outermost transaction scope needed to explicitly roll back transactions.
Use this method for scripts with direct, straightforward, control of all writes.
| IDatabase | $dbw | |
| string | $fname | Caller name |
rollbackTransactionRound() instead Definition at line 1230 of file Maintenance.php.
References Wikimedia\Rdbms\IDatabase\rollback().
|
protected |
Rollback a transactional batch of DB operations.
Use this method for scripts that split up their work into logical transactions. Note that this does not call ILBfactory::flushPrimarySessions().
| string | $fname | Caller name |
Definition at line 1357 of file Maintenance.php.
|
protected |
Sets whether to allow unregistered options, which are options passed to a script that do not match an expected parameter.
| bool | $allow | Should we allow? |
Definition at line 327 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::setArg | ( | $argId, | |
| $value ) |
Programmatically set the value of the given argument.
Useful for setting up child scripts, see createChild().
| string | int | $argId | Arg index or name |
| mixed | null | $value |
Definition at line 407 of file Maintenance.php.
References setArg().
Referenced by setArg().
|
protected |
| int | $s | The number of operations to do in a batch |
Definition at line 425 of file Maintenance.php.
References addOption(), and supportsOption().
Referenced by CleanupWatchlistLabelMember\__construct(), CleanupWatchlistTemporaryAccountRows\__construct(), FixWrongPasswordPrefixes\__construct(), MediaWiki\Maintenance\ApplyChangeTag\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), MediaWiki\Maintenance\FixAutoblockLogTitles\__construct(), MediaWiki\Maintenance\LoggedUpdateMaintenance\__construct(), MediaWiki\Maintenance\UpdateRestrictions\__construct(), MigrateBlocks\__construct(), MigrateLinksTable\__construct(), and PopulateUserIsTemp\__construct().
| MediaWiki\Maintenance\Maintenance::setConfig | ( | Config | $config | ) |
| MediaWiki\Maintenance\Maintenance::setDB | ( | IMaintainableDatabase | $db | ) |
Sets database object to be returned by getDB().
| IMaintainableDatabase | $db |
Reimplemented in MediaWiki\Maintenance\BackupDumper.
Definition at line 1113 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::setLBFactory | ( | ILBFactory | $lbFactory | ) |
| ILBFactory | $lbFactory | LBFactory to inject in place of the service instance |
Definition at line 1152 of file Maintenance.php.
| MediaWiki\Maintenance\Maintenance::setName | ( | string | $name | ) |
| MediaWiki\Maintenance\Maintenance::setOption | ( | string | $name, |
| $value ) |
Programmatically set the value of the given option.
Useful for setting up child scripts, see createChild().
| string | $name | |
| mixed | null | $value |
Definition at line 394 of file Maintenance.php.
References setOption().
Referenced by MediaWiki\Maintenance\LoggedUpdateMaintenance\setForce(), and setOption().
| MediaWiki\Maintenance\Maintenance::setup | ( | ) |
Provides subclasses with an opportunity to perform initial checks.
Definition at line 768 of file Maintenance.php.
|
protected |
Definitely show the help.
Does not exit.
Definition at line 919 of file Maintenance.php.
References output().
Referenced by maybeHelp().
|
protected |
Checks to see if a particular option in supported.
Normally this means it has been registered by the script via addOption.
| string | $name | The name of the option |
Definition at line 250 of file Maintenance.php.
Referenced by setBatchSize().
| MediaWiki\Maintenance\Maintenance::validateParamsAndArgs | ( | ) |
Run some validation checks on the params, etc.
Definition at line 865 of file Maintenance.php.
References maybeHelp().
|
protected |
| string | $errorMsg | Error message to be displayed if neither –user or –userid are passed. |
Definition at line 1609 of file Maintenance.php.
References fatalError(), getOption(), and hasOption().
|
protected |
Wait for replica DB servers to catch up.
Use this method after performing a batch of autocommit writes inscripts with direct, straightforward, control of all writes.
commitTransactionRound() instead Definition at line 1268 of file Maintenance.php.
References MediaWiki\MediaWikiEntryPoint\emitBufferedStats(), and getServiceContainer().
Referenced by commitTransaction(), and MediaWiki\Maintenance\DeleteLocalPasswords\processUsers().
| resource null MediaWiki\Maintenance\Maintenance::$fileHandle |
Used when creating separate schema files.
Definition at line 146 of file Maintenance.php.
|
protected |
This is the list of arguments that were actually passed.
Definition at line 103 of file Maintenance.php.
|
protected |
Batch size.
If a script supports this, they should set a default with setBatchSize()
Definition at line 131 of file Maintenance.php.
|
protected |
Definition at line 111 of file Maintenance.php.
|
protected |
Definition at line 110 of file Maintenance.php.
|
protected |
A description of the script, children should change this via addDescription().
Definition at line 117 of file Maintenance.php.
|
protected |
Have we already loaded our user input?
Definition at line 123 of file Maintenance.php.
|
protected |
This is the list of options that were actually passed.
Definition at line 97 of file Maintenance.php.
|
protected |
Empty.
Definition at line 91 of file Maintenance.php.
|
protected |
Special vars for params that are always used.
Definition at line 109 of file Maintenance.php.
|
protected |
Name of the script currently running.
Definition at line 106 of file Maintenance.php.
| array MediaWiki\Maintenance\Maintenance::$orderedOptions = [] |
Used to read the options in the order they were passed.
Useful for option chaining (Ex. dumpBackup.php). It will be an empty array if the options are passed in through loadParamsAndArgs( $self, $opts, $args ).
This is an array of arrays where 0 => the option and 1 => parameter value.
Definition at line 179 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\BackupDumper\processOptions().
|
protected |
Definition at line 83 of file Maintenance.php.
| const MediaWiki\Maintenance\Maintenance::DB_ADMIN = 2 |
Definition at line 71 of file Maintenance.php.
| const MediaWiki\Maintenance\Maintenance::DB_NONE = 0 |
Constants for DB access type.
Definition at line 69 of file Maintenance.php.
| const MediaWiki\Maintenance\Maintenance::DB_STD = 1 |
Definition at line 70 of file Maintenance.php.
| const MediaWiki\Maintenance\Maintenance::GENERIC_MAINTENANCE_PARAMETERS = 'Script runner options' |
Definition at line 78 of file Maintenance.php.
Referenced by MediaWiki\Maintenance\MaintenanceRunner\addDefaultParams().
| const MediaWiki\Maintenance\Maintenance::SCRIPT_DEPENDENT_PARAMETERS = 'Common options' |
Definition at line 77 of file Maintenance.php.
| const MediaWiki\Maintenance\Maintenance::STDIN_ALL = -1 |
Definition at line 74 of file Maintenance.php.