MediaWiki  1.28.1
DatabaseUpdater.php
Go to the documentation of this file.
1 <?php
24 
25 require_once __DIR__ . '/../../maintenance/Maintenance.php';
26 
34 abstract class DatabaseUpdater {
35  protected static $updateCounter = 0;
36 
42  protected $updates = [];
43 
49  protected $updatesSkipped = [];
50 
55  protected $extensionUpdates = [];
56 
62  protected $db;
63 
64  protected $shared = false;
65 
81  ];
82 
88  protected $fileHandle = null;
89 
95  protected $skipSchema = false;
96 
100  protected $holdContentHandlerUseDB = true;
101 
109  protected function __construct( Database &$db, $shared, Maintenance $maintenance = null ) {
110  $this->db = $db;
111  $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
112  $this->shared = $shared;
113  if ( $maintenance ) {
114  $this->maintenance = $maintenance;
115  $this->fileHandle = $maintenance->fileHandle;
116  } else {
117  $this->maintenance = new FakeMaintenance;
118  }
119  $this->maintenance->setDB( $db );
120  $this->initOldGlobals();
121  $this->loadExtensions();
122  Hooks::run( 'LoadExtensionSchemaUpdates', [ $this ] );
123  }
124 
129  private function initOldGlobals() {
130  global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
131  $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
132 
133  # For extensions only, should be populated via hooks
134  # $wgDBtype should be checked to specifiy the proper file
135  $wgExtNewTables = []; // table, dir
136  $wgExtNewFields = []; // table, column, dir
137  $wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
138  $wgExtPGAlteredFields = []; // table, column, new type, conversion method; for PostgreSQL
139  $wgExtNewIndexes = []; // table, index, dir
140  $wgExtModifiedFields = []; // table, index, dir
141  }
142 
147  private function loadExtensions() {
148  if ( !defined( 'MEDIAWIKI_INSTALL' ) ) {
149  return; // already loaded
150  }
152 
153  $registry = ExtensionRegistry::getInstance();
154  $queue = $registry->getQueue();
155  // Don't accidentally load extensions in the future
156  $registry->clearQueue();
157 
158  // This will automatically add "AutoloadClasses" to $wgAutoloadClasses
159  $data = $registry->readFromQueue( $queue );
160  $hooks = [ 'wgHooks' => [ 'LoadExtensionSchemaUpdates' => [] ] ];
161  if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
162  $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
163  }
164  if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
165  $hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
166  }
168  $wgHooks['LoadExtensionSchemaUpdates'] = $hooks;
169  if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) {
170  $wgAutoloadClasses += $vars['wgAutoloadClasses'];
171  }
172  }
173 
182  public static function newForDB( Database $db, $shared = false, $maintenance = null ) {
183  $type = $db->getType();
184  if ( in_array( $type, Installer::getDBTypes() ) ) {
185  $class = ucfirst( $type ) . 'Updater';
186 
187  return new $class( $db, $shared, $maintenance );
188  } else {
189  throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
190  }
191  }
192 
198  public function getDB() {
199  return $this->db;
200  }
201 
207  public function output( $str ) {
208  if ( $this->maintenance->isQuiet() ) {
209  return;
210  }
212  if ( !$wgCommandLineMode ) {
213  $str = htmlspecialchars( $str );
214  }
215  echo $str;
216  flush();
217  }
218 
231  public function addExtensionUpdate( array $update ) {
232  $this->extensionUpdates[] = $update;
233  }
234 
244  public function addExtensionTable( $tableName, $sqlPath ) {
245  $this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ];
246  }
247 
255  public function addExtensionIndex( $tableName, $indexName, $sqlPath ) {
256  $this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ];
257  }
258 
267  public function addExtensionField( $tableName, $columnName, $sqlPath ) {
268  $this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ];
269  }
270 
279  public function dropExtensionField( $tableName, $columnName, $sqlPath ) {
280  $this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ];
281  }
282 
292  public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) {
293  $this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ];
294  }
295 
303  public function dropExtensionTable( $tableName, $sqlPath ) {
304  $this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ];
305  }
306 
319  public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName,
320  $sqlPath, $skipBothIndexExistWarning = false
321  ) {
322  $this->extensionUpdates[] = [
323  'renameIndex',
324  $tableName,
325  $oldIndexName,
326  $newIndexName,
327  $skipBothIndexExistWarning,
328  $sqlPath,
329  true
330  ];
331  }
332 
340  public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) {
341  $this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ];
342  }
343 
351  public function tableExists( $tableName ) {
352  return ( $this->db->tableExists( $tableName, __METHOD__ ) );
353  }
354 
364  public function addPostDatabaseUpdateMaintenance( $class ) {
365  $this->postDatabaseUpdateMaintenance[] = $class;
366  }
367 
373  protected function getExtensionUpdates() {
375  }
376 
384  }
385 
392  private function writeSchemaUpdateFile( $schemaUpdate = [] ) {
394  $this->updatesSkipped = [];
395 
396  foreach ( $updates as $funcList ) {
397  $func = $funcList[0];
398  $arg = $funcList[1];
399  $origParams = $funcList[2];
400  call_user_func_array( $func, $arg );
401  flush();
402  $this->updatesSkipped[] = $origParams;
403  }
404  }
405 
416  public function getSchemaVars() {
417  return []; // DB-type specific
418  }
419 
425  public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
427 
428  $this->db->setSchemaVars( $this->getSchemaVars() );
429 
430  $what = array_flip( $what );
431  $this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
432  if ( isset( $what['core'] ) ) {
433  $this->runUpdates( $this->getCoreUpdateList(), false );
434  }
435  if ( isset( $what['extensions'] ) ) {
436  $this->runUpdates( $this->getOldGlobalUpdates(), false );
437  $this->runUpdates( $this->getExtensionUpdates(), true );
438  }
439 
440  if ( isset( $what['stats'] ) ) {
441  $this->checkStats();
442  }
443 
444  $this->setAppliedUpdates( $wgVersion, $this->updates );
445 
446  if ( $this->fileHandle ) {
447  $this->skipSchema = false;
448  $this->writeSchemaUpdateFile();
449  $this->setAppliedUpdates( "$wgVersion-schema", $this->updatesSkipped );
450  }
451  }
452 
459  private function runUpdates( array $updates, $passSelf ) {
460  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
461 
462  $updatesDone = [];
463  $updatesSkipped = [];
464  foreach ( $updates as $params ) {
465  $origParams = $params;
466  $func = array_shift( $params );
467  if ( !is_array( $func ) && method_exists( $this, $func ) ) {
468  $func = [ $this, $func ];
469  } elseif ( $passSelf ) {
470  array_unshift( $params, $this );
471  }
472  $ret = call_user_func_array( $func, $params );
473  flush();
474  if ( $ret !== false ) {
475  $updatesDone[] = $origParams;
476  $lbFactory->waitForReplication();
477  } else {
478  $updatesSkipped[] = [ $func, $params, $origParams ];
479  }
480  }
481  $this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped );
482  $this->updates = array_merge( $this->updates, $updatesDone );
483  }
484 
489  protected function setAppliedUpdates( $version, $updates = [] ) {
490  $this->db->clearFlag( DBO_DDLMODE );
491  if ( !$this->canUseNewUpdatelog() ) {
492  return;
493  }
494  $key = "updatelist-$version-" . time() . self::$updateCounter;
495  self::$updateCounter++;
496  $this->db->insert( 'updatelog',
497  [ 'ul_key' => $key, 'ul_value' => serialize( $updates ) ],
498  __METHOD__ );
499  $this->db->setFlag( DBO_DDLMODE );
500  }
501 
509  public function updateRowExists( $key ) {
510  $row = $this->db->selectRow(
511  'updatelog',
512  # Bug 65813
513  '1 AS X',
514  [ 'ul_key' => $key ],
515  __METHOD__
516  );
517 
518  return (bool)$row;
519  }
520 
528  public function insertUpdateRow( $key, $val = null ) {
529  $this->db->clearFlag( DBO_DDLMODE );
530  $values = [ 'ul_key' => $key ];
531  if ( $val && $this->canUseNewUpdatelog() ) {
532  $values['ul_value'] = $val;
533  }
534  $this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
535  $this->db->setFlag( DBO_DDLMODE );
536  }
537 
546  protected function canUseNewUpdatelog() {
547  return $this->db->tableExists( 'updatelog', __METHOD__ ) &&
548  $this->db->fieldExists( 'updatelog', 'ul_value', __METHOD__ );
549  }
550 
559  protected function doTable( $name ) {
561 
562  // Don't bother to check $wgSharedTables if there isn't a shared database
563  // or the user actually also wants to do updates on the shared database.
564  if ( $wgSharedDB === null || $this->shared ) {
565  return true;
566  }
567 
568  if ( in_array( $name, $wgSharedTables ) ) {
569  $this->output( "...skipping update to shared table $name.\n" );
570  return false;
571  } else {
572  return true;
573  }
574  }
575 
584  protected function getOldGlobalUpdates() {
585  global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
586  $wgExtNewIndexes;
587 
588  $updates = [];
589 
590  foreach ( $wgExtNewTables as $tableRecord ) {
591  $updates[] = [
592  'addTable', $tableRecord[0], $tableRecord[1], true
593  ];
594  }
595 
596  foreach ( $wgExtNewFields as $fieldRecord ) {
597  $updates[] = [
598  'addField', $fieldRecord[0], $fieldRecord[1],
599  $fieldRecord[2], true
600  ];
601  }
602 
603  foreach ( $wgExtNewIndexes as $fieldRecord ) {
604  $updates[] = [
605  'addIndex', $fieldRecord[0], $fieldRecord[1],
606  $fieldRecord[2], true
607  ];
608  }
609 
610  foreach ( $wgExtModifiedFields as $fieldRecord ) {
611  $updates[] = [
612  'modifyField', $fieldRecord[0], $fieldRecord[1],
613  $fieldRecord[2], true
614  ];
615  }
616 
617  return $updates;
618  }
619 
628  abstract protected function getCoreUpdateList();
629 
635  public function copyFile( $filename ) {
636  $this->db->sourceFile(
637  $filename,
638  null,
639  null,
640  __METHOD__,
641  [ $this, 'appendLine' ]
642  );
643  }
644 
655  public function appendLine( $line ) {
656  $line = rtrim( $line ) . ";\n";
657  if ( fwrite( $this->fileHandle, $line ) === false ) {
658  throw new MWException( "trouble writing file" );
659  }
660 
661  return false;
662  }
663 
672  protected function applyPatch( $path, $isFullPath = false, $msg = null ) {
673  if ( $msg === null ) {
674  $msg = "Applying $path patch";
675  }
676  if ( $this->skipSchema ) {
677  $this->output( "...skipping schema change ($msg).\n" );
678 
679  return false;
680  }
681 
682  $this->output( "$msg ..." );
683 
684  if ( !$isFullPath ) {
685  $path = $this->patchPath( $this->db, $path );
686  }
687  if ( $this->fileHandle !== null ) {
688  $this->copyFile( $path );
689  } else {
690  $this->db->sourceFile( $path );
691  }
692  $this->output( "done.\n" );
693 
694  return true;
695  }
696 
706  public function patchPath( IDatabase $db, $patch ) {
707  global $IP;
708 
709  $dbType = $db->getType();
710  if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) {
711  return "$IP/maintenance/$dbType/archives/$patch";
712  } else {
713  return "$IP/maintenance/archives/$patch";
714  }
715  }
716 
725  protected function addTable( $name, $patch, $fullpath = false ) {
726  if ( !$this->doTable( $name ) ) {
727  return true;
728  }
729 
730  if ( $this->db->tableExists( $name, __METHOD__ ) ) {
731  $this->output( "...$name table already exists.\n" );
732  } else {
733  return $this->applyPatch( $patch, $fullpath, "Creating $name table" );
734  }
735 
736  return true;
737  }
738 
748  protected function addField( $table, $field, $patch, $fullpath = false ) {
749  if ( !$this->doTable( $table ) ) {
750  return true;
751  }
752 
753  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
754  $this->output( "...$table table does not exist, skipping new field patch.\n" );
755  } elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
756  $this->output( "...have $field field in $table table.\n" );
757  } else {
758  return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" );
759  }
760 
761  return true;
762  }
763 
773  protected function addIndex( $table, $index, $patch, $fullpath = false ) {
774  if ( !$this->doTable( $table ) ) {
775  return true;
776  }
777 
778  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
779  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
780  } elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
781  $this->output( "...index $index already set on $table table.\n" );
782  } else {
783  return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
784  }
785 
786  return true;
787  }
788 
798  protected function dropField( $table, $field, $patch, $fullpath = false ) {
799  if ( !$this->doTable( $table ) ) {
800  return true;
801  }
802 
803  if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) {
804  return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" );
805  } else {
806  $this->output( "...$table table does not contain $field field.\n" );
807  }
808 
809  return true;
810  }
811 
821  protected function dropIndex( $table, $index, $patch, $fullpath = false ) {
822  if ( !$this->doTable( $table ) ) {
823  return true;
824  }
825 
826  if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
827  return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" );
828  } else {
829  $this->output( "...$index key doesn't exist.\n" );
830  }
831 
832  return true;
833  }
834 
847  protected function renameIndex( $table, $oldIndex, $newIndex,
848  $skipBothIndexExistWarning, $patch, $fullpath = false
849  ) {
850  if ( !$this->doTable( $table ) ) {
851  return true;
852  }
853 
854  // First requirement: the table must exist
855  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
856  $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
857 
858  return true;
859  }
860 
861  // Second requirement: the new index must be missing
862  if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) {
863  $this->output( "...index $newIndex already set on $table table.\n" );
864  if ( !$skipBothIndexExistWarning &&
865  $this->db->indexExists( $table, $oldIndex, __METHOD__ )
866  ) {
867  $this->output( "...WARNING: $oldIndex still exists, despite it has " .
868  "been renamed into $newIndex (which also exists).\n" .
869  " $oldIndex should be manually removed if not needed anymore.\n" );
870  }
871 
872  return true;
873  }
874 
875  // Third requirement: the old index must exist
876  if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) {
877  $this->output( "...skipping: index $oldIndex doesn't exist.\n" );
878 
879  return true;
880  }
881 
882  // Requirements have been satisfied, patch can be applied
883  return $this->applyPatch(
884  $patch,
885  $fullpath,
886  "Renaming index $oldIndex into $newIndex to table $table"
887  );
888  }
889 
901  public function dropTable( $table, $patch = false, $fullpath = false ) {
902  if ( !$this->doTable( $table ) ) {
903  return true;
904  }
905 
906  if ( $this->db->tableExists( $table, __METHOD__ ) ) {
907  $msg = "Dropping table $table";
908 
909  if ( $patch === false ) {
910  $this->output( "$msg ..." );
911  $this->db->dropTable( $table, __METHOD__ );
912  $this->output( "done.\n" );
913  } else {
914  return $this->applyPatch( $patch, $fullpath, $msg );
915  }
916  } else {
917  $this->output( "...$table doesn't exist.\n" );
918  }
919 
920  return true;
921  }
922 
932  public function modifyField( $table, $field, $patch, $fullpath = false ) {
933  if ( !$this->doTable( $table ) ) {
934  return true;
935  }
936 
937  $updateKey = "$table-$field-$patch";
938  if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
939  $this->output( "...$table table does not exist, skipping modify field patch.\n" );
940  } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
941  $this->output( "...$field field does not exist in $table table, " .
942  "skipping modify field patch.\n" );
943  } elseif ( $this->updateRowExists( $updateKey ) ) {
944  $this->output( "...$field in table $table already modified by patch $patch.\n" );
945  } else {
946  $this->insertUpdateRow( $updateKey );
947 
948  return $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" );
949  }
950 
951  return true;
952  }
953 
959  public function setFileAccess() {
960  $repo = RepoGroup::singleton()->getLocalRepo();
961  $zonePath = $repo->getZonePath( 'temp' );
962  if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) {
963  // If the directory was never made, then it will have the right ACLs when it is made
964  $status = $repo->getBackend()->secure( [
965  'dir' => $zonePath,
966  'noAccess' => true,
967  'noListing' => true
968  ] );
969  if ( $status->isOK() ) {
970  $this->output( "Set the local repo temp zone container to be private.\n" );
971  } else {
972  $this->output( "Failed to set the local repo temp zone container to be private.\n" );
973  }
974  }
975  }
976 
980  public function purgeCache() {
982  # We can't guarantee that the user will be able to use TRUNCATE,
983  # but we know that DELETE is available to us
984  $this->output( "Purging caches..." );
985  $this->db->delete( 'objectcache', '*', __METHOD__ );
986  if ( $wgLocalisationCacheConf['manualRecache'] ) {
987  $this->rebuildLocalisationCache();
988  }
989  $blobStore = new MessageBlobStore();
990  $blobStore->clear();
991  $this->db->delete( 'module_deps', '*', __METHOD__ );
992  $this->output( "done.\n" );
993  }
994 
998  protected function checkStats() {
999  $this->output( "...site_stats is populated..." );
1000  $row = $this->db->selectRow( 'site_stats', '*', [ 'ss_row_id' => 1 ], __METHOD__ );
1001  if ( $row === false ) {
1002  $this->output( "data is missing! rebuilding...\n" );
1003  } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
1004  $this->output( "missing ss_total_pages, rebuilding...\n" );
1005  } else {
1006  $this->output( "done.\n" );
1007 
1008  return;
1009  }
1010  SiteStatsInit::doAllAndCommit( $this->db );
1011  }
1012 
1013  # Common updater functions
1014 
1018  protected function doActiveUsersInit() {
1019  $activeUsers = $this->db->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
1020  if ( $activeUsers == -1 ) {
1021  $activeUsers = $this->db->selectField( 'recentchanges',
1022  'COUNT( DISTINCT rc_user_text )',
1023  [ 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ], __METHOD__
1024  );
1025  $this->db->update( 'site_stats',
1026  [ 'ss_active_users' => intval( $activeUsers ) ],
1027  [ 'ss_row_id' => 1 ], __METHOD__, [ 'LIMIT' => 1 ]
1028  );
1029  }
1030  $this->output( "...ss_active_users user count set...\n" );
1031  }
1032 
1036  protected function doLogUsertextPopulation() {
1037  if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
1038  $this->output(
1039  "Populating log_user_text field, printing progress markers. For large\n" .
1040  "databases, you may want to hit Ctrl-C and do this manually with\n" .
1041  "maintenance/populateLogUsertext.php.\n"
1042  );
1043 
1044  $task = $this->maintenance->runChild( 'PopulateLogUsertext' );
1045  $task->execute();
1046  $this->output( "done.\n" );
1047  }
1048  }
1049 
1053  protected function doLogSearchPopulation() {
1054  if ( !$this->updateRowExists( 'populate log_search' ) ) {
1055  $this->output(
1056  "Populating log_search table, printing progress markers. For large\n" .
1057  "databases, you may want to hit Ctrl-C and do this manually with\n" .
1058  "maintenance/populateLogSearch.php.\n" );
1059 
1060  $task = $this->maintenance->runChild( 'PopulateLogSearch' );
1061  $task->execute();
1062  $this->output( "done.\n" );
1063  }
1064  }
1065 
1070  protected function doUpdateTranscacheField() {
1071  if ( $this->updateRowExists( 'convert transcache field' ) ) {
1072  $this->output( "...transcache tc_time already converted.\n" );
1073 
1074  return true;
1075  }
1076 
1077  return $this->applyPatch( 'patch-tc-timestamp.sql', false,
1078  "Converting tc_time from UNIX epoch to MediaWiki timestamp" );
1079  }
1080 
1084  protected function doCollationUpdate() {
1085  global $wgCategoryCollation;
1086  if ( $this->db->fieldExists( 'categorylinks', 'cl_collation', __METHOD__ ) ) {
1087  if ( $this->db->selectField(
1088  'categorylinks',
1089  'COUNT(*)',
1090  'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
1091  __METHOD__
1092  ) == 0
1093  ) {
1094  $this->output( "...collations up-to-date.\n" );
1095 
1096  return;
1097  }
1098 
1099  $this->output( "Updating category collations..." );
1100  $task = $this->maintenance->runChild( 'UpdateCollation' );
1101  $task->execute();
1102  $this->output( "...done.\n" );
1103  }
1104  }
1105 
1109  protected function doMigrateUserOptions() {
1110  if ( $this->db->tableExists( 'user_properties' ) ) {
1111  $cl = $this->maintenance->runChild( 'ConvertUserOptions', 'convertUserOptions.php' );
1112  $cl->execute();
1113  $this->output( "done.\n" );
1114  }
1115  }
1116 
1120  protected function doEnableProfiling() {
1122 
1123  if ( !$this->doTable( 'profiling' ) ) {
1124  return;
1125  }
1126 
1127  $profileToDb = false;
1128  if ( isset( $wgProfiler['output'] ) ) {
1129  $out = $wgProfiler['output'];
1130  if ( $out === 'db' ) {
1131  $profileToDb = true;
1132  } elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
1133  $profileToDb = true;
1134  }
1135  }
1136 
1137  if ( $profileToDb && !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
1138  $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
1139  }
1140  }
1141 
1145  protected function rebuildLocalisationCache() {
1149  $cl = $this->maintenance->runChild( 'RebuildLocalisationCache', 'rebuildLocalisationCache.php' );
1150  $this->output( "Rebuilding localisation cache...\n" );
1151  $cl->setForce();
1152  $cl->execute();
1153  $this->output( "done.\n" );
1154  }
1155 
1160  protected function disableContentHandlerUseDB() {
1161  global $wgContentHandlerUseDB;
1162 
1163  if ( $wgContentHandlerUseDB ) {
1164  $this->output( "Turning off Content Handler DB fields for this part of upgrade.\n" );
1165  $this->holdContentHandlerUseDB = $wgContentHandlerUseDB;
1166  $wgContentHandlerUseDB = false;
1167  }
1168  }
1169 
1173  protected function enableContentHandlerUseDB() {
1174  global $wgContentHandlerUseDB;
1175 
1176  if ( $this->holdContentHandlerUseDB ) {
1177  $this->output( "Content Handler DB fields should be usable now.\n" );
1178  $wgContentHandlerUseDB = $this->holdContentHandlerUseDB;
1179  }
1180  }
1181 }
This class generates message blobs for use by ResourceLoader modules.
getSchemaVars()
Get appropriate schema variables in the current database connection.
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:802
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)
$IP
Definition: WebStart.php:58
loadExtensions()
Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates ...
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:1936
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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.
patchPath(IDatabase $db, $patch)
Get the full path of a patch file.
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.
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 MediaWikiServices
Definition: injection.txt:23
$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.
setFlag($flag, $remember=self::REMEMBER_NOTHING)
Set a flag for this connection.
Definition: Database.php:581
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.
static newForDB(Database $db, $shared=false, $maintenance=null)
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
const DBO_DDLMODE
Definition: defines.php:13
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:380
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:1936
Fake maintenance wrapper, mostly used for the web installer/updater.
getDB()
Get a database connection to run updates.
global $wgCommandLineMode
Definition: Setup.php:495
dropExtensionIndex($tableName, $indexName, $sqlPath)
Drop an index from an extension table.
Database $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:572
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.
$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
$lbFactory
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)
__construct(Database &$db, $shared, Maintenance $maintenance=null)
Constructor.
$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:1046
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)
serialize()
Definition: ApiMessage.php:94
static getDBTypes()
Get a list of known DB types.
Definition: Installer.php:456
$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:2159
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:2491
modifyExtensionField($tableName, $fieldName, $sqlPath)
doCollationUpdate()
Update CategoryLinks collation.
getOldGlobalUpdates()
Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:34
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:300