MediaWiki  1.27.2
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 
78  ];
79 
85  protected $fileHandle = null;
86 
92  protected $skipSchema = false;
93 
97  protected $holdContentHandlerUseDB = true;
98 
106  protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
107  $this->db = $db;
108  $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
109  $this->shared = $shared;
110  if ( $maintenance ) {
111  $this->maintenance = $maintenance;
112  $this->fileHandle = $maintenance->fileHandle;
113  } else {
114  $this->maintenance = new FakeMaintenance;
115  }
116  $this->maintenance->setDB( $db );
117  $this->initOldGlobals();
118  $this->loadExtensions();
119  Hooks::run( 'LoadExtensionSchemaUpdates', [ $this ] );
120  }
121 
126  private function initOldGlobals() {
127  global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
128  $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
129 
130  # For extensions only, should be populated via hooks
131  # $wgDBtype should be checked to specifiy the proper file
132  $wgExtNewTables = []; // table, dir
133  $wgExtNewFields = []; // table, column, dir
134  $wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
135  $wgExtPGAlteredFields = []; // table, column, new type, conversion method; for PostgreSQL
136  $wgExtNewIndexes = []; // table, index, dir
137  $wgExtModifiedFields = []; // table, index, dir
138  }
139 
144  private function loadExtensions() {
145  if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
146  return; // already loaded
147  }
149 
150  $registry = ExtensionRegistry::getInstance();
151  $queue = $registry->getQueue();
152  // Don't accidentally load extensions in the future
153  $registry->clearQueue();
154 
155  // This will automatically add "AutoloadClasses" to $wgAutoloadClasses
156  $data = $registry->readFromQueue( $queue );
157  $hooks = [ 'wgHooks' => [ 'LoadExtensionSchemaUpdates' => [] ] ];
158  if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
159  $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
160  }
161  if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
162  $hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
163  }
165  $wgHooks['LoadExtensionSchemaUpdates'] = $hooks;
166  if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
167  $wgAutoloadClasses += $vars['wgAutoloadClasses'];
168  }
169  }
170 
179  public static function newForDB( &$db, $shared = false, $maintenance = null ) {
180  $type = $db->getType();
181  if ( in_array( $type, Installer::getDBTypes() ) ) {
182  $class = ucfirst( $type ) . 'Updater';
183 
184  return new $class( $db, $shared, $maintenance );
185  } else {
186  throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
187  }
188  }
189 
195  public function getDB() {
196  return $this->db;
197  }
198 
204  public function output( $str ) {
205  if ( $this->maintenance->isQuiet() ) {
206  return;
207  }
209  if ( !$wgCommandLineMode ) {
210  $str = htmlspecialchars( $str );
211  }
212  echo $str;
213  flush();
214  }
215 
229  public function addExtensionUpdate( array $update ) {
230  $this->extensionUpdates[] = $update;
231  }
232 
242  public function addExtensionTable( $tableName, $sqlPath ) {
243  $this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ];
244  }
245 
253  public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
254  $this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ];
255  }
256 
265  public function addExtensionField( $tableName, $columnName, $sqlPath ) {
266  $this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ];
267  }
268 
277  public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
278  $this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ];
279  }
280 
290  public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
291  $this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ];
292  }
293 
301  public function dropExtensionTable( $tableName, $sqlPath ) {
302  $this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ];
303  }
304 
317  public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
318  $sqlPath, $skipBothIndexExistWarning = false
319  ) {
320  $this->extensionUpdates[] = [
321  'renameIndex',
322  $tableName,
323  $oldIndexName,
324  $newIndexName,
325  $skipBothIndexExistWarning,
326  $sqlPath,
327  true
328  ];
329  }
330 
338  public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
339  $this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ];
340  }
341 
349  public function tableExists( $tableName ) {
350  return ( $this->db->tableExists( $tableName, __METHOD__ ) );
351  }
352 
362  public function addPostDatabaseUpdateMaintenance( $class ) {
363  $this->postDatabaseUpdateMaintenance[] = $class;
364  }
365 
371  protected function getExtensionUpdates() {
373  }
374 
382  }
383 
390  private function writeSchemaUpdateFile( $schemaUpdate = [] ) {
392  $this->updatesSkipped = [];
393 
394  foreach ( $updates as $funcList ) {
395  $func = $funcList[0];
396  $arg = $funcList[1];
397  $origParams = $funcList[2];
398  call_user_func_array( $func, $arg );
399  flush();
400  $this->updatesSkipped[] = $origParams;
401  }
402  }
403 
409  public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
411 
412  $this->db->begin( __METHOD__ );
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  $this->db->commit( __METHOD__ );
436  }
437 
444  private function runUpdates( array $updates, $passSelf ) {
445  $updatesDone = [];
446  $updatesSkipped = [];
447  foreach ( $updates as $params ) {
448  $origParams = $params;
449  $func = array_shift( $params );
450  if ( !is_array( $func ) && method_exists( $this, $func ) ) {
451  $func = [ $this, $func ];
452  } elseif ( $passSelf ) {
453  array_unshift( $params, $this );
454  }
455  $ret = call_user_func_array( $func, $params );
456  flush();
457  if ( $ret !== false ) {
458  $updatesDone[] = $origParams;
459  wfGetLBFactory()->waitForReplication();
460  } else {
461  $updatesSkipped[] = [ $func, $params, $origParams ];
462  }
463  }
464  $this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped );
465  $this->updates = array_merge( $this->updates, $updatesDone );
466  }
467 
472  protected function setAppliedUpdates( $version, $updates = [] ) {
473  $this->db->clearFlag( DBO_DDLMODE );
474  if ( !$this->canUseNewUpdatelog() ) {
475  return;
476  }
477  $key = "updatelist-$version-" . time() . self::$updateCounter;
478  self::$updateCounter++;
479  $this->db->insert( 'updatelog',
480  [ 'ul_key' => $key, 'ul_value' => serialize( $updates ) ],
481  __METHOD__ );
482  $this->db->setFlag( DBO_DDLMODE );
483  }
484 
492  public function updateRowExists( $key ) {
493  $row = $this->db->selectRow(
494  'updatelog',
495  # Bug 65813
496  '1 AS X',
497  [ 'ul_key' => $key ],
498  __METHOD__
499  );
500 
501  return (bool)$row;
502  }
503 
511  public function insertUpdateRow( $key, $val = null ) {
512  $this->db->clearFlag( DBO_DDLMODE );
513  $values = [ 'ul_key' => $key ];
514  if ( $val && $this->canUseNewUpdatelog() ) {
515  $values['ul_value'] = $val;
516  }
517  $this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
518  $this->db->setFlag( DBO_DDLMODE );
519  }
520 
529  protected function canUseNewUpdatelog() {
530  return $this->db->tableExists( 'updatelog', __METHOD__ ) &&
531  $this->db->fieldExists( 'updatelog', 'ul_value', __METHOD__ );
532  }
533 
542  protected function doTable( $name ) {
544 
545  // Don't bother to check $wgSharedTables if there isn't a shared database
546  // or the user actually also wants to do updates on the shared database.
547  if ( $wgSharedDB === null || $this->shared ) {
548  return true;
549  }
550 
551  if ( in_array( $name, $wgSharedTables ) ) {
552  $this->output( "...skipping update to shared table $name.\n" );
553  return false;
554  } else {
555  return true;
556  }
557  }
558 
567  protected function getOldGlobalUpdates() {
568  global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
569  $wgExtNewIndexes;
570 
571  $updates = [];
572 
573  foreach ( $wgExtNewTables as $tableRecord ) {
574  $updates[] = [
575  'addTable', $tableRecord[0], $tableRecord[1], true
576  ];
577  }
578 
579  foreach ( $wgExtNewFields as $fieldRecord ) {
580  $updates[] = [
581  'addField', $fieldRecord[0], $fieldRecord[1],
582  $fieldRecord[2], true
583  ];
584  }
585 
586  foreach ( $wgExtNewIndexes as $fieldRecord ) {
587  $updates[] = [
588  'addIndex', $fieldRecord[0], $fieldRecord[1],
589  $fieldRecord[2], true
590  ];
591  }
592 
593  foreach ( $wgExtModifiedFields as $fieldRecord ) {
594  $updates[] = [
595  'modifyField', $fieldRecord[0], $fieldRecord[1],
596  $fieldRecord[2], true
597  ];
598  }
599 
600  return $updates;
601  }
602 
611  abstract protected function getCoreUpdateList();
612 
618  public function copyFile( $filename ) {
619  $this->db->sourceFile( $filename, false, false, false,
620  [ $this, 'appendLine' ]
621  );
622  }
623 
634  public function appendLine( $line ) {
635  $line = rtrim( $line ) . ";\n";
636  if ( fwrite( $this->fileHandle, $line ) === false ) {
637  throw new MWException( "trouble writing file" );
638  }
639 
640  return false;
641  }
642 
651  protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
652  if ( $msg === null ) {
653  $msg = "Applying $path patch";
654  }
655  if ( $this->skipSchema ) {
656  $this->output( "...skipping schema change ($msg).\n" );
657 
658  return false;
659  }
660 
661  $this->output( "$msg ..." );
662 
663  if ( !$isFullPath ) {
664  $path = $this->db->patchPath( $path );
665  }
666  if ( $this->fileHandle !== null ) {
667  $this->copyFile( $path );
668  } else {
669  $this->db->sourceFile( $path );
670  }
671  $this->output( "done.\n" );
672 
673  return true;
674  }
675 
684  protected function addTable( $name, $patch, $fullpath = false ) {
685  if ( !$this->doTable( $name ) ) {
686  return true;
687  }
688 
689  if ( $this->db->tableExists( $name, __METHOD__ ) ) {
690  $this->output( "...$name table already exists.\n" );
691  } else {
692  return $this->applyPatch( $patch, $fullpath, "Creating $name table" );
693  }
694 
695  return true;
696  }
697 
707  protected function addField( $table, $field, $patch, $fullpath = false ) {
708  if ( !$this->doTable( $table ) ) {
709  return true;
710  }
711 
712  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
713  $this->output( "...$table table does not exist, skipping new field patch.\n" );
714  } elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
715  $this->output( "...have $field field in $table table.\n" );
716  } else {
717  return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" );
718  }
719 
720  return true;
721  }
722 
732  protected function addIndex( $table, $index, $patch, $fullpath = false ) {
733  if ( !$this->doTable( $table ) ) {
734  return true;
735  }
736 
737  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
738  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
739  } elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
740  $this->output( "...index $index already set on $table table.\n" );
741  } else {
742  return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
743  }
744 
745  return true;
746  }
747 
757  protected function dropField( $table, $field, $patch, $fullpath = false ) {
758  if ( !$this->doTable( $table ) ) {
759  return true;
760  }
761 
762  if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
763  return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" );
764  } else {
765  $this->output( "...$table table does not contain $field field.\n" );
766  }
767 
768  return true;
769  }
770 
780  protected function dropIndex( $table, $index, $patch, $fullpath = false ) {
781  if ( !$this->doTable( $table ) ) {
782  return true;
783  }
784 
785  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
786  return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" );
787  } else {
788  $this->output( "...$index key doesn't exist.\n" );
789  }
790 
791  return true;
792  }
793 
806  protected function renameIndex( $table, $oldIndex, $newIndex,
807  $skipBothIndexExistWarning, $patch, $fullpath = false
808  ) {
809  if ( !$this->doTable( $table ) ) {
810  return true;
811  }
812 
813  // First requirement: the table must exist
814  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
815  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
816 
817  return true;
818  }
819 
820  // Second requirement: the new index must be missing
821  if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
822  $this->output( "...index $newIndex already set on $table table.\n" );
823  if ( !$skipBothIndexExistWarning &&
824  $this->db->indexExists( $table, $oldIndex, __METHOD__ )
825  ) {
826  $this->output( "...WARNING: $oldIndex still exists, despite it has " .
827  "been renamed into $newIndex (which also exists).\n" .
828  " $oldIndex should be manually removed if not needed anymore.\n" );
829  }
830 
831  return true;
832  }
833 
834  // Third requirement: the old index must exist
835  if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
836  $this->output( "...skipping: index $oldIndex doesn't exist.\n" );
837 
838  return true;
839  }
840 
841  // Requirements have been satisfied, patch can be applied
842  return $this->applyPatch(
843  $patch,
844  $fullpath,
845  "Renaming index $oldIndex into $newIndex to table $table"
846  );
847  }
848 
860  public function dropTable( $table, $patch = false, $fullpath = false ) {
861  if ( !$this->doTable( $table ) ) {
862  return true;
863  }
864 
865  if ( $this->db->tableExists( $table, __METHOD__ ) ) {
866  $msg = "Dropping table $table";
867 
868  if ( $patch === false ) {
869  $this->output( "$msg ..." );
870  $this->db->dropTable( $table, __METHOD__ );
871  $this->output( "done.\n" );
872  } else {
873  return $this->applyPatch( $patch, $fullpath, $msg );
874  }
875  } else {
876  $this->output( "...$table doesn't exist.\n" );
877  }
878 
879  return true;
880  }
881 
891  public function modifyField( $table, $field, $patch, $fullpath = false ) {
892  if ( !$this->doTable( $table ) ) {
893  return true;
894  }
895 
896  $updateKey = "$table-$field-$patch";
897  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
898  $this->output( "...$table table does not exist, skipping modify field patch.\n" );
899  } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
900  $this->output( "...$field field does not exist in $table table, " .
901  "skipping modify field patch.\n" );
902  } elseif ( $this->updateRowExists( $updateKey ) ) {
903  $this->output( "...$field in table $table already modified by patch $patch.\n" );
904  } else {
905  $this->insertUpdateRow( $updateKey );
906 
907  return $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
908  }
909 
910  return true;
911  }
912 
918  public function setFileAccess() {
919  $repo = RepoGroup::singleton()->getLocalRepo();
920  $zonePath = $repo->getZonePath( 'temp' );
921  if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) {
922  // If the directory was never made, then it will have the right ACLs when it is made
923  $status = $repo->getBackend()->secure( [
924  'dir' => $zonePath,
925  'noAccess' => true,
926  'noListing' => true
927  ] );
928  if ( $status->isOK() ) {
929  $this->output( "Set the local repo temp zone container to be private.\n" );
930  } else {
931  $this->output( "Failed to set the local repo temp zone container to be private.\n" );
932  }
933  }
934  }
935 
939  public function purgeCache() {
941  # We can't guarantee that the user will be able to use TRUNCATE,
942  # but we know that DELETE is available to us
943  $this->output( "Purging caches..." );
944  $this->db->delete( 'objectcache', '*', __METHOD__ );
945  if ( $wgLocalisationCacheConf['manualRecache'] ) {
946  $this->rebuildLocalisationCache();
947  }
948  $blobStore = new MessageBlobStore();
949  $blobStore->clear();
950  $this->db->delete( 'module_deps', '*', __METHOD__ );
951  $this->output( "done.\n" );
952  }
953 
957  protected function checkStats() {
958  $this->output( "...site_stats is populated..." );
959  $row = $this->db->selectRow( 'site_stats', '*', [ 'ss_row_id' => 1 ], __METHOD__ );
960  if ( $row === false ) {
961  $this->output( "data is missing! rebuilding...\n" );
962  } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
963  $this->output( "missing ss_total_pages, rebuilding...\n" );
964  } else {
965  $this->output( "done.\n" );
966 
967  return;
968  }
969  SiteStatsInit::doAllAndCommit( $this->db );
970  }
971 
972  # Common updater functions
973 
977  protected function doActiveUsersInit() {
978  $activeUsers = $this->db->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
979  if ( $activeUsers == -1 ) {
980  $activeUsers = $this->db->selectField( 'recentchanges',
981  'COUNT( DISTINCT rc_user_text )',
982  [ 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ], __METHOD__
983  );
984  $this->db->update( 'site_stats',
985  [ 'ss_active_users' => intval( $activeUsers ) ],
986  [ 'ss_row_id' => 1 ], __METHOD__, [ 'LIMIT' => 1 ]
987  );
988  }
989  $this->output( "...ss_active_users user count set...\n" );
990  }
991 
995  protected function doLogUsertextPopulation() {
996  if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
997  $this->output(
998  "Populating log_user_text field, printing progress markers. For large\n" .
999  "databases, you may want to hit Ctrl-C and do this manually with\n" .
1000  "maintenance/populateLogUsertext.php.\n"
1001  );
1002 
1003  $task = $this->maintenance->runChild( 'PopulateLogUsertext' );
1004  $task->execute();
1005  $this->output( "done.\n" );
1006  }
1007  }
1008 
1012  protected function doLogSearchPopulation() {
1013  if ( !$this->updateRowExists( 'populate log_search' ) ) {
1014  $this->output(
1015  "Populating log_search table, printing progress markers. For large\n" .
1016  "databases, you may want to hit Ctrl-C and do this manually with\n" .
1017  "maintenance/populateLogSearch.php.\n" );
1018 
1019  $task = $this->maintenance->runChild( 'PopulateLogSearch' );
1020  $task->execute();
1021  $this->output( "done.\n" );
1022  }
1023  }
1024 
1029  protected function doUpdateTranscacheField() {
1030  if ( $this->updateRowExists( 'convert transcache field' ) ) {
1031  $this->output( "...transcache tc_time already converted.\n" );
1032 
1033  return true;
1034  }
1035 
1036  return $this->applyPatch( 'patch-tc-timestamp.sql', false,
1037  "Converting tc_time from UNIX epoch to MediaWiki timestamp" );
1038  }
1039 
1043  protected function doCollationUpdate() {
1044  global $wgCategoryCollation;
1045  if ( $this->db->fieldExists( 'categorylinks', 'cl_collation', __METHOD__ ) ) {
1046  if ( $this->db->selectField(
1047  'categorylinks',
1048  'COUNT(*)',
1049  'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
1050  __METHOD__
1051  ) == 0
1052  ) {
1053  $this->output( "...collations up-to-date.\n" );
1054 
1055  return;
1056  }
1057 
1058  $this->output( "Updating category collations..." );
1059  $task = $this->maintenance->runChild( 'UpdateCollation' );
1060  $task->execute();
1061  $this->output( "...done.\n" );
1062  }
1063  }
1064 
1068  protected function doMigrateUserOptions() {
1069  if ( $this->db->tableExists( 'user_properties' ) ) {
1070  $cl = $this->maintenance->runChild( 'ConvertUserOptions', 'convertUserOptions.php' );
1071  $cl->execute();
1072  $this->output( "done.\n" );
1073  }
1074  }
1075 
1079  protected function doEnableProfiling() {
1081 
1082  if ( !$this->doTable( 'profiling' ) ) {
1083  return true;
1084  }
1085 
1086  $profileToDb = false;
1087  if ( isset( $wgProfiler['output'] ) ) {
1088  $out = $wgProfiler['output'];
1089  if ( $out === 'db' ) {
1090  $profileToDb = true;
1091  } elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
1092  $profileToDb = true;
1093  }
1094  }
1095 
1096  if ( $profileToDb && !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
1097  $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
1098  }
1099  }
1100 
1104  protected function rebuildLocalisationCache() {
1108  $cl = $this->maintenance->runChild( 'RebuildLocalisationCache', 'rebuildLocalisationCache.php' );
1109  $this->output( "Rebuilding localisation cache...\n" );
1110  $cl->setForce();
1111  $cl->execute();
1112  $this->output( "done.\n" );
1113  }
1114 
1119  protected function disableContentHandlerUseDB() {
1120  global $wgContentHandlerUseDB;
1121 
1122  if ( $wgContentHandlerUseDB ) {
1123  $this->output( "Turning off Content Handler DB fields for this part of upgrade.\n" );
1124  $this->holdContentHandlerUseDB = $wgContentHandlerUseDB;
1125  $wgContentHandlerUseDB = false;
1126  }
1127  }
1128 
1132  protected function enableContentHandlerUseDB() {
1133  global $wgContentHandlerUseDB;
1134 
1135  if ( $this->holdContentHandlerUseDB ) {
1136  $this->output( "Content Handler DB fields should be usable now.\n" );
1137  $wgContentHandlerUseDB = $this->holdContentHandlerUseDB;
1138  }
1139  }
1140 }
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:762
the array() calling protocol came about after MediaWiki 1.4rc1.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
$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.
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:1798
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.
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.
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:1798
Fake maintenance wrapper, mostly used for the web installer/updater.
getDB()
Get a database connection to run updates.
global $wgCommandLineMode
Definition: Setup.php:513
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)
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
Definition: Installer.php:533
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=[])
global $wgAutoloadClasses
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...
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:408
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:1004
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:85
serialize()
Definition: ApiMessage.php:94
static newForDB(&$db, $shared=false, $maintenance=null)
static getDBTypes()
Get a list of known DB types.
Definition: Installer.php:417
$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:1996
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:2338
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