MediaWiki  master
DatabaseUpdater.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/../../maintenance/Maintenance.php';
25 
33 abstract class DatabaseUpdater {
34  protected static $updateCounter = 0;
35 
41  protected $updates = [];
42 
48  protected $updatesSkipped = [];
49 
54  protected $extensionUpdates = [];
55 
61  protected $db;
62 
63  protected $shared = false;
64 
79  ];
80 
86  protected $fileHandle = null;
87 
93  protected $skipSchema = false;
94 
98  protected $holdContentHandlerUseDB = true;
99 
107  protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
108  $this->db = $db;
109  $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
110  $this->shared = $shared;
111  if ( $maintenance ) {
112  $this->maintenance = $maintenance;
113  $this->fileHandle = $maintenance->fileHandle;
114  } else {
115  $this->maintenance = new FakeMaintenance;
116  }
117  $this->maintenance->setDB( $db );
118  $this->initOldGlobals();
119  $this->loadExtensions();
120  Hooks::run( 'LoadExtensionSchemaUpdates', [ $this ] );
121  }
122 
127  private function initOldGlobals() {
128  global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
129  $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
130 
131  # For extensions only, should be populated via hooks
132  # $wgDBtype should be checked to specifiy the proper file
133  $wgExtNewTables = []; // table, dir
134  $wgExtNewFields = []; // table, column, dir
135  $wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
136  $wgExtPGAlteredFields = []; // table, column, new type, conversion method; for PostgreSQL
137  $wgExtNewIndexes = []; // table, index, dir
138  $wgExtModifiedFields = []; // table, index, dir
139  }
140 
145  private function loadExtensions() {
146  if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
147  return; // already loaded
148  }
150 
151  $registry = ExtensionRegistry::getInstance();
152  $queue = $registry->getQueue();
153  // Don't accidentally load extensions in the future
154  $registry->clearQueue();
155 
156  // This will automatically add "AutoloadClasses" to $wgAutoloadClasses
157  $data = $registry->readFromQueue( $queue );
158  $hooks = [ 'wgHooks' => [ 'LoadExtensionSchemaUpdates' => [] ] ];
159  if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
160  $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
161  }
162  if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
163  $hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
164  }
166  $wgHooks['LoadExtensionSchemaUpdates'] = $hooks;
167  if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
168  $wgAutoloadClasses += $vars['wgAutoloadClasses'];
169  }
170  }
171 
180  public static function newForDB( &$db, $shared = false, $maintenance = null ) {
181  $type = $db->getType();
182  if ( in_array( $type, Installer::getDBTypes() ) ) {
183  $class = ucfirst( $type ) . 'Updater';
184 
185  return new $class( $db, $shared, $maintenance );
186  } else {
187  throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
188  }
189  }
190 
196  public function getDB() {
197  return $this->db;
198  }
199 
205  public function output( $str ) {
206  if ( $this->maintenance->isQuiet() ) {
207  return;
208  }
210  if ( !$wgCommandLineMode ) {
211  $str = htmlspecialchars( $str );
212  }
213  echo $str;
214  flush();
215  }
216 
230  public function addExtensionUpdate( array $update ) {
231  $this->extensionUpdates[] = $update;
232  }
233 
243  public function addExtensionTable( $tableName, $sqlPath ) {
244  $this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ];
245  }
246 
254  public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
255  $this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ];
256  }
257 
266  public function addExtensionField( $tableName, $columnName, $sqlPath ) {
267  $this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ];
268  }
269 
278  public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
279  $this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ];
280  }
281 
291  public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
292  $this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ];
293  }
294 
302  public function dropExtensionTable( $tableName, $sqlPath ) {
303  $this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ];
304  }
305 
318  public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
319  $sqlPath, $skipBothIndexExistWarning = false
320  ) {
321  $this->extensionUpdates[] = [
322  'renameIndex',
323  $tableName,
324  $oldIndexName,
325  $newIndexName,
326  $skipBothIndexExistWarning,
327  $sqlPath,
328  true
329  ];
330  }
331 
339  public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
340  $this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ];
341  }
342 
350  public function tableExists( $tableName ) {
351  return ( $this->db->tableExists( $tableName, __METHOD__ ) );
352  }
353 
363  public function addPostDatabaseUpdateMaintenance( $class ) {
364  $this->postDatabaseUpdateMaintenance[] = $class;
365  }
366 
372  protected function getExtensionUpdates() {
374  }
375 
383  }
384 
391  private function writeSchemaUpdateFile( $schemaUpdate = [] ) {
393  $this->updatesSkipped = [];
394 
395  foreach ( $updates as $funcList ) {
396  $func = $funcList[0];
397  $arg = $funcList[1];
398  $origParams = $funcList[2];
399  call_user_func_array( $func, $arg );
400  flush();
401  $this->updatesSkipped[] = $origParams;
402  }
403  }
404 
410  public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
412 
413  $what = array_flip( $what );
414  $this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
415  if ( isset( $what['core'] ) ) {
416  $this->runUpdates( $this->getCoreUpdateList(), false );
417  }
418  if ( isset( $what['extensions'] ) ) {
419  $this->runUpdates( $this->getOldGlobalUpdates(), false );
420  $this->runUpdates( $this->getExtensionUpdates(), true );
421  }
422 
423  if ( isset( $what['stats'] ) ) {
424  $this->checkStats();
425  }
426 
427  $this->setAppliedUpdates( $wgVersion, $this->updates );
428 
429  if ( $this->fileHandle ) {
430  $this->skipSchema = false;
431  $this->writeSchemaUpdateFile();
432  $this->setAppliedUpdates( "$wgVersion-schema", $this->updatesSkipped );
433  }
434  }
435 
442  private function runUpdates( array $updates, $passSelf ) {
443  $updatesDone = [];
444  $updatesSkipped = [];
445  foreach ( $updates as $params ) {
446  $origParams = $params;
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 );
452  }
453  $ret = call_user_func_array( $func, $params );
454  flush();
455  if ( $ret !== false ) {
456  $updatesDone[] = $origParams;
457  wfGetLBFactory()->waitForReplication();
458  } else {
459  $updatesSkipped[] = [ $func, $params, $origParams ];
460  }
461  }
462  $this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped );
463  $this->updates = array_merge( $this->updates, $updatesDone );
464  }
465 
470  protected function setAppliedUpdates( $version, $updates = [] ) {
471  $this->db->clearFlag( DBO_DDLMODE );
472  if ( !$this->canUseNewUpdatelog() ) {
473  return;
474  }
475  $key = "updatelist-$version-" . time() . self::$updateCounter;
476  self::$updateCounter++;
477  $this->db->insert( 'updatelog',
478  [ 'ul_key' => $key, 'ul_value' => serialize( $updates ) ],
479  __METHOD__ );
480  $this->db->setFlag( DBO_DDLMODE );
481  }
482 
490  public function updateRowExists( $key ) {
491  $row = $this->db->selectRow(
492  'updatelog',
493  # Bug 65813
494  '1 AS X',
495  [ 'ul_key' => $key ],
496  __METHOD__
497  );
498 
499  return (bool)$row;
500  }
501 
509  public function insertUpdateRow( $key, $val = null ) {
510  $this->db->clearFlag( DBO_DDLMODE );
511  $values = [ 'ul_key' => $key ];
512  if ( $val && $this->canUseNewUpdatelog() ) {
513  $values['ul_value'] = $val;
514  }
515  $this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
516  $this->db->setFlag( DBO_DDLMODE );
517  }
518 
527  protected function canUseNewUpdatelog() {
528  return $this->db->tableExists( 'updatelog', __METHOD__ ) &&
529  $this->db->fieldExists( 'updatelog', 'ul_value', __METHOD__ );
530  }
531 
540  protected function doTable( $name ) {
542 
543  // Don't bother to check $wgSharedTables if there isn't a shared database
544  // or the user actually also wants to do updates on the shared database.
545  if ( $wgSharedDB === null || $this->shared ) {
546  return true;
547  }
548 
549  if ( in_array( $name, $wgSharedTables ) ) {
550  $this->output( "...skipping update to shared table $name.\n" );
551  return false;
552  } else {
553  return true;
554  }
555  }
556 
565  protected function getOldGlobalUpdates() {
566  global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
567  $wgExtNewIndexes;
568 
569  $updates = [];
570 
571  foreach ( $wgExtNewTables as $tableRecord ) {
572  $updates[] = [
573  'addTable', $tableRecord[0], $tableRecord[1], true
574  ];
575  }
576 
577  foreach ( $wgExtNewFields as $fieldRecord ) {
578  $updates[] = [
579  'addField', $fieldRecord[0], $fieldRecord[1],
580  $fieldRecord[2], true
581  ];
582  }
583 
584  foreach ( $wgExtNewIndexes as $fieldRecord ) {
585  $updates[] = [
586  'addIndex', $fieldRecord[0], $fieldRecord[1],
587  $fieldRecord[2], true
588  ];
589  }
590 
591  foreach ( $wgExtModifiedFields as $fieldRecord ) {
592  $updates[] = [
593  'modifyField', $fieldRecord[0], $fieldRecord[1],
594  $fieldRecord[2], true
595  ];
596  }
597 
598  return $updates;
599  }
600 
609  abstract protected function getCoreUpdateList();
610 
616  public function copyFile( $filename ) {
617  $this->db->sourceFile( $filename, false, false, false,
618  [ $this, 'appendLine' ]
619  );
620  }
621 
632  public function appendLine( $line ) {
633  $line = rtrim( $line ) . ";\n";
634  if ( fwrite( $this->fileHandle, $line ) === false ) {
635  throw new MWException( "trouble writing file" );
636  }
637 
638  return false;
639  }
640 
649  protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
650  if ( $msg === null ) {
651  $msg = "Applying $path patch";
652  }
653  if ( $this->skipSchema ) {
654  $this->output( "...skipping schema change ($msg).\n" );
655 
656  return false;
657  }
658 
659  $this->output( "$msg ..." );
660 
661  if ( !$isFullPath ) {
662  $path = $this->db->patchPath( $path );
663  }
664  if ( $this->fileHandle !== null ) {
665  $this->copyFile( $path );
666  } else {
667  $this->db->sourceFile( $path );
668  }
669  $this->output( "done.\n" );
670 
671  return true;
672  }
673 
682  protected function addTable( $name, $patch, $fullpath = false ) {
683  if ( !$this->doTable( $name ) ) {
684  return true;
685  }
686 
687  if ( $this->db->tableExists( $name, __METHOD__ ) ) {
688  $this->output( "...$name table already exists.\n" );
689  } else {
690  return $this->applyPatch( $patch, $fullpath, "Creating $name table" );
691  }
692 
693  return true;
694  }
695 
705  protected function addField( $table, $field, $patch, $fullpath = false ) {
706  if ( !$this->doTable( $table ) ) {
707  return true;
708  }
709 
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" );
714  } else {
715  return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" );
716  }
717 
718  return true;
719  }
720 
730  protected function addIndex( $table, $index, $patch, $fullpath = false ) {
731  if ( !$this->doTable( $table ) ) {
732  return true;
733  }
734 
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" );
739  } else {
740  return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
741  }
742 
743  return true;
744  }
745 
755  protected function dropField( $table, $field, $patch, $fullpath = false ) {
756  if ( !$this->doTable( $table ) ) {
757  return true;
758  }
759 
760  if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
761  return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" );
762  } else {
763  $this->output( "...$table table does not contain $field field.\n" );
764  }
765 
766  return true;
767  }
768 
778  protected function dropIndex( $table, $index, $patch, $fullpath = false ) {
779  if ( !$this->doTable( $table ) ) {
780  return true;
781  }
782 
783  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
784  return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" );
785  } else {
786  $this->output( "...$index key doesn't exist.\n" );
787  }
788 
789  return true;
790  }
791 
804  protected function renameIndex( $table, $oldIndex, $newIndex,
805  $skipBothIndexExistWarning, $patch, $fullpath = false
806  ) {
807  if ( !$this->doTable( $table ) ) {
808  return true;
809  }
810 
811  // First requirement: the table must exist
812  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
813  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
814 
815  return true;
816  }
817 
818  // Second requirement: the new index must be missing
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__ )
823  ) {
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" );
827  }
828 
829  return true;
830  }
831 
832  // Third requirement: the old index must exist
833  if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
834  $this->output( "...skipping: index $oldIndex doesn't exist.\n" );
835 
836  return true;
837  }
838 
839  // Requirements have been satisfied, patch can be applied
840  return $this->applyPatch(
841  $patch,
842  $fullpath,
843  "Renaming index $oldIndex into $newIndex to table $table"
844  );
845  }
846 
858  public function dropTable( $table, $patch = false, $fullpath = false ) {
859  if ( !$this->doTable( $table ) ) {
860  return true;
861  }
862 
863  if ( $this->db->tableExists( $table, __METHOD__ ) ) {
864  $msg = "Dropping table $table";
865 
866  if ( $patch === false ) {
867  $this->output( "$msg ..." );
868  $this->db->dropTable( $table, __METHOD__ );
869  $this->output( "done.\n" );
870  } else {
871  return $this->applyPatch( $patch, $fullpath, $msg );
872  }
873  } else {
874  $this->output( "...$table doesn't exist.\n" );
875  }
876 
877  return true;
878  }
879 
889  public function modifyField( $table, $field, $patch, $fullpath = false ) {
890  if ( !$this->doTable( $table ) ) {
891  return true;
892  }
893 
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" );
900  } elseif ( $this->updateRowExists( $updateKey ) ) {
901  $this->output( "...$field in table $table already modified by patch $patch.\n" );
902  } else {
903  $this->insertUpdateRow( $updateKey );
904 
905  return $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
906  }
907 
908  return true;
909  }
910 
916  public function setFileAccess() {
917  $repo = RepoGroup::singleton()->getLocalRepo();
918  $zonePath = $repo->getZonePath( 'temp' );
919  if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) {
920  // If the directory was never made, then it will have the right ACLs when it is made
921  $status = $repo->getBackend()->secure( [
922  'dir' => $zonePath,
923  'noAccess' => true,
924  'noListing' => true
925  ] );
926  if ( $status->isOK() ) {
927  $this->output( "Set the local repo temp zone container to be private.\n" );
928  } else {
929  $this->output( "Failed to set the local repo temp zone container to be private.\n" );
930  }
931  }
932  }
933 
937  public function purgeCache() {
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'] ) {
944  $this->rebuildLocalisationCache();
945  }
946  $blobStore = new MessageBlobStore();
947  $blobStore->clear();
948  $this->db->delete( 'module_deps', '*', __METHOD__ );
949  $this->output( "done.\n" );
950  }
951 
955  protected function checkStats() {
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" );
962  } else {
963  $this->output( "done.\n" );
964 
965  return;
966  }
967  SiteStatsInit::doAllAndCommit( $this->db );
968  }
969 
970  # Common updater functions
971 
975  protected function doActiveUsersInit() {
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__
981  );
982  $this->db->update( 'site_stats',
983  [ 'ss_active_users' => intval( $activeUsers ) ],
984  [ 'ss_row_id' => 1 ], __METHOD__, [ 'LIMIT' => 1 ]
985  );
986  }
987  $this->output( "...ss_active_users user count set...\n" );
988  }
989 
993  protected function doLogUsertextPopulation() {
994  if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
995  $this->output(
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"
999  );
1000 
1001  $task = $this->maintenance->runChild( 'PopulateLogUsertext' );
1002  $task->execute();
1003  $this->output( "done.\n" );
1004  }
1005  }
1006 
1010  protected function doLogSearchPopulation() {
1011  if ( !$this->updateRowExists( 'populate log_search' ) ) {
1012  $this->output(
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" );
1016 
1017  $task = $this->maintenance->runChild( 'PopulateLogSearch' );
1018  $task->execute();
1019  $this->output( "done.\n" );
1020  }
1021  }
1022 
1027  protected function doUpdateTranscacheField() {
1028  if ( $this->updateRowExists( 'convert transcache field' ) ) {
1029  $this->output( "...transcache tc_time already converted.\n" );
1030 
1031  return true;
1032  }
1033 
1034  return $this->applyPatch( 'patch-tc-timestamp.sql', false,
1035  "Converting tc_time from UNIX epoch to MediaWiki timestamp" );
1036  }
1037 
1041  protected function doCollationUpdate() {
1043  if ( $this->db->fieldExists( 'categorylinks', 'cl_collation', __METHOD__ ) ) {
1044  if ( $this->db->selectField(
1045  'categorylinks',
1046  'COUNT(*)',
1047  'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
1048  __METHOD__
1049  ) == 0
1050  ) {
1051  $this->output( "...collations up-to-date.\n" );
1052 
1053  return;
1054  }
1055 
1056  $this->output( "Updating category collations..." );
1057  $task = $this->maintenance->runChild( 'UpdateCollation' );
1058  $task->execute();
1059  $this->output( "...done.\n" );
1060  }
1061  }
1062 
1066  protected function doMigrateUserOptions() {
1067  if ( $this->db->tableExists( 'user_properties' ) ) {
1068  $cl = $this->maintenance->runChild( 'ConvertUserOptions', 'convertUserOptions.php' );
1069  $cl->execute();
1070  $this->output( "done.\n" );
1071  }
1072  }
1073 
1077  protected function doEnableProfiling() {
1079 
1080  if ( !$this->doTable( 'profiling' ) ) {
1081  return true;
1082  }
1083 
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;
1091  }
1092  }
1093 
1094  if ( $profileToDb && !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
1095  $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
1096  }
1097  }
1098 
1102  protected function rebuildLocalisationCache() {
1106  $cl = $this->maintenance->runChild( 'RebuildLocalisationCache', 'rebuildLocalisationCache.php' );
1107  $this->output( "Rebuilding localisation cache...\n" );
1108  $cl->setForce();
1109  $cl->execute();
1110  $this->output( "done.\n" );
1111  }
1112 
1117  protected function disableContentHandlerUseDB() {
1119 
1120  if ( $wgContentHandlerUseDB ) {
1121  $this->output( "Turning off Content Handler DB fields for this part of upgrade.\n" );
1122  $this->holdContentHandlerUseDB = $wgContentHandlerUseDB;
1123  $wgContentHandlerUseDB = false;
1124  }
1125  }
1126 
1130  protected function enableContentHandlerUseDB() {
1132 
1133  if ( $this->holdContentHandlerUseDB ) {
1134  $this->output( "Content Handler DB fields should be usable now.\n" );
1135  $wgContentHandlerUseDB = $this->holdContentHandlerUseDB;
1136  }
1137  }
1138 }
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
Definition: hooks.txt:776
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...
Definition: maintenance.txt:39
$wgProfiler
Definition: WebStart.php:73
$wgSharedTables
resource $fileHandle
File handle for SQL output.
rebuildLocalisationCache()
Rebuilds the localisation cache.
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
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
Definition: design.txt:93
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.
Definition: SiteStats.php:376
__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
Definition: hooks.txt:1816
Fake maintenance wrapper, mostly used for the web installer/updater.
getDB()
Get a database connection to run updates.
global $wgCommandLineMode
Definition: Setup.php:511
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.
Definition: RepoGroup.php:59
addExtensionIndex($tableName, $indexName, $sqlPath)
MediaWiki exception.
Definition: MWException.php:26
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
Definition: Installer.php:575
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.
$params
purgeCache()
Purge the objectcache table.
$wgSharedDB
Shared database for multiple wikis.
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.
Definition: Hooks.php:131
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
Definition: hooks.txt:1816
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
Definition: distributors.txt:9
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.
Definition: Database.php:412
Database abstraction object.
Definition: Database.php:32
$maintenance
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
Definition: injection.txt:35
wfGetLBFactory()
Get the load balancer factory object.
const DBO_DDLMODE
Definition: Defines.php:37
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
Definition: maintenance.txt:52
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)
$line
Definition: cdb.php:59
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
Definition: hooks.txt:1020
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.
tableExists($tableName)
$version
Definition: parserTests.php:94
serialize()
Definition: ApiMessage.php:94
static newForDB(&$db, $shared=false, $maintenance=null)
static getDBTypes()
Get a list of known DB types.
Definition: Installer.php:459
$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
Definition: hooks.txt:2044
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
Definition: hooks.txt:2376
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
Definition: hooks.txt:310