MediaWiki master
MediaWiki\Maintenance\Maintenance Class Reference

Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effort. More...

Inherited by AddChangeTag, AddSite, AttachLatest, BackupReader, BenchmarkParse, BlockUsers, CLIParser, CategoryChangesAsRdf, ChangePassword, CheckBadRedirects, CheckComposerLockUpToDate, CheckDependencies, CheckImages, CheckSignatures, CheckUsernames, CleanupInvalidDbKeys, CleanupPreferences, CleanupRemovedModules, CleanupSpam, CleanupUploadStash, ClearInterwikiCache, CommandLineInc, CommandLineInstaller, CompareLanguageConverterOutput, CompareParserCache, ConvertExtensionToRegistration, ConvertExtensionsMessagesToTranslationAlias, CopyFileBackend, CopyJobQueue, CreateAndPromote, CreateBotPassword, DatabaseLag, DeleteArchivedFiles, DeleteArchivedRevisions, DeleteAutoPatrolLogs, DeleteBatch, DeleteDefaultMessages, DeleteEqualMessages, DeleteOldRevisions, DeleteOrphanedRevisions, DeleteSelfExternals, DeleteTag, DeleteUserEmail, DumpCategoriesAsRdf, DumpIterator, DumpLinks, DumpRenderer, DumpUploads, EditCLI, EmptyUserGroup, EraseArchivedFile, ExpireTemporaryAccounts, ExportSites, FetchText, FileOpPerfTest, FindBadBlobs, FindClasses, FindDeprecated, FindMissingActors, FindMissingFiles, FindOrphanedFiles, FixDoubleRedirects, FixMergeHistoryCorruption, FixTimestamps, FixUserRegistration, FormatInstallDoc, GenerateAutoload, GenerateConfigSchema, GenerateJsonI18n, GeneratePhpCharToUpperMappings, GenerateSitemap, GetConfiguration, GetLagTimes, GetReplicaServer, GetTextMaint, GrepPages, ImageBuilder, ImportImages, ImportSiteScripts, ImportSites, ImportTextFiles, InitEditCount, InitSiteStats, InitUserPreference, InstallPreConfigured, InvalidateBotPasswords, InvalidateUserSessions, JSParseHelper, MWDocGen, MWEval, MakeTestEdits, ManageForeignResources, ManageJobs, McTest, Mcc, MediaWiki\Maintenance\BackupDumper, MediaWiki\Maintenance\Benchmarker, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\FakeMaintenance, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, MediaWiki\Maintenance\Version, MediaWikiShell, MergeMessageFileList, MigrateFileRepoLayout, MigrateUserGroup, MoveBatch, MwSql, MysqlMaintenance, NamespaceDupes, NukeNS, NukePage, PageExists, PatchSql, PopulateInterwiki, PrewarmParsoidParserCache, Protect, PruneFileCache, PruneUnusedLinkTargetRows, PurgeChangedFiles, PurgeChangedPages, PurgeExpiredBlocks, PurgeExpiredUserrights, PurgeExpiredWatchlistItems, PurgeList, PurgeMessageBlobStore, PurgeModuleDeps, PurgeOldText, PurgePage, PurgeParserCache, PurgeRecentChanges, ReassignEdits, RebuildAll, RebuildFileCache, RebuildLocalisationCache, RebuildMessages, RebuildRecentchanges, RebuildTextIndex, RecountCategories, RefreshFileHeaders, RefreshImageMetadata, RefreshLinks, RemoveInvalidEmails, RemoveUnusedAccounts, RenameDbPrefix, RenameRestrictions, RenameUser, RenameUsersMatchingPattern, ResetAuthenticationThrottle, ResetPageRandom, ResetUserEmail, RollbackEdits, RunBatchedQuery, RunJobs, ShowJobs, ShowSiteStats, SqliteMaintenance, TableCleanup, Undelete, UpdateArticleCount, UpdateCollation, UpdateExtensionJsonSchema, UpdateMediaWiki, UpdateRestrictions, UpdateSearchIndex, UpdateSpecialPages, UppercaseTitlesForUnicodeTransition, UserOptionsMaintenance, ValidateRegistrationFile, ViewCLI, WikiBirthday, and WrapOldPasswords.

Collaboration diagram for MediaWiki\Maintenance\Maintenance:

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? By default, we give Maintenance scripts normal rights to the DB.
 
 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 ()
 Normally we disable the memory_limit when running admin scripts.
 
 outputChanneled ( $msg, $channel=null)
 Message outputter with channeled message support.
 
 purgeRedundantText ( $delete=true)
 Support function for cleaning up redundant text records.
 
 runChild ( $maintClass, $classFile=null)
 Returns an instance of the given maintenance script, with all of the current arguments passed to it.
 
 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, $die=0)
 Throw an error to the user.
 
 fatalError ( $msg, $exitCode=1)
 Output a message and terminate the current script.
 
 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 ()
 
 getReplicaDB ()
 
 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)
 
 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
 

Detailed Description

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.

Stability: stable
to extend
Since
1.16

Definition at line 78 of file Maintenance.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Maintenance\Maintenance::__construct ( )

Default constructor.

Children should call this first if implementing their own constructors

Stability: stable
to call

Reimplemented in AddChangeTag, AddSite, AttachLatest, BenchmarkParse, BlockUsers, CategoryChangesAsRdf, ChangePassword, CheckBadRedirects, CheckComposerLockUpToDate, CheckDependencies, CheckImages, CheckSignatures, CheckUsernames, CleanupCaps, CleanupEmptyCategories, CleanupImages, CleanupInvalidDbKeys, CleanupPageLang, CleanupPreferences, CleanupRemovedModules, CleanupSpam, TitleCleanup, CleanupUploadStash, CleanupWatchlist, ClearInterwikiCache, CommandLineInc, CompareLanguageConverterOutput, CompareParserCache, CompareParsers, ConvertExtensionsMessagesToTranslationAlias, ConvertExtensionToRegistration, CopyFileBackend, CopyJobQueue, CreateAndPromote, CreateBotPassword, DeleteArchivedFiles, DeleteArchivedRevisions, DeleteAutoPatrolLogs, DeleteBatch, DeleteDefaultMessages, DeleteEqualMessages, DeleteOldRevisions, DeleteOrphanedRevisions, DeleteSelfExternals, DeleteTag, DeleteUserEmail, DumpCategoriesAsRdf, DumpIterator, SearchDump, DumpLinks, DumpUploads, EditCLI, EmptyUserGroup, EraseArchivedFile, MWEval, ExpireTemporaryAccounts, ExportSites, FetchText, FileOpPerfTest, FindBadBlobs, FindClasses, FindDeprecated, FindMissingActors, FindMissingFiles, FindOrphanedFiles, MediaWiki\Maintenance\FixAutoblockLogTitles, FixDoubleRedirects, FixInconsistentRedirects, FixMergeHistoryCorruption, FixTimestamps, FixUserRegistration, FormatInstallDoc, GenerateConfigSchema, GenerateJsonI18n, GenerateSchemaChangeSql, GenerateSchemaSql, GenerateSitemap, GetConfiguration, GetLagTimes, GetReplicaServer, GetTextMaint, GrepPages, BackupReader, ImportImages, ImportSites, ImportSiteScripts, ImportTextFiles, MediaWiki\Maintenance\Benchmarker, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, InitEditCount, InitSiteStats, InitUserPreference, CommandLineInstaller, InstallPreConfigured, InvalidateBotPasswords, InvalidateUserSessions, JSParseHelper, DatabaseLag, MakeTestEdits, ManageForeignResources, ManageJobs, Mcc, McTest, GeneratePhpCharToUpperMappings, MergeMessageFileList, MigrateBlocks, MigrateExternallinks, MigrateFileRepoLayout, MigrateLinksTable, MigrateRevisionActorTemp, MigrateRevisionCommentTemp, MigrateUserGroup, MoveBatch, MWDocGen, MysqlMaintenance, NamespaceDupes, NukeNS, NukePage, PageExists, CLIParser, PatchSql, PopulateChangeTagDef, PopulateInterwiki, PopulateUserIsTemp, PrewarmParsoidParserCache, Protect, PruneFileCache, PruneUnusedLinkTargetRows, PurgeChangedFiles, PurgeChangedPages, PurgeExpiredBlocks, PurgeExpiredUserrights, PurgeExpiredWatchlistItems, PurgeList, PurgeModuleDeps, PurgeOldText, PurgePage, PurgeParserCache, PurgeRecentChanges, ReassignEdits, RebuildAll, RebuildFileCache, ImageBuilder, RebuildLocalisationCache, RebuildMessages, RebuildRecentchanges, RebuildTextIndex, RecountCategories, RefreshFileHeaders, RefreshImageMetadata, RefreshLinks, RemoveInvalidEmails, RemoveUnusedAccounts, RenameDbPrefix, RenameRestrictions, RenameUser, RenameUsersMatchingPattern, DumpRenderer, ResetAuthenticationThrottle, ResetPageRandom, ResetUserEmail, RollbackEdits, RunBatchedQuery, RunJobs, MediaWikiShell, ShowJobs, ShowSiteStats, MwSql, SqliteMaintenance, TableCleanup, Undelete, UpdateMediaWiki, UpdateArticleCount, UpdateCollation, UpdateExtensionJsonSchema, UpdateRestrictions, UpdateSearchIndex, UpdateSpecialPages, UppercaseTitlesForUnicodeTransition, UserOptionsMaintenance, ValidateRegistrationFile, MediaWiki\Maintenance\Version, ViewCLI, WikiBirthday, and WrapOldPasswords.

Definition at line 206 of file Maintenance.php.

References MediaWiki\Maintenance\Maintenance\addDefaultParams().

Member Function Documentation

◆ addArg()

MediaWiki\Maintenance\Maintenance::addArg ( $arg,
$description,
$required = true,
$multi = false )
protected

Add some args that are needed.

Parameters
string$argName of the arg, like 'start'
string$descriptionShort description of the arg
bool$requiredIs this required?
bool$multiDoes it allow multiple values? (Last arg only)

Definition at line 318 of file Maintenance.php.

Referenced by AddSite\__construct(), BenchmarkParse\__construct(), BlockUsers\__construct(), CleanupSpam\__construct(), CompareLanguageConverterOutput\__construct(), ConvertExtensionsMessagesToTranslationAlias\__construct(), ConvertExtensionToRegistration\__construct(), CreateAndPromote\__construct(), CreateBotPassword\__construct(), DeleteBatch\__construct(), DeleteOldRevisions\__construct(), DeleteTag\__construct(), DeleteUserEmail\__construct(), EditCLI\__construct(), EmptyUserGroup\__construct(), ExportSites\__construct(), FixTimestamps\__construct(), FormatInstallDoc\__construct(), GenerateJsonI18n\__construct(), GetTextMaint\__construct(), GrepPages\__construct(), BackupReader\__construct(), ImportImages\__construct(), ImportSites\__construct(), ImportSiteScripts\__construct(), ImportTextFiles\__construct(), CommandLineInstaller\__construct(), JSParseHelper\__construct(), ManageForeignResources\__construct(), McTest\__construct(), MigrateUserGroup\__construct(), MoveBatch\__construct(), MysqlMaintenance\__construct(), NukePage\__construct(), PageExists\__construct(), CLIParser\__construct(), PatchSql\__construct(), Protect\__construct(), ReassignEdits\__construct(), RefreshLinks\__construct(), RenameRestrictions\__construct(), RenameUser\__construct(), ResetUserEmail\__construct(), Undelete\__construct(), UpdateExtensionJsonSchema\__construct(), UserOptionsMaintenance\__construct(), ValidateRegistrationFile\__construct(), and ViewCLI\__construct().

◆ addDefaultParams()

MediaWiki\Maintenance\Maintenance::addDefaultParams ( )
protected

Add the default parameters to the scripts.

Definition at line 644 of file Maintenance.php.

Referenced by MediaWiki\Maintenance\Maintenance\__construct().

◆ addDescription()

MediaWiki\Maintenance\Maintenance::addDescription ( $text)
protected

Set the description text.

Parameters
string$textThe text of the description

Definition at line 343 of file Maintenance.php.

Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), AddChangeTag\__construct(), AddSite\__construct(), AttachLatest\__construct(), BenchmarkParse\__construct(), BlockUsers\__construct(), CategoryChangesAsRdf\__construct(), ChangePassword\__construct(), CheckBadRedirects\__construct(), CheckComposerLockUpToDate\__construct(), CheckDependencies\__construct(), CheckImages\__construct(), CheckSignatures\__construct(), CheckUsernames\__construct(), CleanupCaps\__construct(), CleanupEmptyCategories\__construct(), CleanupImages\__construct(), CleanupInvalidDbKeys\__construct(), CleanupPageLang\__construct(), CleanupPreferences\__construct(), CleanupRemovedModules\__construct(), CleanupSpam\__construct(), TitleCleanup\__construct(), CleanupUploadStash\__construct(), CleanupWatchlist\__construct(), ClearInterwikiCache\__construct(), CompareLanguageConverterOutput\__construct(), CompareParserCache\__construct(), CompareParsers\__construct(), ConvertExtensionsMessagesToTranslationAlias\__construct(), ConvertExtensionToRegistration\__construct(), CopyFileBackend\__construct(), CopyJobQueue\__construct(), CreateAndPromote\__construct(), CreateBotPassword\__construct(), DeleteArchivedFiles\__construct(), DeleteArchivedRevisions\__construct(), DeleteAutoPatrolLogs\__construct(), DeleteBatch\__construct(), DeleteDefaultMessages\__construct(), DeleteEqualMessages\__construct(), DeleteOldRevisions\__construct(), DeleteOrphanedRevisions\__construct(), DeleteSelfExternals\__construct(), DeleteTag\__construct(), DeleteUserEmail\__construct(), DumpCategoriesAsRdf\__construct(), DumpIterator\__construct(), SearchDump\__construct(), DumpLinks\__construct(), DumpUploads\__construct(), EditCLI\__construct(), EmptyUserGroup\__construct(), EraseArchivedFile\__construct(), MWEval\__construct(), ExpireTemporaryAccounts\__construct(), ExportSites\__construct(), FetchText\__construct(), FileOpPerfTest\__construct(), FindBadBlobs\__construct(), FindClasses\__construct(), FindDeprecated\__construct(), FindMissingActors\__construct(), FindMissingFiles\__construct(), FindOrphanedFiles\__construct(), MediaWiki\Maintenance\FixAutoblockLogTitles\__construct(), FixDoubleRedirects\__construct(), FixInconsistentRedirects\__construct(), FixMergeHistoryCorruption\__construct(), FixTimestamps\__construct(), FixUserRegistration\__construct(), GenerateConfigSchema\__construct(), GenerateJsonI18n\__construct(), GenerateSchemaChangeSql\__construct(), GenerateSchemaSql\__construct(), GenerateSitemap\__construct(), GetConfiguration\__construct(), GetLagTimes\__construct(), GetReplicaServer\__construct(), GetTextMaint\__construct(), GrepPages\__construct(), BackupReader\__construct(), ImportImages\__construct(), ImportSites\__construct(), ImportSiteScripts\__construct(), ImportTextFiles\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), InitEditCount\__construct(), InitSiteStats\__construct(), CommandLineInstaller\__construct(), InstallPreConfigured\__construct(), InvalidateBotPasswords\__construct(), InvalidateUserSessions\__construct(), JSParseHelper\__construct(), DatabaseLag\__construct(), MakeTestEdits\__construct(), ManageForeignResources\__construct(), ManageJobs\__construct(), Mcc\__construct(), McTest\__construct(), GeneratePhpCharToUpperMappings\__construct(), MergeMessageFileList\__construct(), MigrateBlocks\__construct(), MigrateExternallinks\__construct(), MigrateFileRepoLayout\__construct(), MigrateLinksTable\__construct(), MigrateRevisionActorTemp\__construct(), MigrateRevisionCommentTemp\__construct(), MigrateUserGroup\__construct(), MoveBatch\__construct(), MWDocGen\__construct(), MysqlMaintenance\__construct(), NamespaceDupes\__construct(), NukeNS\__construct(), NukePage\__construct(), PageExists\__construct(), CLIParser\__construct(), PatchSql\__construct(), PopulateChangeTagDef\__construct(), PopulateInterwiki\__construct(), PopulateUserIsTemp\__construct(), PrewarmParsoidParserCache\__construct(), Protect\__construct(), PruneFileCache\__construct(), PruneUnusedLinkTargetRows\__construct(), PurgeChangedFiles\__construct(), PurgeChangedPages\__construct(), PurgeExpiredBlocks\__construct(), PurgeExpiredUserrights\__construct(), PurgeExpiredWatchlistItems\__construct(), PurgeList\__construct(), PurgeModuleDeps\__construct(), PurgeOldText\__construct(), PurgePage\__construct(), PurgeParserCache\__construct(), PurgeRecentChanges\__construct(), ReassignEdits\__construct(), RebuildAll\__construct(), RebuildFileCache\__construct(), ImageBuilder\__construct(), RebuildLocalisationCache\__construct(), RebuildMessages\__construct(), RebuildRecentchanges\__construct(), RebuildTextIndex\__construct(), RecountCategories\__construct(), RefreshFileHeaders\__construct(), RefreshImageMetadata\__construct(), RefreshLinks\__construct(), RenameRestrictions\__construct(), RenameUser\__construct(), RenameUsersMatchingPattern\__construct(), DumpRenderer\__construct(), ResetAuthenticationThrottle\__construct(), ResetPageRandom\__construct(), ResetUserEmail\__construct(), RollbackEdits\__construct(), RunBatchedQuery\__construct(), RunJobs\__construct(), ShowJobs\__construct(), ShowSiteStats\__construct(), MwSql\__construct(), SqliteMaintenance\__construct(), Undelete\__construct(), UpdateMediaWiki\__construct(), UpdateArticleCount\__construct(), UpdateCollation\__construct(), UpdateExtensionJsonSchema\__construct(), UpdateRestrictions\__construct(), UpdateSearchIndex\__construct(), UppercaseTitlesForUnicodeTransition\__construct(), UserOptionsMaintenance\__construct(), MediaWiki\Maintenance\Version\__construct(), ViewCLI\__construct(), WikiBirthday\__construct(), and WrapOldPasswords\__construct().

◆ addOption()

MediaWiki\Maintenance\Maintenance::addOption ( $name,
$description,
$required = false,
$withArg = false,
$shortName = false,
$multiOccurrence = false )
protected

Add a parameter to the script.

Will be displayed on –help with the associated description

Parameters
string$nameThe name of the param (help, version, etc)
string$descriptionThe description of the param to show on –help
bool$requiredIs the param required?
bool$withArgIs an argument required with this option?
string | bool$shortNameCharacter to use as short name
bool$multiOccurrenceCan this option be passed multiple times?

Definition at line 273 of file Maintenance.php.

Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\BackupDumper\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), AddChangeTag\__construct(), AddSite\__construct(), AttachLatest\__construct(), BenchmarkParse\__construct(), BlockUsers\__construct(), CategoryChangesAsRdf\__construct(), ChangePassword\__construct(), CheckDependencies\__construct(), CleanupCaps\__construct(), CleanupInvalidDbKeys\__construct(), CleanupPreferences\__construct(), CleanupSpam\__construct(), TitleCleanup\__construct(), CleanupWatchlist\__construct(), CommandLineInc\__construct(), CompareParserCache\__construct(), CompareParsers\__construct(), ConvertExtensionToRegistration\__construct(), CopyFileBackend\__construct(), CopyJobQueue\__construct(), CreateAndPromote\__construct(), CreateBotPassword\__construct(), DeleteArchivedFiles\__construct(), DeleteArchivedRevisions\__construct(), DeleteAutoPatrolLogs\__construct(), DeleteBatch\__construct(), DeleteDefaultMessages\__construct(), DeleteEqualMessages\__construct(), DeleteOldRevisions\__construct(), DeleteOrphanedRevisions\__construct(), DumpCategoriesAsRdf\__construct(), DumpIterator\__construct(), SearchDump\__construct(), DumpUploads\__construct(), EditCLI\__construct(), EraseArchivedFile\__construct(), MWEval\__construct(), ExpireTemporaryAccounts\__construct(), FileOpPerfTest\__construct(), FindBadBlobs\__construct(), FindMissingActors\__construct(), FindMissingFiles\__construct(), FindOrphanedFiles\__construct(), FixDoubleRedirects\__construct(), FixMergeHistoryCorruption\__construct(), FormatInstallDoc\__construct(), GenerateConfigSchema\__construct(), GenerateJsonI18n\__construct(), GenerateSitemap\__construct(), GetConfiguration\__construct(), GetLagTimes\__construct(), GetReplicaServer\__construct(), GetTextMaint\__construct(), GrepPages\__construct(), BackupReader\__construct(), ImportImages\__construct(), ImportSiteScripts\__construct(), ImportTextFiles\__construct(), MediaWiki\Maintenance\Benchmarker\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), MediaWiki\Maintenance\LoggedUpdateMaintenance\__construct(), MediaWiki\Maintenance\SchemaMaintenance\__construct(), InitEditCount\__construct(), InitSiteStats\__construct(), InitUserPreference\__construct(), CommandLineInstaller\__construct(), InstallPreConfigured\__construct(), InvalidateBotPasswords\__construct(), InvalidateUserSessions\__construct(), DatabaseLag\__construct(), MakeTestEdits\__construct(), ManageForeignResources\__construct(), ManageJobs\__construct(), Mcc\__construct(), McTest\__construct(), MergeMessageFileList\__construct(), MigrateBlocks\__construct(), MigrateExternallinks\__construct(), MigrateFileRepoLayout\__construct(), MigrateLinksTable\__construct(), MigrateRevisionActorTemp\__construct(), MigrateRevisionCommentTemp\__construct(), MoveBatch\__construct(), MWDocGen\__construct(), MysqlMaintenance\__construct(), NamespaceDupes\__construct(), NukeNS\__construct(), NukePage\__construct(), CLIParser\__construct(), PopulateChangeTagDef\__construct(), PopulateInterwiki\__construct(), PrewarmParsoidParserCache\__construct(), Protect\__construct(), PruneFileCache\__construct(), PruneUnusedLinkTargetRows\__construct(), PurgeChangedFiles\__construct(), PurgeChangedPages\__construct(), PurgeList\__construct(), PurgeOldText\__construct(), PurgePage\__construct(), PurgeParserCache\__construct(), ReassignEdits\__construct(), RebuildFileCache\__construct(), ImageBuilder\__construct(), RebuildLocalisationCache\__construct(), RebuildRecentchanges\__construct(), RecountCategories\__construct(), RefreshFileHeaders\__construct(), RefreshImageMetadata\__construct(), RefreshLinks\__construct(), RemoveInvalidEmails\__construct(), RemoveUnusedAccounts\__construct(), RenameDbPrefix\__construct(), RenameUser\__construct(), RenameUsersMatchingPattern\__construct(), DumpRenderer\__construct(), ResetAuthenticationThrottle\__construct(), ResetPageRandom\__construct(), ResetUserEmail\__construct(), RollbackEdits\__construct(), RunBatchedQuery\__construct(), RunJobs\__construct(), MediaWikiShell\__construct(), ShowJobs\__construct(), MwSql\__construct(), SqliteMaintenance\__construct(), TableCleanup\__construct(), Undelete\__construct(), UpdateMediaWiki\__construct(), UpdateArticleCount\__construct(), UpdateCollation\__construct(), UpdateSearchIndex\__construct(), UpdateSpecialPages\__construct(), UppercaseTitlesForUnicodeTransition\__construct(), UserOptionsMaintenance\__construct(), WrapOldPasswords\__construct(), MediaWiki\Maintenance\BackupDumper\finalSetup(), and UpdateMediaWiki\validateParamsAndArgs().

◆ afterFinalSetup()

MediaWiki\Maintenance\Maintenance::afterFinalSetup ( )
protected

Override to perform any required operation at the end of initialisation.

Stability: stable
to override

Reimplemented in UpdateMediaWiki.

Definition at line 1041 of file Maintenance.php.

◆ beginTransaction()

MediaWiki\Maintenance\Maintenance::beginTransaction ( IDatabase $dbw,
$fname )
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.

Parameters
IDatabase$dbw
string$fnameCaller name
Since
1.27
Deprecated
Since 1.44 Use beginTransactionRound() instead

Definition at line 1204 of file Maintenance.php.

References Wikimedia\Rdbms\IDatabase\begin().

Referenced by NukePage\deleteRevisions(), CleanupRemovedModules\execute(), DeleteArchivedFiles\execute(), DeleteOrphanedRevisions\execute(), MigrateUserGroup\execute(), NukeNS\execute(), NukePage\execute(), PurgeModuleDeps\execute(), RebuildFileCache\execute(), UpdateRestrictions\execute(), and WrapOldPasswords\execute().

◆ beginTransactionRound()

MediaWiki\Maintenance\Maintenance::beginTransactionRound ( $fname)
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.

See also
ILBfactory::beginPrimaryChanges()
Parameters
string$fnameCaller name
Returns
void
Since
1.44

Definition at line 1304 of file Maintenance.php.

Referenced by CleanupSpam\execute(), ImportSiteScripts\execute(), MakeTestEdits\execute(), MoveBatch\execute(), Protect\execute(), RollbackEdits\execute(), and Undelete\execute().

◆ canExecuteWithoutLocalSettings()

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.

Note
Subclasses that override this method to return true should also override getDbType() to return self::DB_NONE, unless they are going to use the database connection when it is available.
See also
getDbType()
Since
1.40
Stability: stable
to override
Returns
bool

Reimplemented in CheckComposerLockUpToDate, MWEval, GenerateAutoload, GenerateConfigSchema, MediaWiki\Maintenance\SchemaMaintenance, CommandLineInstaller, MediaWikiShell, and MediaWiki\Maintenance\Version.

Definition at line 248 of file Maintenance.php.

◆ checkRequiredExtensions()

MediaWiki\Maintenance\Maintenance::checkRequiredExtensions ( )

Verify that the required extensions are installed.

Since
1.28

Definition at line 721 of file Maintenance.php.

◆ cleanupChanneled()

MediaWiki\Maintenance\Maintenance::cleanupChanneled ( )

Clean up channeled output.

Output a newline if necessary.

Definition at line 582 of file Maintenance.php.

◆ clearParamsAndArgs()

MediaWiki\Maintenance\Maintenance::clearParamsAndArgs ( )

Clear all params and arguments.

Definition at line 823 of file Maintenance.php.

◆ commitTransaction()

MediaWiki\Maintenance\Maintenance::commitTransaction ( IDatabase $dbw,
$fname )
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.

Parameters
IDatabase$dbw
string$fnameCaller name
Returns
bool Whether the replication wait succeeded
Since
1.27
Deprecated
Since 1.44 Use commitTransactionRound() instead

Definition at line 1225 of file Maintenance.php.

References Wikimedia\Rdbms\IDatabase\commit().

Referenced by NukePage\deleteRevisions(), CleanupRemovedModules\execute(), DeleteArchivedFiles\execute(), DeleteOrphanedRevisions\execute(), MigrateUserGroup\execute(), NukeNS\execute(), NukePage\execute(), PurgeModuleDeps\execute(), RebuildFileCache\execute(), UpdateRestrictions\execute(), and WrapOldPasswords\execute().

◆ commitTransactionRound()

MediaWiki\Maintenance\Maintenance::commitTransactionRound ( $fname)
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().

See also
ILBfactory::commitPrimaryChanges()
Parameters
string$fnameCaller name
Returns
bool Whether the replication wait succeeded
Since
1.44

Definition at line 1323 of file Maintenance.php.

Referenced by CleanupSpam\execute(), ImportSiteScripts\execute(), MakeTestEdits\execute(), MoveBatch\execute(), Protect\execute(), RollbackEdits\execute(), and Undelete\execute().

◆ countDown()

MediaWiki\Maintenance\Maintenance::countDown ( $seconds)
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.

Since
1.31
Parameters
int$seconds

Definition at line 1410 of file Maintenance.php.

Referenced by DeleteAutoPatrolLogs\execute(), and UpdateMediaWiki\execute().

◆ createChild()

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

Parameters
string$maintClassA name of a child maintenance class
string | null$classFileFull path of where the child is
Stability: stable
to override
Returns
Maintenance The created instance, which the caller is expected to run by calling Maintenance::execute on the returned object.

Definition at line 771 of file Maintenance.php.

References $maintClass.

◆ deleteOption()

MediaWiki\Maintenance\Maintenance::deleteOption ( $name)
protected

Remove an option.

Useful for removing options that won't be used in your script.

Parameters
string$nameThe option to remove.

Definition at line 326 of file Maintenance.php.

◆ error()

MediaWiki\Maintenance\Maintenance::error ( $err,
$die = 0 )
protected

Throw an error to the user.

Doesn't respect –quiet, so don't use this for non-error output

Stability: stable
to override
Parameters
string | StatusValue$errThe error to display
int$dieDeprecated since 1.31, use Maintenance::fatalError() instead

Definition at line 524 of file Maintenance.php.

References wfDeprecated(), and wfMessage().

Referenced by FindOrphanedFiles\checkFiles(), CompareParsers\conclusions(), CopyFileBackend\copyFileBatch(), CopyFileBackend\delFileBatch(), MigrateRevisionActorTemp\doDBUpdates(), CleanupUploadStash\doOperations(), FileOpPerfTest\doPerfTest(), UpdateSpecialPages\doSpecialPageCacheUpdates(), CategoryChangesAsRdf\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteArchivedFiles\execute(), DumpIterator\execute(), EditCLI\execute(), FixDoubleRedirects\execute(), GenerateJsonI18n\execute(), GrepPages\execute(), ImportSiteScripts\execute(), ImportTextFiles\execute(), InstallPreConfigured\execute(), ManageForeignResources\execute(), MergeMessageFileList\execute(), MigrateFileRepoLayout\execute(), MoveBatch\execute(), PatchSql\execute(), PopulateInterwiki\execute(), PurgeChangedFiles\execute(), PurgeChangedPages\execute(), PurgeExpiredWatchlistItems\execute(), ReassignEdits\execute(), DumpRenderer\execute(), ResetUserEmail\execute(), RollbackEdits\execute(), SqliteMaintenance\execute(), UpdateSearchIndex\execute(), UppercaseTitlesForUnicodeTransition\execute(), DumpIterator\handleRevision(), DumpRenderer\handleRevision(), TitleCleanup\moveIllegalPage(), TitleCleanup\moveInconsistentPage(), CompareParsers\processRevision(), PurgeChangedFiles\purgeFromArchiveTable(), PurgeChangedFiles\purgeFromLogType(), MigrateFileRepoLayout\runBatch(), EraseArchivedFile\scrubVersion(), MwSql\sqlDoQuery(), RefreshFileHeaders\updateFileHeaders(), GetConfiguration\validateParamsAndArgs(), and CLIParser\Wikitext().

◆ execute()

MediaWiki\Maintenance\Maintenance::execute ( )
abstract

Do the actual work.

All child classes will need to implement this

Returns
bool|null|void True for success, false for failure. Not returning a value, or returning null, is also interpreted as success. Returning false for failure will cause doMaintenance.php to exit the process with a non-zero exit status.

Reimplemented in AddChangeTag, AddSite, AttachLatest, BenchmarkParse, BlockUsers, CategoryChangesAsRdf, ChangePassword, CheckBadRedirects, CheckComposerLockUpToDate, CheckDependencies, CheckImages, CheckSignatures, CheckUsernames, CleanupCaps, CleanupInvalidDbKeys, CleanupPreferences, CleanupRemovedModules, CleanupSpam, TitleCleanup, CleanupUploadStash, CleanupWatchlist, ClearInterwikiCache, CommandLineInc, CompareLanguageConverterOutput, CompareParserCache, ConvertExtensionsMessagesToTranslationAlias, ConvertExtensionToRegistration, CopyFileBackend, CopyJobQueue, CreateAndPromote, CreateBotPassword, DeleteArchivedFiles, DeleteArchivedRevisions, DeleteAutoPatrolLogs, DeleteBatch, DeleteDefaultMessages, DeleteEqualMessages, DeleteOldRevisions, DeleteOrphanedRevisions, DeleteSelfExternals, DeleteTag, DeleteUserEmail, DumpBackup, DumpCategoriesAsRdf, DumpIterator, DumpLinks, DumpUploads, EditCLI, EmptyUserGroup, EraseArchivedFile, MWEval, ExpireTemporaryAccounts, ExportSites, FetchText, FileOpPerfTest, FindBadBlobs, FindClasses, FindDeprecated, FindMissingActors, FindMissingFiles, FindOrphanedFiles, FixDoubleRedirects, FixMergeHistoryCorruption, FixTimestamps, FixUserRegistration, FormatInstallDoc, GenerateAutoload, GenerateConfigSchema, GenerateJsonI18n, GenerateSitemap, GetConfiguration, GetLagTimes, GetReplicaServer, GetTextMaint, GrepPages, BackupReader, ImportImages, ImportSites, ImportSiteScripts, ImportTextFiles, MediaWiki\Maintenance\DeleteLocalPasswords, MediaWiki\Maintenance\FakeMaintenance, MediaWiki\Maintenance\LoggedUpdateMaintenance, MediaWiki\Maintenance\SchemaMaintenance, MediaWiki\Maintenance\TextPassDumper, InitEditCount, InitSiteStats, InitUserPreference, CommandLineInstaller, InstallPreConfigured, InvalidateBotPasswords, InvalidateUserSessions, JSParseHelper, DatabaseLag, MakeTestEdits, ManageForeignResources, ManageJobs, Mcc, McTest, GeneratePhpCharToUpperMappings, MergeMessageFileList, MigrateFileRepoLayout, MigrateUserGroup, MoveBatch, MWDocGen, MysqlMaintenance, NamespaceDupes, NukeNS, NukePage, PageExists, CLIParser, PatchSql, PopulateInterwiki, PrewarmParsoidParserCache, Protect, PruneFileCache, PruneUnusedLinkTargetRows, PurgeChangedFiles, PurgeChangedPages, PurgeExpiredBlocks, PurgeExpiredUserrights, PurgeExpiredWatchlistItems, PurgeList, PurgeMessageBlobStore, PurgeModuleDeps, PurgeOldText, PurgePage, PurgeParserCache, PurgeRecentChanges, ReassignEdits, RebuildAll, RebuildFileCache, ImageBuilder, RebuildLocalisationCache, RebuildMessages, RebuildRecentchanges, RebuildTextIndex, RecountCategories, RefreshFileHeaders, RefreshImageMetadata, RefreshLinks, RemoveInvalidEmails, RemoveUnusedAccounts, RenameDbPrefix, RenameRestrictions, RenameUser, RenameUsersMatchingPattern, DumpRenderer, ResetAuthenticationThrottle, ResetPageRandom, ResetUserEmail, RollbackEdits, RunBatchedQuery, RunJobs, MediaWikiShell, ShowJobs, ShowSiteStats, MwSql, SqliteMaintenance, TableCleanup, Undelete, UpdateMediaWiki, UpdateArticleCount, UpdateCollation, UpdateExtensionJsonSchema, UpdateRestrictions, UpdateSearchIndex, UpdateSpecialPages, UppercaseTitlesForUnicodeTransition, UserOptionsMaintenance, ValidateRegistrationFile, MediaWiki\Maintenance\Version, ViewCLI, WikiBirthday, and WrapOldPasswords.

◆ fatalError()

MediaWiki\Maintenance\Maintenance::fatalError ( $msg,
$exitCode = 1 )
protected

Output a message and terminate the current script.

Stability: stable
to override
Parameters
string | StatusValue$msgError message
int$exitCodePHP exit status. Should be in range 1-254.
Since
1.31
Returns
never

Definition at line 562 of file Maintenance.php.

Referenced by ResetAuthenticationThrottle\clearLoginThrottle(), CopyFileBackend\copyFileBatch(), CopyFileBackend\delFileBatch(), MigrateBlocks\doDBUpdates(), AddChangeTag\execute(), AddSite\execute(), BenchmarkParse\execute(), BlockUsers\execute(), ChangePassword\execute(), CleanupSpam\execute(), TitleCleanup\execute(), CleanupUploadStash\execute(), CompareLanguageConverterOutput\execute(), ConvertExtensionsMessagesToTranslationAlias\execute(), ConvertExtensionToRegistration\execute(), CopyFileBackend\execute(), CopyJobQueue\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteBatch\execute(), DeleteDefaultMessages\execute(), DeleteEqualMessages\execute(), DeleteSelfExternals\execute(), DeleteTag\execute(), DeleteUserEmail\execute(), DumpBackup\execute(), DumpIterator\execute(), EditCLI\execute(), EraseArchivedFile\execute(), ExportSites\execute(), FindBadBlobs\execute(), FindMissingActors\execute(), FindOrphanedFiles\execute(), FixDoubleRedirects\execute(), FixMergeHistoryCorruption\execute(), FixTimestamps\execute(), FormatInstallDoc\execute(), GenerateJsonI18n\execute(), GenerateSitemap\execute(), GetConfiguration\execute(), GetReplicaServer\execute(), GetTextMaint\execute(), BackupReader\execute(), ImportImages\execute(), ImportTextFiles\execute(), InvalidateUserSessions\execute(), JSParseHelper\execute(), MakeTestEdits\execute(), ManageForeignResources\execute(), ManageJobs\execute(), Mcc\execute(), McTest\execute(), GeneratePhpCharToUpperMappings\execute(), MergeMessageFileList\execute(), MigrateFileRepoLayout\execute(), MigrateUserGroup\execute(), MoveBatch\execute(), MWDocGen\execute(), MysqlMaintenance\execute(), Protect\execute(), PruneFileCache\execute(), PurgeParserCache\execute(), RebuildFileCache\execute(), RebuildLocalisationCache\execute(), RebuildRecentchanges\execute(), RebuildTextIndex\execute(), RecountCategories\execute(), RefreshImageMetadata\execute(), RefreshLinks\execute(), RemoveUnusedAccounts\execute(), RenameDbPrefix\execute(), RenameUser\execute(), RenameUsersMatchingPattern\execute(), DumpRenderer\execute(), ResetAuthenticationThrottle\execute(), ResetUserEmail\execute(), RollbackEdits\execute(), RunJobs\execute(), MwSql\execute(), Undelete\execute(), UpdateMediaWiki\execute(), UpdateExtensionJsonSchema\execute(), UpdateRestrictions\execute(), UpdateSpecialPages\execute(), UppercaseTitlesForUnicodeTransition\execute(), ValidateRegistrationFile\execute(), ViewCLI\execute(), WrapOldPasswords\execute(), CopyFileBackend\getListingDiffRel(), ConvertExtensionToRegistration\handleExtensionFunctions(), ConvertExtensionToRegistration\handleHooks(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), TableCleanup\runTable(), MwSql\sqlDoQuery(), and GenerateJsonI18n\transformI18nFile().

◆ finalSetup()

MediaWiki\Maintenance\Maintenance::finalSetup ( SettingsBuilder $settingsBuilder)

◆ getArg()

MediaWiki\Maintenance\Maintenance::getArg ( $argId = 0,
$default = null )
protected

◆ getArgName()

MediaWiki\Maintenance\Maintenance::getArgName ( int $argId)
protected

Get the name of an argument.

Since
1.43
Parameters
int$argIdThe index (from zero) of the argument.
Returns
string|null The name of the argument, or null if the argument does not exist.

Definition at line 389 of file Maintenance.php.

◆ getArgs()

MediaWiki\Maintenance\Maintenance::getArgs ( $offset = 0)
protected

Get arguments.

Since
1.40
Parameters
int | string$offsetThe index (from zero) of the first argument, or the name declared for the argument by addArg().
Returns
string[]

Definition at line 377 of file Maintenance.php.

Referenced by ConvertExtensionsMessagesToTranslationAlias\execute(), DeleteOldRevisions\execute(), JSParseHelper\execute(), and PatchSql\execute().

◆ getBatchSize()

MediaWiki\Maintenance\Maintenance::getBatchSize ( )
protected

Returns batch size.

Since
1.31
Returns
int|null

Definition at line 426 of file Maintenance.php.

Referenced by CleanupInvalidDbKeys\cleanupTable(), CopyJobQueue\copyJobs(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), FixInconsistentRedirects\doDBUpdates(), MigrateExternallinks\doDBUpdates(), MigrateLinksTable\doDBUpdates(), MigrateRevisionActorTemp\doDBUpdates(), MigrateRevisionCommentTemp\doDBUpdates(), PopulateChangeTagDef\doDBUpdates(), PopulateUserIsTemp\doDBUpdates(), RecountCategories\doWork(), CheckImages\execute(), CheckSignatures\execute(), CheckUsernames\execute(), CleanupRemovedModules\execute(), CleanupUploadStash\execute(), CopyFileBackend\execute(), DeleteAutoPatrolLogs\execute(), DeleteSelfExternals\execute(), DeleteTag\execute(), EmptyUserGroup\execute(), FindMissingFiles\execute(), FindOrphanedFiles\execute(), FixUserRegistration\execute(), InitUserPreference\execute(), InvalidateUserSessions\execute(), MakeTestEdits\execute(), MigrateFileRepoLayout\execute(), MigrateUserGroup\execute(), PruneUnusedLinkTargetRows\execute(), PurgeChangedPages\execute(), PurgeExpiredWatchlistItems\execute(), PurgeModuleDeps\execute(), RebuildFileCache\execute(), RefreshFileHeaders\execute(), RefreshImageMetadata\execute(), RefreshLinks\execute(), RemoveInvalidEmails\execute(), RenameUsersMatchingPattern\execute(), ResetPageRandom\execute(), MwSql\execute(), UpdateCollation\execute(), UpdateRestrictions\execute(), WrapOldPasswords\execute(), DumpCategoriesAsRdf\getCategoryIterator(), DumpCategoriesAsRdf\getCategoryLinksIterator(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), PurgeChangedFiles\purgeFromLogType(), and TableCleanup\runTable().

◆ getConfig()

◆ getDB()

MediaWiki\Maintenance\Maintenance::getDB ( $db,
$groups = [],
$dbDomain = false )
protected

Returns a database to be used by current maintenance script.

This uses the main LBFactory instance by default unless overriden via setDB().

This function has the same parameters as LoadBalancer::getConnection().

For simple cases, use ::getReplicaDB() or ::getPrimaryDB() instead.

Stability: stable
to override
Parameters
int$dbDB index (DB_REPLICA/DB_PRIMARY)
string | string[]$groupsdefault: empty array
string | bool$dbDomaindefault: current wiki
Returns
IMaintainableDatabase

Definition at line 1132 of file Maintenance.php.

Referenced by CleanupInvalidDbKeys\cleanupTable(), MigrateBlocks\doDBUpdates(), MigrateExternallinks\doDBUpdates(), MigrateLinksTable\doDBUpdates(), MigrateRevisionActorTemp\doDBUpdates(), MigrateRevisionCommentTemp\doDBUpdates(), PopulateChangeTagDef\doDBUpdates(), RecountCategories\doWork(), CategoryChangesAsRdf\execute(), CleanupSpam\execute(), DumpCategoriesAsRdf\execute(), PatchSql\execute(), RefreshLinks\execute(), UpdateArticleCount\execute(), UpdateRestrictions\execute(), RefreshLinks\fixRedirect(), MediaWiki\Maintenance\BackupDumper\initProgress(), and PopulateUserIsTemp\initServices().

◆ getDbType()

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

Note
Subclasses that override this method to return self::DB_NONE should also override canExecuteWithoutLocalSettings() to return true, unless they need the wiki to be set up for reasons beyond access to a database connection.
See also
canExecuteWithoutLocalSettings()
Stability: stable
to override
Returns
int

Reimplemented in SearchDump, GenerateAutoload, GenerateConfigSchema, CommandLineInstaller, InstallPreConfigured, MergeMessageFileList, MWDocGen, PatchSql, RebuildAll, RebuildLocalisationCache, RebuildTextIndex, RenameDbPrefix, RunBatchedQuery, MwSql, UpdateMediaWiki, and UpdateSearchIndex.

Definition at line 637 of file Maintenance.php.

Referenced by DumpIterator\finalSetup().

◆ getDir()

MediaWiki\Maintenance\Maintenance::getDir ( )
protected

Get the maintenance directory.

Returns
string

Definition at line 1112 of file Maintenance.php.

◆ getHookContainer()

MediaWiki\Maintenance\Maintenance::getHookContainer ( )
protected

Get a HookContainer, for running extension hooks or for hook metadata.

Since
1.35
Returns
HookContainer

Definition at line 1566 of file Maintenance.php.

Referenced by BenchmarkParse\execute().

◆ getHookRunner()

MediaWiki\Maintenance\Maintenance::getHookRunner ( )
protected

Get a HookRunner for running core hooks.

Access: internal
This is for use by core only. Hook interfaces may be removed without notice.
Since
1.35
Returns
HookRunner

Definition at line 1581 of file Maintenance.php.

Referenced by CleanupPreferences\execute(), and UpdateMediaWiki\validateParamsAndArgs().

◆ getName()

MediaWiki\Maintenance\Maintenance::getName ( )

Get the script's name.

Returns
string

Definition at line 455 of file Maintenance.php.

◆ getOption()

MediaWiki\Maintenance\Maintenance::getOption ( $name,
$default = null )
protected

Get an option, or return the default.

If the option was added to support multiple occurrences, this will return an array.

Parameters
string$nameThe name of the param
mixed | null$defaultAnything you want, default null
Returns
mixed

Definition at line 307 of file Maintenance.php.

Referenced by MediaWiki\Maintenance\Benchmarker\bench(), CompareParsers\checkOptions(), MigrateLinksTable\doDBUpdates(), MigrateRevisionActorTemp\doDBUpdates(), MigrateRevisionCommentTemp\doDBUpdates(), PopulateChangeTagDef\doDBUpdates(), FileOpPerfTest\doPerfTest(), UpdateSpecialPages\doSpecialPageCacheUpdates(), AddChangeTag\execute(), AddSite\execute(), BenchmarkParse\execute(), BlockUsers\execute(), CategoryChangesAsRdf\execute(), CheckDependencies\execute(), CleanupCaps\execute(), CleanupInvalidDbKeys\execute(), TitleCleanup\execute(), CompareParserCache\execute(), ConvertExtensionToRegistration\execute(), CopyFileBackend\execute(), CopyJobQueue\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteAutoPatrolLogs\execute(), DeleteBatch\execute(), DeleteEqualMessages\execute(), DumpCategoriesAsRdf\execute(), DumpIterator\execute(), DumpUploads\execute(), EditCLI\execute(), EraseArchivedFile\execute(), FileOpPerfTest\execute(), FindBadBlobs\execute(), FindMissingActors\execute(), FindMissingFiles\execute(), FindOrphanedFiles\execute(), FixDoubleRedirects\execute(), FixMergeHistoryCorruption\execute(), FormatInstallDoc\execute(), GenerateJsonI18n\execute(), GenerateSitemap\execute(), GetConfiguration\execute(), GetReplicaServer\execute(), GetTextMaint\execute(), GrepPages\execute(), BackupReader\execute(), ImportImages\execute(), ImportSiteScripts\execute(), ImportTextFiles\execute(), InitUserPreference\execute(), InstallPreConfigured\execute(), InvalidateUserSessions\execute(), MakeTestEdits\execute(), ManageForeignResources\execute(), ManageJobs\execute(), Mcc\execute(), McTest\execute(), MergeMessageFileList\execute(), MigrateFileRepoLayout\execute(), MoveBatch\execute(), MysqlMaintenance\execute(), NamespaceDupes\execute(), NukeNS\execute(), PopulateInterwiki\execute(), Protect\execute(), PruneFileCache\execute(), PruneUnusedLinkTargetRows\execute(), PurgeChangedFiles\execute(), PurgeChangedPages\execute(), PurgeList\execute(), PurgeParserCache\execute(), RebuildFileCache\execute(), RebuildLocalisationCache\execute(), RecountCategories\execute(), RefreshFileHeaders\execute(), RefreshImageMetadata\execute(), RefreshLinks\execute(), RemoveUnusedAccounts\execute(), RenameDbPrefix\execute(), RenameUser\execute(), RenameUsersMatchingPattern\execute(), DumpRenderer\execute(), ResetAuthenticationThrottle\execute(), ResetPageRandom\execute(), RollbackEdits\execute(), RunBatchedQuery\execute(), RunJobs\execute(), ShowJobs\execute(), MwSql\execute(), SqliteMaintenance\execute(), TableCleanup\execute(), Undelete\execute(), UpdateMediaWiki\execute(), UpdateCollation\execute(), UpdateSearchIndex\execute(), UpdateSpecialPages\execute(), UppercaseTitlesForUnicodeTransition\execute(), WrapOldPasswords\execute(), InstallPreConfigured\finalSetup(), CLIParser\getTitle(), MigrateLinksTable\getUpdateKey(), MWDocGen\init(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), MediaWiki\Maintenance\TextPassDumper\processOptions(), CompareParsers\processRevision(), SearchDump\processRevision(), MediaWiki\Maintenance\DeleteLocalPasswords\processUsers(), PurgeChangedFiles\purgeFromLogType(), and GetConfiguration\validateParamsAndArgs().

◆ getParameters()

MediaWiki\Maintenance\Maintenance::getParameters ( )
Since
1.39
Returns
MaintenanceParameters

Definition at line 218 of file Maintenance.php.

◆ getPrimaryDB()

MediaWiki\Maintenance\Maintenance::getPrimaryDB ( )
protected
Returns
IDatabase
Since
1.42

Definition at line 1165 of file Maintenance.php.

Referenced by CleanupInvalidDbKeys\cleanupTable(), NukePage\deleteRevisions(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), PopulateInterwiki\doPopulate(), RecountCategories\doWork(), AttachLatest\execute(), CleanupRemovedModules\execute(), DeleteArchivedFiles\execute(), DeleteArchivedRevisions\execute(), DeleteDefaultMessages\execute(), DeleteEqualMessages\execute(), DeleteOrphanedRevisions\execute(), DeleteSelfExternals\execute(), DeleteTag\execute(), EraseArchivedFile\execute(), FixMergeHistoryCorruption\execute(), FixTimestamps\execute(), FixUserRegistration\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), InitEditCount\execute(), InitSiteStats\execute(), InitUserPreference\execute(), MigrateUserGroup\execute(), NukeNS\execute(), NukePage\execute(), PruneUnusedLinkTargetRows\execute(), PurgeModuleDeps\execute(), RebuildFileCache\execute(), ImageBuilder\execute(), RebuildTextIndex\execute(), RefreshImageMetadata\execute(), RemoveInvalidEmails\execute(), RemoveUnusedAccounts\execute(), RenameDbPrefix\execute(), RenameRestrictions\execute(), ResetPageRandom\execute(), RunBatchedQuery\execute(), UpdateMediaWiki\execute(), UpdateArticleCount\execute(), UpdateSpecialPages\execute(), UppercaseTitlesForUnicodeTransition\execute(), WrapOldPasswords\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserDB(), TitleCleanup\moveIllegalPage(), TitleCleanup\moveInconsistentPage(), RebuildTextIndex\populateSearchIndex(), and EraseArchivedFile\scrubAllVersions().

◆ getReplicaDB()

◆ getServiceContainer()

MediaWiki\Maintenance\Maintenance::getServiceContainer ( )
protected

Returns the main service container.

Since
1.40
Returns
MediaWikiServices

Definition at line 691 of file Maintenance.php.

Referenced by DumpCategoriesAsRdf\addDumpHeader(), CleanupInvalidDbKeys\cleanupTable(), ResetAuthenticationThrottle\clearLoginThrottle(), ResetAuthenticationThrottle\clearSignupThrottle(), PopulateInterwiki\doPopulate(), MediaWiki\Maintenance\BackupDumper\dump(), AddSite\execute(), AttachLatest\execute(), BenchmarkParse\execute(), BlockUsers\execute(), CheckBadRedirects\execute(), CheckImages\execute(), CheckSignatures\execute(), CheckUsernames\execute(), CleanupCaps\execute(), CleanupPreferences\execute(), CleanupRemovedModules\execute(), CleanupSpam\execute(), CleanupUploadStash\execute(), ClearInterwikiCache\execute(), CompareLanguageConverterOutput\execute(), CompareParserCache\execute(), CopyFileBackend\execute(), CopyJobQueue\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteArchivedFiles\execute(), DeleteBatch\execute(), DeleteDefaultMessages\execute(), DeleteEqualMessages\execute(), DeleteSelfExternals\execute(), DeleteTag\execute(), DeleteUserEmail\execute(), DumpIterator\execute(), DumpLinks\execute(), EditCLI\execute(), EmptyUserGroup\execute(), EraseArchivedFile\execute(), ExportSites\execute(), FileOpPerfTest\execute(), FindBadBlobs\execute(), FindMissingActors\execute(), FindMissingFiles\execute(), FindOrphanedFiles\execute(), FixDoubleRedirects\execute(), FixUserRegistration\execute(), FormatInstallDoc\execute(), GetLagTimes\execute(), GetReplicaServer\execute(), GetTextMaint\execute(), BackupReader\execute(), ImportImages\execute(), ImportSites\execute(), ImportSiteScripts\execute(), ImportTextFiles\execute(), InitEditCount\execute(), DatabaseLag\execute(), MakeTestEdits\execute(), ManageJobs\execute(), GeneratePhpCharToUpperMappings\execute(), MigrateUserGroup\execute(), MoveBatch\execute(), MysqlMaintenance\execute(), Protect\execute(), PruneUnusedLinkTargetRows\execute(), PurgeChangedPages\execute(), PurgeExpiredBlocks\execute(), PurgeExpiredUserrights\execute(), PurgeExpiredWatchlistItems\execute(), PurgeMessageBlobStore\execute(), PurgeParserCache\execute(), RebuildFileCache\execute(), ImageBuilder\execute(), RebuildLocalisationCache\execute(), RebuildMessages\execute(), RefreshFileHeaders\execute(), RemoveUnusedAccounts\execute(), DumpRenderer\execute(), ResetUserEmail\execute(), RollbackEdits\execute(), RunBatchedQuery\execute(), RunJobs\execute(), ShowJobs\execute(), MwSql\execute(), SqliteMaintenance\execute(), Undelete\execute(), UpdateMediaWiki\execute(), UpdateSpecialPages\execute(), ViewCLI\execute(), WikiBirthday\execute(), WrapOldPasswords\execute(), PopulateInterwiki\fetchLinks(), DeleteEqualMessages\fetchMessageInfo(), ImportSiteScripts\fetchScriptList(), RebuildFileCache\finalSetup(), RefreshLinks\fixRedirect(), MediaWiki\Maintenance\BackupDumper\getBackupDatabase(), MigrateFileRepoLayout\getRepo(), DumpRenderer\handleRevision(), BackupReader\handleUpload(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), CLIParser\initParser(), PopulateUserIsTemp\initServices(), GenerateSitemap\main(), TitleCleanup\moveIllegalPage(), TitleCleanup\moveInconsistentPage(), RebuildTextIndex\populateSearchIndex(), CleanupImages\processRow(), TitleCleanup\processRow(), CleanupWatchlist\processRow(), CleanupCaps\processRowToLowercase(), CleanupCaps\processRowToUppercase(), PurgeChangedFiles\purgeFromLogType(), FixDoubleRedirects\queueJobs(), CLIParser\render(), EraseArchivedFile\scrubVersion(), and CreateBotPassword\showGrants().

◆ getStdin()

MediaWiki\Maintenance\Maintenance::getStdin ( $len = null)
protected

Return input from stdin.

Parameters
int | null$lenThe number of bytes to read. If null, just return the handle. Maintenance::STDIN_ALL returns the full content
Returns
mixed

Definition at line 465 of file Maintenance.php.

Referenced by BlockUsers\execute(), DeleteBatch\execute(), DumpIterator\execute(), EditCLI\execute(), FetchText\execute(), FindClasses\execute(), MoveBatch\execute(), PurgePage\execute(), and DumpRenderer\execute().

◆ getTermSize()

static MediaWiki\Maintenance\Maintenance::getTermSize ( )
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).

Returns
array

Definition at line 1514 of file Maintenance.php.

References wfIsWindows().

◆ hasArg()

MediaWiki\Maintenance\Maintenance::hasArg ( $argId = 0)
protected

Does a given argument exist?

Parameters
int | string$argIdThe index (from zero) of the argument, or the name declared for the argument by addArg().
Returns
bool

Definition at line 353 of file Maintenance.php.

Referenced by BlockUsers\execute(), DeleteBatch\execute(), FormatInstallDoc\execute(), BackupReader\execute(), MoveBatch\execute(), ReassignEdits\execute(), MwSql\execute(), and UserOptionsMaintenance\execute().

◆ hasOption()

MediaWiki\Maintenance\Maintenance::hasOption ( $name)
protected

Checks to see if a particular option was set.

Parameters
string$nameThe name of the option
Returns
bool

Definition at line 292 of file Maintenance.php.

Referenced by MediaWiki\Maintenance\Benchmarker\bench(), CompareParsers\checkOptions(), CleanupInvalidDbKeys\cleanupTable(), CopyFileBackend\copyFileBatch(), PopulateChangeTagDef\doDBUpdates(), FileOpPerfTest\doPerfTest(), UpdateSpecialPages\doSpecialPageCacheUpdates(), AttachLatest\execute(), BenchmarkParse\execute(), BlockUsers\execute(), CheckDependencies\execute(), CleanupCaps\execute(), CleanupInvalidDbKeys\execute(), CleanupPreferences\execute(), CleanupSpam\execute(), CleanupWatchlist\execute(), ConvertExtensionToRegistration\execute(), CopyFileBackend\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteArchivedFiles\execute(), DeleteArchivedRevisions\execute(), DeleteAutoPatrolLogs\execute(), DeleteBatch\execute(), DeleteDefaultMessages\execute(), DeleteEqualMessages\execute(), DeleteOldRevisions\execute(), DeleteOrphanedRevisions\execute(), DumpBackup\execute(), DumpIterator\execute(), DumpUploads\execute(), EditCLI\execute(), EraseArchivedFile\execute(), FindBadBlobs\execute(), FindOrphanedFiles\execute(), FixDoubleRedirects\execute(), FixMergeHistoryCorruption\execute(), FormatInstallDoc\execute(), GenerateJsonI18n\execute(), GenerateSitemap\execute(), GetLagTimes\execute(), GetReplicaServer\execute(), GetTextMaint\execute(), GrepPages\execute(), BackupReader\execute(), ImportImages\execute(), ImportTextFiles\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), InitEditCount\execute(), InitSiteStats\execute(), InstallPreConfigured\execute(), DatabaseLag\execute(), ManageForeignResources\execute(), Mcc\execute(), MergeMessageFileList\execute(), MoveBatch\execute(), MysqlMaintenance\execute(), NamespaceDupes\execute(), NukeNS\execute(), NukePage\execute(), PopulateInterwiki\execute(), Protect\execute(), PurgeChangedFiles\execute(), PurgeChangedPages\execute(), PurgeList\execute(), PurgeOldText\execute(), PurgeParserCache\execute(), ReassignEdits\execute(), RebuildFileCache\execute(), ImageBuilder\execute(), RebuildLocalisationCache\execute(), RebuildRecentchanges\execute(), RecountCategories\execute(), RefreshFileHeaders\execute(), RefreshImageMetadata\execute(), RefreshLinks\execute(), RemoveInvalidEmails\execute(), RemoveUnusedAccounts\execute(), DumpRenderer\execute(), ResetUserEmail\execute(), RollbackEdits\execute(), RunJobs\execute(), ShowJobs\execute(), MwSql\execute(), SqliteMaintenance\execute(), TableCleanup\execute(), UpdateMediaWiki\execute(), UpdateArticleCount\execute(), UpdateCollation\execute(), UpdateSearchIndex\execute(), UpdateSpecialPages\execute(), UserOptionsMaintenance\execute(), WrapOldPasswords\execute(), CopyFileBackend\filesAreSame(), RebuildLocalisationCache\getDbType(), ConvertExtensionToRegistration\handleResourceModules(), MWDocGen\init(), MediaWiki\Maintenance\DeleteLocalPasswords\initialize(), CLIParser\initParser(), RunJobs\memoryLimit(), DumpBackup\processOptions(), MediaWiki\Maintenance\BackupDumper\processOptions(), MediaWiki\Maintenance\TextPassDumper\processOptions(), PurgeChangedFiles\purgeFromLogType(), EraseArchivedFile\scrubVersion(), MwSql\sqlPrintResult(), GetConfiguration\validateParamsAndArgs(), and PurgeChangedFiles\verbose().

◆ isQuiet()

MediaWiki\Maintenance\Maintenance::isQuiet ( )
Returns
bool

Definition at line 482 of file Maintenance.php.

◆ loadParamsAndArgs()

MediaWiki\Maintenance\Maintenance::loadParamsAndArgs ( $self = null,
$opts = null,
$args = null )

Process command line arguments when running as a child script.

Parameters
string | null$selfThe name of the script, if any
array | null$optsAn array of options, in form of key=>value
array | null$argsAn array of command line arguments

Definition at line 869 of file Maintenance.php.

References $self.

◆ loadSpecialVars()

MediaWiki\Maintenance\Maintenance::loadSpecialVars ( )
protected

Handle the special variables that are global to all scripts.

Stability: stable
to override

Definition at line 908 of file Maintenance.php.

◆ loadWithArgv()

MediaWiki\Maintenance\Maintenance::loadWithArgv ( $argv)

Load params and arguments from a given array of command-line arguments.

Since
1.27
Parameters
array$argvThe argument array, not including the script itself.

Definition at line 845 of file Maintenance.php.

Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\BackupDumper\__construct(), and MediaWiki\Maintenance\TextPassDumper\__construct().

◆ maybeHelp()

MediaWiki\Maintenance\Maintenance::maybeHelp ( $force = false)
protected

Maybe show the help.

If the help is shown, exit.

Parameters
bool$forceWhether to force the help to show, default false

Reimplemented in CommandLineInc.

Definition at line 928 of file Maintenance.php.

Referenced by CreateAndPromote\execute(), GenerateJsonI18n\execute(), PurgeChangedFiles\execute(), PurgeChangedPages\execute(), UserOptionsMaintenance\execute(), and GetConfiguration\validateParamsAndArgs().

◆ memoryLimit()

MediaWiki\Maintenance\Maintenance::memoryLimit ( )

Normally we disable the memory_limit when running admin scripts.

Some scripts may wish to actually set a limit, however, to avoid blowing up unexpectedly.

Stability: stable
to override
Returns
string

Reimplemented in RunJobs.

Definition at line 816 of file Maintenance.php.

◆ newBatchIterator()

MediaWiki\Maintenance\Maintenance::newBatchIterator ( $source)
finalprotected

Wrap an entry iterator into a generator that returns batches of said entries.

The batch size is determined by getBatchSize().

Parameters
iterable | Generator | Closure$sourceAn iterable or a callback to get one
Returns
iterable<array> New iterable yielding entry batches from the given iterable
Since
1.44

Definition at line 1379 of file Maintenance.php.

References $source.

Referenced by ImportSiteScripts\execute(), MakeTestEdits\execute(), and RollbackEdits\execute().

◆ output()

MediaWiki\Maintenance\Maintenance::output ( $out,
$channel = null )
protected

Throw some output to the user.

Scripts can call this with no fears, as we handle all –quiet stuff here

Stability: stable
to override
Parameters
string$outThe text to show to the user
mixed | null$channelUnique identifier for the channel. See function outputChanneled.

Definition at line 493 of file Maintenance.php.

Referenced by DumpBackup\__construct(), MediaWiki\Maintenance\TextPassDumper\__construct(), MediaWiki\Maintenance\Benchmarker\addResult(), FindOrphanedFiles\checkFiles(), ResetAuthenticationThrottle\clearLoginThrottle(), ResetAuthenticationThrottle\clearSignupThrottle(), ResetAuthenticationThrottle\clearTempAccountCreationThrottle(), CompareParsers\conclusions(), CopyFileBackend\copyFileBatch(), RunJobs\debugInternal(), CopyFileBackend\delFileBatch(), MediaWiki\Maintenance\FixAutoblockLogTitles\doDBUpdates(), FixInconsistentRedirects\doDBUpdates(), MigrateBlocks\doDBUpdates(), MigrateExternallinks\doDBUpdates(), MigrateLinksTable\doDBUpdates(), MigrateRevisionActorTemp\doDBUpdates(), MigrateRevisionCommentTemp\doDBUpdates(), FileOpPerfTest\doPerfTest(), PopulateInterwiki\doPopulate(), UpdateSpecialPages\doSpecialPageCacheUpdates(), RecountCategories\doWork(), AddChangeTag\execute(), AddSite\execute(), AttachLatest\execute(), BlockUsers\execute(), ChangePassword\execute(), CheckBadRedirects\execute(), CheckDependencies\execute(), CheckImages\execute(), CheckSignatures\execute(), CheckUsernames\execute(), CleanupCaps\execute(), CleanupPreferences\execute(), CleanupRemovedModules\execute(), CleanupSpam\execute(), CleanupUploadStash\execute(), CleanupWatchlist\execute(), ClearInterwikiCache\execute(), CompareParserCache\execute(), ConvertExtensionsMessagesToTranslationAlias\execute(), ConvertExtensionToRegistration\execute(), CopyFileBackend\execute(), CopyJobQueue\execute(), CreateAndPromote\execute(), CreateBotPassword\execute(), DeleteArchivedFiles\execute(), DeleteArchivedRevisions\execute(), DeleteAutoPatrolLogs\execute(), DeleteBatch\execute(), DeleteDefaultMessages\execute(), DeleteEqualMessages\execute(), DeleteOldRevisions\execute(), DeleteOrphanedRevisions\execute(), DeleteSelfExternals\execute(), DeleteTag\execute(), DeleteUserEmail\execute(), DumpLinks\execute(), EditCLI\execute(), EmptyUserGroup\execute(), EraseArchivedFile\execute(), ExportSites\execute(), FetchText\execute(), FindBadBlobs\execute(), FindClasses\execute(), FindMissingActors\execute(), FindMissingFiles\execute(), FindOrphanedFiles\execute(), FixDoubleRedirects\execute(), FixMergeHistoryCorruption\execute(), FixTimestamps\execute(), FixUserRegistration\execute(), GenerateJsonI18n\execute(), GetConfiguration\execute(), GetLagTimes\execute(), GetReplicaServer\execute(), GetTextMaint\execute(), BackupReader\execute(), ImportImages\execute(), ImportSites\execute(), ImportSiteScripts\execute(), ImportTextFiles\execute(), MediaWiki\Maintenance\DeleteLocalPasswords\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\execute(), InitEditCount\execute(), InitSiteStats\execute(), InitUserPreference\execute(), InstallPreConfigured\execute(), InvalidateBotPasswords\execute(), InvalidateUserSessions\execute(), JSParseHelper\execute(), DatabaseLag\execute(), MakeTestEdits\execute(), ManageForeignResources\execute(), McTest\execute(), GeneratePhpCharToUpperMappings\execute(), MigrateFileRepoLayout\execute(), MigrateUserGroup\execute(), MoveBatch\execute(), MWDocGen\execute(), NamespaceDupes\execute(), NukeNS\execute(), NukePage\execute(), PageExists\execute(), PatchSql\execute(), Protect\execute(), PruneFileCache\execute(), PruneUnusedLinkTargetRows\execute(), PurgeChangedPages\execute(), PurgeExpiredBlocks\execute(), PurgeExpiredUserrights\execute(), PurgeExpiredWatchlistItems\execute(), PurgeList\execute(), PurgeModuleDeps\execute(), PurgeParserCache\execute(), PurgeRecentChanges\execute(), ReassignEdits\execute(), RebuildAll\execute(), RebuildFileCache\execute(), RebuildLocalisationCache\execute(), RebuildMessages\execute(), RebuildRecentchanges\execute(), RebuildTextIndex\execute(), RecountCategories\execute(), RefreshFileHeaders\execute(), RefreshImageMetadata\execute(), RefreshLinks\execute(), RemoveInvalidEmails\execute(), RemoveUnusedAccounts\execute(), RenameDbPrefix\execute(), RenameUser\execute(), RenameUsersMatchingPattern\execute(), ResetPageRandom\execute(), ResetUserEmail\execute(), RollbackEdits\execute(), RunBatchedQuery\execute(), RunJobs\execute(), ShowJobs\execute(), ShowSiteStats\execute(), TableCleanup\execute(), Undelete\execute(), UpdateMediaWiki\execute(), UpdateArticleCount\execute(), UpdateCollation\execute(), UpdateExtensionJsonSchema\execute(), UpdateRestrictions\execute(), UpdateSpecialPages\execute(), ValidateRegistrationFile\execute(), ViewCLI\execute(), WikiBirthday\execute(), WrapOldPasswords\execute(), DeleteEqualMessages\fetchMessageInfo(), ImportSiteScripts\fetchScriptList(), MediaWiki\Maintenance\DeleteLocalPasswords\getUserBatches(), ConvertExtensionToRegistration\handleExtensionMessagesFiles(), ConvertExtensionToRegistration\handleHooks(), DumpIterator\handleRevision(), DumpRenderer\handleRevision(), MWDocGen\init(), GenerateSitemap\main(), TitleCleanup\moveIllegalPage(), TitleCleanup\moveInconsistentPage(), RebuildTextIndex\populateSearchIndex(), CompareParsers\processRevision(), SearchDump\processRevision(), CleanupImages\processRow(), TitleCleanup\processRow(), CleanupWatchlist\processRow(), CleanupCaps\processRowToLowercase(), CleanupCaps\processRowToUppercase(), TableCleanup\progress(), PruneFileCache\prune_directory(), PurgeChangedFiles\purgeFromArchiveTable(), FixDoubleRedirects\queueJobs(), ImportSites\reportException(), MigrateFileRepoLayout\runBatch(), TableCleanup\runTable(), EraseArchivedFile\scrubVersion(), CreateBotPassword\showGrants(), Mcc\showHelp(), PurgeParserCache\showProgressAndWait(), MwSql\sqlPrintResult(), MediaWiki\Maintenance\Benchmarker\startBench(), GenerateJsonI18n\transformI18nFile(), PurgeChangedFiles\verbose(), and MediaWiki\Maintenance\Benchmarker\verboseRun().

◆ outputChanneled()

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.

Parameters
string | false$msgThe message without trailing newline
string | null$channelChannel identifier or null for no channel. Channel comparison uses ===.

Definition at line 597 of file Maintenance.php.

◆ parseIntList()

MediaWiki\Maintenance\Maintenance::parseIntList ( $text)
protected

Utility function to parse a string (perhaps from a command line option) into a list of integers (perhaps some kind of numeric IDs).

Since
1.35
Parameters
string$text
Returns
int[]

Definition at line 1598 of file Maintenance.php.

Referenced by FindMissingActors\execute().

◆ posix_isatty()

static MediaWiki\Maintenance\Maintenance::posix_isatty ( $fd)
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.

Parameters
mixed$fdFile descriptor
Returns
bool

Definition at line 1434 of file Maintenance.php.

◆ prompt()

MediaWiki\Maintenance\Maintenance::prompt ( string $prompt,
?string $default = null )
protected
Parameters
string$promptThe prompt to display to the user
string | null$defaultThe default value to return if the user just presses enter
Returns
string|null
Since
1.43

Definition at line 1643 of file Maintenance.php.

◆ purgeRedundantText()

MediaWiki\Maintenance\Maintenance::purgeRedundantText ( $delete = true)

Support function for cleaning up redundant text records.

Parameters
bool$deleteWhether or not to actually delete the records
Author
Rob Church robch.nosp@m.ur@g.nosp@m.mail..nosp@m.com

Definition at line 1049 of file Maintenance.php.

Referenced by DeleteArchivedRevisions\execute(), DeleteOrphanedRevisions\execute(), NukeNS\execute(), NukePage\execute(), and PurgeOldText\execute().

◆ readconsole()

static MediaWiki\Maintenance\Maintenance::readconsole ( $prompt = ',
'  )
static

Prompt the console for input.

Parameters
string$promptWhat to begin the line with, like '> '
Returns
string|false Response

Definition at line 1447 of file Maintenance.php.

Referenced by FindMissingActors\execute(), and Mcc\execute().

◆ requireExtension()

MediaWiki\Maintenance\Maintenance::requireExtension ( $name)
protected

Indicate that the specified extension must be loaded before the script can run.

This must be called in the constructor.

Since
1.28
Parameters
string$name

Definition at line 712 of file Maintenance.php.

◆ requireTestsAutoloader()

static MediaWiki\Maintenance\Maintenance::requireTestsAutoloader ( )
static

Call this to set up the autoloader to allow classes to be used from the tests directory.

Deprecated
since 1.41. Set the MW_AUTOLOAD_TEST_CLASSES in file scope instead.

Definition at line 1556 of file Maintenance.php.

◆ rollbackTransaction()

MediaWiki\Maintenance\Maintenance::rollbackTransaction ( IDatabase $dbw,
$fname )
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.

Parameters
IDatabase$dbw
string$fnameCaller name
Since
1.27
Deprecated
Since 1.44 Use rollbackTransactionRound() instead

Definition at line 1245 of file Maintenance.php.

References Wikimedia\Rdbms\IDatabase\rollback().

◆ rollbackTransactionRound()

MediaWiki\Maintenance\Maintenance::rollbackTransactionRound ( $fname)
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().

See also
ILBfactory::rollbackPrimaryChanges()
Parameters
string$fnameCaller name
Returns
void
Since
1.44

Definition at line 1364 of file Maintenance.php.

◆ runChild()

MediaWiki\Maintenance\Maintenance::runChild ( $maintClass,
$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

Deprecated
Since 1.43. Use Maintenance::createChild instead. This method is an alias to that method.
Parameters
string$maintClassA name of a child maintenance class
string | null$classFileFull path of where the child is
Returns
Maintenance The created instance, which the caller is expected to run by calling Maintenance::execute on the returned object.

Definition at line 754 of file Maintenance.php.

References $maintClass.

Referenced by NukeNS\execute(), RebuildAll\execute(), RecountCategories\execute(), and UpdateMediaWiki\execute().

◆ setAllowUnregisteredOptions()

MediaWiki\Maintenance\Maintenance::setAllowUnregisteredOptions ( $allow)
protected

Sets whether to allow unregistered options, which are options passed to a script that do not match an expected parameter.

Parameters
bool$allowShould we allow?

Definition at line 335 of file Maintenance.php.

Referenced by CommandLineInc\__construct().

◆ setArg()

MediaWiki\Maintenance\Maintenance::setArg ( $argId,
$value )

Programmatically set the value of the given argument.

Useful for setting up child scripts, see runChild().

Since
1.39
Parameters
string | int$argIdArg index or name
mixed | null$value

Definition at line 415 of file Maintenance.php.

◆ setBatchSize()

MediaWiki\Maintenance\Maintenance::setBatchSize ( $s = 0)
protected
Parameters
int$sThe number of operations to do in a batch

Definition at line 433 of file Maintenance.php.

Referenced by CategoryChangesAsRdf\__construct(), CheckImages\__construct(), CheckSignatures\__construct(), CheckUsernames\__construct(), CleanupInvalidDbKeys\__construct(), CleanupPageLang\__construct(), CleanupPreferences\__construct(), CleanupRemovedModules\__construct(), TitleCleanup\__construct(), CleanupUploadStash\__construct(), CopyFileBackend\__construct(), CopyJobQueue\__construct(), DeleteAutoPatrolLogs\__construct(), DeleteSelfExternals\__construct(), DeleteTag\__construct(), DumpCategoriesAsRdf\__construct(), EmptyUserGroup\__construct(), FindBadBlobs\__construct(), FindMissingActors\__construct(), FindMissingFiles\__construct(), FindOrphanedFiles\__construct(), MediaWiki\Maintenance\FixAutoblockLogTitles\__construct(), FixInconsistentRedirects\__construct(), FixUserRegistration\__construct(), ImportSiteScripts\__construct(), MediaWiki\Maintenance\DeleteLocalPasswords\__construct(), MediaWiki\Maintenance\LoggedUpdateMaintenance\__construct(), InitUserPreference\__construct(), InvalidateUserSessions\__construct(), MakeTestEdits\__construct(), ManageJobs\__construct(), MigrateBlocks\__construct(), MigrateExternallinks\__construct(), MigrateFileRepoLayout\__construct(), MigrateLinksTable\__construct(), MigrateUserGroup\__construct(), PopulateChangeTagDef\__construct(), PopulateUserIsTemp\__construct(), PrewarmParsoidParserCache\__construct(), PruneUnusedLinkTargetRows\__construct(), PurgeChangedFiles\__construct(), PurgeChangedPages\__construct(), PurgeExpiredWatchlistItems\__construct(), PurgeList\__construct(), PurgeModuleDeps\__construct(), RebuildFileCache\__construct(), RebuildRecentchanges\__construct(), RecountCategories\__construct(), RefreshFileHeaders\__construct(), RefreshImageMetadata\__construct(), RefreshLinks\__construct(), RemoveInvalidEmails\__construct(), RenameUsersMatchingPattern\__construct(), ResetPageRandom\__construct(), RollbackEdits\__construct(), MwSql\__construct(), TableCleanup\__construct(), UpdateCollation\__construct(), UpdateRestrictions\__construct(), UppercaseTitlesForUnicodeTransition\__construct(), UserOptionsMaintenance\__construct(), WrapOldPasswords\__construct(), PopulateChangeTagDef\doDBUpdates(), CopyFileBackend\execute(), and DeleteAutoPatrolLogs\execute().

◆ setConfig()

MediaWiki\Maintenance\Maintenance::setConfig ( Config $config)
Since
1.24
Parameters
Config$config

Definition at line 699 of file Maintenance.php.

◆ setDB()

MediaWiki\Maintenance\Maintenance::setDB ( IMaintainableDatabase $db)

Sets database object to be returned by getDB().

Stability: stable
to override
Parameters
IMaintainableDatabase$db

Reimplemented in MediaWiki\Maintenance\BackupDumper.

Definition at line 1149 of file Maintenance.php.

Referenced by MediaWiki\Installer\DatabaseUpdater\__construct().

◆ setLBFactory()

MediaWiki\Maintenance\Maintenance::setLBFactory ( ILBFactory $lbFactory)
Access: internal
Parameters
ILBFactory$lbFactoryLBFactory to inject in place of the service instance
Returns
void

Definition at line 1174 of file Maintenance.php.

◆ setName()

MediaWiki\Maintenance\Maintenance::setName ( string $name)
Since
1.40
Access: internal
Parameters
string$name

Definition at line 833 of file Maintenance.php.

◆ setOption()

MediaWiki\Maintenance\Maintenance::setOption ( string $name,
$value )

Programmatically set the value of the given option.

Useful for setting up child scripts, see runChild().

Since
1.39
Parameters
string$name
mixed | null$value

Definition at line 402 of file Maintenance.php.

Referenced by PurgeChangedFiles\execute(), MediaWiki\Maintenance\LoggedUpdateMaintenance\setForce(), and RebuildLocalisationCache\setForce().

◆ setup()

MediaWiki\Maintenance\Maintenance::setup ( )

Provides subclasses with an opportunity to perform initial checks.

Stability: stable
to override

Reimplemented in UpdateMediaWiki.

Definition at line 805 of file Maintenance.php.

◆ showHelp()

MediaWiki\Maintenance\Maintenance::showHelp ( )
protected

Definitely show the help.

Does not exit.

Reimplemented in Mcc.

Definition at line 945 of file Maintenance.php.

◆ supportsOption()

MediaWiki\Maintenance\Maintenance::supportsOption ( $name)
protected

Checks to see if a particular option in supported.

Normally this means it has been registered by the script via addOption.

Parameters
string$nameThe name of the option
Returns
bool true if the option exists, false otherwise

Definition at line 258 of file Maintenance.php.

◆ validateParamsAndArgs()

MediaWiki\Maintenance\Maintenance::validateParamsAndArgs ( )

Run some validation checks on the params, etc.

Stability: stable
to override

Reimplemented in GetConfiguration, CommandLineInstaller, and UpdateMediaWiki.

Definition at line 898 of file Maintenance.php.

◆ validateUserOption()

MediaWiki\Maintenance\Maintenance::validateUserOption ( $errorMsg)
protected
Parameters
string$errorMsgError message to be displayed if neither –user or –userid are passed.
Since
1.37
Returns
User

Definition at line 1616 of file Maintenance.php.

Referenced by ChangePassword\execute(), and InvalidateBotPasswords\execute().

◆ waitForReplication()

Member Data Documentation

◆ $fileHandle

resource null MediaWiki\Maintenance\Maintenance::$fileHandle

Used when creating separate schema files.

Definition at line 160 of file Maintenance.php.

◆ $mArgs

array MediaWiki\Maintenance\Maintenance::$mArgs = []
protected

This is the list of arguments that were actually passed.

Deprecated
since 1.39, use {
See also
addArg} instead.

Definition at line 117 of file Maintenance.php.

◆ $mBatchSize

int null MediaWiki\Maintenance\Maintenance::$mBatchSize = null
protected

Batch size.

If a script supports this, they should set a default with setBatchSize()

Definition at line 145 of file Maintenance.php.

◆ $mDbPass

string MediaWiki\Maintenance\Maintenance::$mDbPass = null
protected

Definition at line 125 of file Maintenance.php.

◆ $mDbUser

string MediaWiki\Maintenance\Maintenance::$mDbUser = null
protected

Definition at line 124 of file Maintenance.php.

◆ $mDescription

string MediaWiki\Maintenance\Maintenance::$mDescription = ''
protected

A description of the script, children should change this via addDescription()

Deprecated
since 1.39, use {
See also
addDescription} instead.

Definition at line 131 of file Maintenance.php.

◆ $mInputLoaded

bool MediaWiki\Maintenance\Maintenance::$mInputLoaded = false
protected

Have we already loaded our user input?

Deprecated
since 1.39, treat as private to the Maintenance base class

Definition at line 137 of file Maintenance.php.

◆ $mOptions

array MediaWiki\Maintenance\Maintenance::$mOptions = []
protected

This is the list of options that were actually passed.

Deprecated
since 1.39, use {
See also
addOption} instead.

Definition at line 111 of file Maintenance.php.

◆ $mParams

array [] MediaWiki\Maintenance\Maintenance::$mParams = []
protected

Empty.

Deprecated
since 1.39, use $this->parameters instead.

Definition at line 105 of file Maintenance.php.

◆ $mQuiet

bool MediaWiki\Maintenance\Maintenance::$mQuiet = false
protected

Special vars for params that are always used.

Definition at line 123 of file Maintenance.php.

◆ $mSelf

string null MediaWiki\Maintenance\Maintenance::$mSelf
protected

Name of the script currently running.

Definition at line 120 of file Maintenance.php.

◆ $orderedOptions

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.

Deprecated
since 1.39, use $this->getParameters()->getOptionsSequence() instead.

Definition at line 193 of file Maintenance.php.

Referenced by MediaWiki\Maintenance\BackupDumper\processOptions().

◆ $parameters

MaintenanceParameters MediaWiki\Maintenance\Maintenance::$parameters
protected

Definition at line 97 of file Maintenance.php.

◆ DB_ADMIN

const MediaWiki\Maintenance\Maintenance::DB_ADMIN = 2

Definition at line 85 of file Maintenance.php.

◆ DB_NONE

const MediaWiki\Maintenance\Maintenance::DB_NONE = 0

Constants for DB access type.

See also
Maintenance::getDbType()

Definition at line 83 of file Maintenance.php.

◆ DB_STD

const MediaWiki\Maintenance\Maintenance::DB_STD = 1

Definition at line 84 of file Maintenance.php.

◆ GENERIC_MAINTENANCE_PARAMETERS

const MediaWiki\Maintenance\Maintenance::GENERIC_MAINTENANCE_PARAMETERS = 'Script runner options'

◆ SCRIPT_DEPENDENT_PARAMETERS

const MediaWiki\Maintenance\Maintenance::SCRIPT_DEPENDENT_PARAMETERS = 'Common options'

Definition at line 91 of file Maintenance.php.

◆ STDIN_ALL

const MediaWiki\Maintenance\Maintenance::STDIN_ALL = -1

Definition at line 88 of file Maintenance.php.


The documentation for this class was generated from the following file: