24 require_once __DIR__ .
'/../../maintenance/Maintenance.php';
117 $this->maintenance->
setDB( $db );
120 Hooks::run(
'LoadExtensionSchemaUpdates', [ $this ] );
128 global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
129 $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
131 # For extensions only, should be populated via hooks
132 # $wgDBtype should be checked to specifiy the proper file
133 $wgExtNewTables = [];
134 $wgExtNewFields = [];
135 $wgExtPGNewFields = [];
136 $wgExtPGAlteredFields = [];
137 $wgExtNewIndexes = [];
138 $wgExtModifiedFields = [];
146 if ( !defined(
'MEDIAWIKI_INSTALL' ) ) {
152 $queue = $registry->getQueue();
154 $registry->clearQueue();
157 $data = $registry->readFromQueue(
$queue );
158 $hooks = [
'wgHooks' => [
'LoadExtensionSchemaUpdates' => [] ] ];
159 if ( isset( $data[
'globals'][
'wgHooks'][
'LoadExtensionSchemaUpdates'] ) ) {
160 $hooks = $data[
'globals'][
'wgHooks'][
'LoadExtensionSchemaUpdates'];
162 if (
$vars && isset(
$vars[
'wgHooks'][
'LoadExtensionSchemaUpdates'] ) ) {
163 $hooks = array_merge_recursive( $hooks,
$vars[
'wgHooks'][
'LoadExtensionSchemaUpdates'] );
166 $wgHooks[
'LoadExtensionSchemaUpdates'] = $hooks;
167 if (
$vars && isset(
$vars[
'wgAutoloadClasses'] ) ) {
168 $wgAutoloadClasses +=
$vars[
'wgAutoloadClasses'];
183 $class = ucfirst(
$type ) .
'Updater';
187 throw new MWException( __METHOD__ .
' called for unsupported $wgDBtype' );
206 if ( $this->maintenance->isQuiet() ) {
210 if ( !$wgCommandLineMode ) {
211 $str = htmlspecialchars( $str );
231 $this->extensionUpdates[] = $update;
244 $this->extensionUpdates[] = [
'addTable', $tableName, $sqlPath,
true ];
255 $this->extensionUpdates[] = [
'addIndex', $tableName, $indexName, $sqlPath,
true ];
267 $this->extensionUpdates[] = [
'addField', $tableName, $columnName, $sqlPath,
true ];
279 $this->extensionUpdates[] = [
'dropField', $tableName, $columnName, $sqlPath,
true ];
292 $this->extensionUpdates[] = [
'dropIndex', $tableName, $indexName, $sqlPath,
true ];
303 $this->extensionUpdates[] = [
'dropTable', $tableName, $sqlPath,
true ];
319 $sqlPath, $skipBothIndexExistWarning =
false
321 $this->extensionUpdates[] = [
326 $skipBothIndexExistWarning,
340 $this->extensionUpdates[] = [
'modifyField', $tableName, $fieldName, $sqlPath,
true ];
351 return ( $this->db->tableExists( $tableName, __METHOD__ ) );
364 $this->postDatabaseUpdateMaintenance[] = $class;
393 $this->updatesSkipped = [];
396 $func = $funcList[0];
398 $origParams = $funcList[2];
399 call_user_func_array( $func, $arg );
401 $this->updatesSkipped[] = $origParams;
410 public function doUpdates( $what = [
'core',
'extensions',
'stats' ] ) {
413 $what = array_flip( $what );
414 $this->skipSchema = isset( $what[
'noschema'] ) || $this->fileHandle !== null;
415 if ( isset( $what[
'core'] ) ) {
418 if ( isset( $what[
'extensions'] ) ) {
423 if ( isset( $what[
'stats'] ) ) {
429 if ( $this->fileHandle ) {
430 $this->skipSchema =
false;
447 $func = array_shift( $params );
448 if ( !is_array( $func ) && method_exists( $this, $func ) ) {
449 $func = [ $this, $func ];
450 } elseif ( $passSelf ) {
451 array_unshift( $params, $this );
453 $ret = call_user_func_array( $func, $params );
455 if (
$ret !==
false ) {
456 $updatesDone[] = $origParams;
462 $this->updatesSkipped = array_merge( $this->updatesSkipped,
$updatesSkipped );
475 $key =
"updatelist-$version-" . time() . self::$updateCounter;
476 self::$updateCounter++;
477 $this->db->insert(
'updatelog',
491 $row = $this->db->selectRow(
495 [
'ul_key' => $key ],
511 $values = [
'ul_key' => $key ];
513 $values[
'ul_value'] = $val;
515 $this->db->insert(
'updatelog', $values, __METHOD__,
'IGNORE' );
528 return $this->db->tableExists(
'updatelog', __METHOD__ ) &&
529 $this->db->fieldExists(
'updatelog',
'ul_value', __METHOD__ );
545 if ( $wgSharedDB === null || $this->shared ) {
549 if ( in_array(
$name, $wgSharedTables ) ) {
550 $this->
output(
"...skipping update to shared table $name.\n" );
566 global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
571 foreach ( $wgExtNewTables
as $tableRecord ) {
573 'addTable', $tableRecord[0], $tableRecord[1],
true
577 foreach ( $wgExtNewFields
as $fieldRecord ) {
579 'addField', $fieldRecord[0], $fieldRecord[1],
580 $fieldRecord[2],
true
584 foreach ( $wgExtNewIndexes
as $fieldRecord ) {
586 'addIndex', $fieldRecord[0], $fieldRecord[1],
587 $fieldRecord[2],
true
591 foreach ( $wgExtModifiedFields
as $fieldRecord ) {
593 'modifyField', $fieldRecord[0], $fieldRecord[1],
594 $fieldRecord[2],
true
617 $this->db->sourceFile( $filename,
false,
false,
false,
618 [ $this,
'appendLine' ]
634 if ( fwrite( $this->fileHandle,
$line ) ===
false ) {
650 if ( $msg === null ) {
651 $msg =
"Applying $path patch";
653 if ( $this->skipSchema ) {
654 $this->
output(
"...skipping schema change ($msg).\n" );
659 $this->
output(
"$msg ..." );
661 if ( !$isFullPath ) {
664 if ( $this->fileHandle !== null ) {
667 $this->db->sourceFile(
$path );
669 $this->
output(
"done.\n" );
687 if ( $this->db->tableExists(
$name, __METHOD__ ) ) {
688 $this->
output(
"...$name table already exists.\n" );
690 return $this->
applyPatch( $patch, $fullpath,
"Creating $name table" );
705 protected function addField( $table, $field, $patch, $fullpath =
false ) {
706 if ( !$this->
doTable( $table ) ) {
710 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
711 $this->
output(
"...$table table does not exist, skipping new field patch.\n" );
712 } elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
713 $this->
output(
"...have $field field in $table table.\n" );
715 return $this->
applyPatch( $patch, $fullpath,
"Adding $field field to table $table" );
730 protected function addIndex( $table, $index, $patch, $fullpath =
false ) {
731 if ( !$this->
doTable( $table ) ) {
735 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
736 $this->
output(
"...skipping: '$table' table doesn't exist yet.\n" );
737 } elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
738 $this->
output(
"...index $index already set on $table table.\n" );
740 return $this->
applyPatch( $patch, $fullpath,
"Adding index $index to table $table" );
755 protected function dropField( $table, $field, $patch, $fullpath =
false ) {
756 if ( !$this->
doTable( $table ) ) {
760 if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
761 return $this->
applyPatch( $patch, $fullpath,
"Table $table contains $field field. Dropping" );
763 $this->
output(
"...$table table does not contain $field field.\n" );
778 protected function dropIndex( $table, $index, $patch, $fullpath =
false ) {
779 if ( !$this->
doTable( $table ) ) {
783 if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
784 return $this->
applyPatch( $patch, $fullpath,
"Dropping $index index from table $table" );
786 $this->
output(
"...$index key doesn't exist.\n" );
805 $skipBothIndexExistWarning, $patch, $fullpath =
false
807 if ( !$this->
doTable( $table ) ) {
812 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
813 $this->
output(
"...skipping: '$table' table doesn't exist yet.\n" );
819 if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
820 $this->
output(
"...index $newIndex already set on $table table.\n" );
821 if ( !$skipBothIndexExistWarning &&
822 $this->db->indexExists( $table, $oldIndex, __METHOD__ )
824 $this->
output(
"...WARNING: $oldIndex still exists, despite it has " .
825 "been renamed into $newIndex (which also exists).\n" .
826 " $oldIndex should be manually removed if not needed anymore.\n" );
833 if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
834 $this->
output(
"...skipping: index $oldIndex doesn't exist.\n" );
843 "Renaming index $oldIndex into $newIndex to table $table"
858 public function dropTable( $table, $patch =
false, $fullpath =
false ) {
859 if ( !$this->
doTable( $table ) ) {
863 if ( $this->db->tableExists( $table, __METHOD__ ) ) {
864 $msg =
"Dropping table $table";
866 if ( $patch ===
false ) {
867 $this->
output(
"$msg ..." );
868 $this->db->dropTable( $table, __METHOD__ );
869 $this->
output(
"done.\n" );
871 return $this->
applyPatch( $patch, $fullpath, $msg );
874 $this->
output(
"...$table doesn't exist.\n" );
889 public function modifyField( $table, $field, $patch, $fullpath =
false ) {
890 if ( !$this->
doTable( $table ) ) {
894 $updateKey =
"$table-$field-$patch";
895 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
896 $this->
output(
"...$table table does not exist, skipping modify field patch.\n" );
897 } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
898 $this->
output(
"...$field field does not exist in $table table, " .
899 "skipping modify field patch.\n" );
901 $this->
output(
"...$field in table $table already modified by patch $patch.\n" );
905 return $this->
applyPatch( $patch, $fullpath,
"Modifying $field field of table $table" );
918 $zonePath = $repo->getZonePath(
'temp' );
919 if ( $repo->getBackend()->directoryExists( [
'dir' => $zonePath ] ) ) {
921 $status = $repo->getBackend()->secure( [
927 $this->
output(
"Set the local repo temp zone container to be private.\n" );
929 $this->
output(
"Failed to set the local repo temp zone container to be private.\n" );
939 # We can't guarantee that the user will be able to use TRUNCATE,
940 # but we know that DELETE is available to us
941 $this->
output(
"Purging caches..." );
942 $this->db->delete(
'objectcache',
'*', __METHOD__ );
943 if ( $wgLocalisationCacheConf[
'manualRecache'] ) {
948 $this->db->delete(
'module_deps',
'*', __METHOD__ );
949 $this->
output(
"done.\n" );
956 $this->
output(
"...site_stats is populated..." );
957 $row = $this->db->selectRow(
'site_stats',
'*', [
'ss_row_id' => 1 ], __METHOD__ );
958 if ( $row ===
false ) {
959 $this->
output(
"data is missing! rebuilding...\n" );
960 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
961 $this->
output(
"missing ss_total_pages, rebuilding...\n" );
963 $this->
output(
"done.\n" );
970 # Common updater functions
976 $activeUsers = $this->db->selectField(
'site_stats',
'ss_active_users',
false, __METHOD__ );
977 if ( $activeUsers == -1 ) {
978 $activeUsers = $this->db->selectField(
'recentchanges',
979 'COUNT( DISTINCT rc_user_text )',
980 [
'rc_user != 0',
'rc_bot' => 0,
"rc_log_type != 'newusers'" ], __METHOD__
982 $this->db->update(
'site_stats',
983 [
'ss_active_users' => intval( $activeUsers ) ],
984 [
'ss_row_id' => 1 ], __METHOD__, [
'LIMIT' => 1 ]
987 $this->
output(
"...ss_active_users user count set...\n" );
996 "Populating log_user_text field, printing progress markers. For large\n" .
997 "databases, you may want to hit Ctrl-C and do this manually with\n" .
998 "maintenance/populateLogUsertext.php.\n"
1001 $task = $this->maintenance->runChild(
'PopulateLogUsertext' );
1003 $this->
output(
"done.\n" );
1013 "Populating log_search table, printing progress markers. For large\n" .
1014 "databases, you may want to hit Ctrl-C and do this manually with\n" .
1015 "maintenance/populateLogSearch.php.\n" );
1017 $task = $this->maintenance->runChild(
'PopulateLogSearch' );
1019 $this->
output(
"done.\n" );
1029 $this->
output(
"...transcache tc_time already converted.\n" );
1034 return $this->
applyPatch(
'patch-tc-timestamp.sql',
false,
1035 "Converting tc_time from UNIX epoch to MediaWiki timestamp" );
1043 if ( $this->db->fieldExists(
'categorylinks',
'cl_collation', __METHOD__ ) ) {
1044 if ( $this->db->selectField(
1047 'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
1051 $this->
output(
"...collations up-to-date.\n" );
1056 $this->
output(
"Updating category collations..." );
1057 $task = $this->maintenance->runChild(
'UpdateCollation' );
1059 $this->
output(
"...done.\n" );
1067 if ( $this->db->tableExists(
'user_properties' ) ) {
1068 $cl = $this->maintenance->runChild(
'ConvertUserOptions',
'convertUserOptions.php' );
1070 $this->
output(
"done.\n" );
1080 if ( !$this->
doTable(
'profiling' ) ) {
1084 $profileToDb =
false;
1085 if ( isset( $wgProfiler[
'output'] ) ) {
1086 $out = $wgProfiler[
'output'];
1087 if (
$out ===
'db' ) {
1088 $profileToDb =
true;
1089 } elseif ( is_array(
$out ) && in_array(
'db',
$out ) ) {
1090 $profileToDb =
true;
1094 if ( $profileToDb && !$this->db->tableExists(
'profiling', __METHOD__ ) ) {
1095 $this->
applyPatch(
'patch-profiling.sql',
false,
'Add profiling table' );
1106 $cl = $this->maintenance->runChild(
'RebuildLocalisationCache',
'rebuildLocalisationCache.php' );
1107 $this->
output(
"Rebuilding localisation cache...\n" );
1110 $this->
output(
"done.\n" );
1120 if ( $wgContentHandlerUseDB ) {
1121 $this->
output(
"Turning off Content Handler DB fields for this part of upgrade.\n" );
1123 $wgContentHandlerUseDB =
false;
1133 if ( $this->holdContentHandlerUseDB ) {
1134 $this->
output(
"Content Handler DB fields should be usable now.\n" );
This class generates message blobs for use by ResourceLoader modules.
doUpdates($what=[ 'core', 'extensions', 'stats'])
Do all the updates.
array $extensionUpdates
List of extension-provided database updates.
copyFile($filename)
Append an SQL fragment to the open file handle.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgVersion
MediaWiki version number.
getExtensionUpdates()
Get the list of extension-defined updates.
canUseNewUpdatelog()
Updatelog was changed in 1.17 to have a ul_value column so we can record more information about what ...
dropExtensionField($tableName, $columnName, $sqlPath)
loadExtensions()
Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates ...
applyPatch($path, $isFullPath=false, $msg=null)
Applies a SQL patch.
dropTable($table, $patch=false, $fullpath=false)
If the specified table exists, drop it, or execute the patch if one is provided.
addExtensionTable($tableName, $sqlPath)
Convenience wrapper for addExtensionUpdate() when adding a new table (which is the most common usage ...
Class for handling database updates.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
resource $fileHandle
File handle for SQL output.
rebuildLocalisationCache()
Rebuilds the localisation cache.
$wgHooks['ArticleShow'][]
string[] $postDatabaseUpdateMaintenance
Scripts to run after database update Should be a subclass of LoggedUpdateMaintenance.
output($str)
Output some text.
checkStats()
Check the site_stats table is not properly populated.
when a variable name is used in a it is silently declared as a new local masking the global
doUpdateTranscacheField()
Updates the timestamps in the transcache table.
dropIndex($table, $index, $patch, $fullpath=false)
Drop an index from an existing table.
$wgCategoryCollation
Specify how category names should be sorted, when listed on a category page.
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
addPostDatabaseUpdateMaintenance($class)
Add a maintenance script to be run after the database updates are complete.
static doAllAndCommit($database, array $options=[])
Do all updates and commit them.
__construct(DatabaseBase &$db, $shared, Maintenance $maintenance=null)
Constructor.
bool $skipSchema
Flag specifying whether or not to skip schema (e.g.
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Fake maintenance wrapper, mostly used for the web installer/updater.
getDB()
Get a database connection to run updates.
global $wgCommandLineMode
dropExtensionIndex($tableName, $indexName, $sqlPath)
Drop an index from an extension table.
DatabaseBase $db
Handle to the database subclass.
$wgLocalisationCacheConf
Localisation cache configuration.
disableContentHandlerUseDB()
Turns off content handler fields during parts of the upgrade where they aren't available.
initOldGlobals()
Initialize all of the old globals.
array $updates
Array of updates to perform on the database.
dropField($table, $field, $patch, $fullpath=false)
Drop a field from an existing table.
array $updatesSkipped
Array of updates that were skipped.
static singleton()
Get a RepoGroup instance.
addExtensionIndex($tableName, $indexName, $sqlPath)
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
setDB(IDatabase $db)
Sets database object to be returned by getDB().
addIndex($table, $index, $patch, $fullpath=false)
Add a new index to an existing table.
purgeCache()
Purge the objectcache table.
$wgSharedDB
Shared database for multiple wikis.
getPostDatabaseUpdateMaintenance()
addField($table, $field, $patch, $fullpath=false)
Add a new field to an existing table.
setAppliedUpdates($version, $updates=[])
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
addTable($name, $patch, $fullpath=false)
Add a new table to the database.
insertUpdateRow($key, $val=null)
Helper function: Add a key to the updatelog table Obviously, only use this for updates that occur aft...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
doEnableProfiling()
Enable profiling table when it's turned on.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
appendLine($line)
Append a line to the open filehandle.
getCoreUpdateList()
Get an array of updates to perform on the database.
dropExtensionTable($tableName, $sqlPath)
doActiveUsersInit()
Sets the number of active users in the site_stats table.
setFlag($flag)
Set a flag for this connection.
Database abstraction object.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
wfGetLBFactory()
Get the load balancer factory object.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
doMigrateUserOptions()
Migrates user options from the user table blob to user_properties.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these updates(as a Java servelet could)
addExtensionField($tableName, $columnName, $sqlPath)
renameExtensionIndex($tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning=false)
Rename an index on an extension table.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
modifyField($table, $field, $patch, $fullpath=false)
Modify an existing field.
doLogSearchPopulation()
Migrate log params to new table and index for searching.
runUpdates(array $updates, $passSelf)
Helper function for doUpdates()
updateRowExists($key)
Helper function: check if the given key is present in the updatelog table.
static newForDB(&$db, $shared=false, $maintenance=null)
static getDBTypes()
Get a list of known DB types.
$wgAutoloadClasses
Array mapping class names to filenames, for autoloading.
$holdContentHandlerUseDB
Hold the value of $wgContentHandlerUseDB during the upgrade.
enableContentHandlerUseDB()
Turns content handler fields back on.
writeSchemaUpdateFile($schemaUpdate=[])
addExtensionUpdate(array $update)
Add a new update coming from an extension.
renameIndex($table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath=false)
Rename an index from an existing table.
setFileAccess()
Set any .htaccess files or equivilent for storage repos.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
modifyExtensionField($tableName, $fieldName, $sqlPath)
doCollationUpdate()
Update CategoryLinks collation.
getOldGlobalUpdates()
Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
doLogUsertextPopulation()
Populates the log_user_text field in the logging table.
doTable($name)
Returns whether updates should be executed on the database table $name.
Allows to change the fields on the form that will be generated $name