7 if ( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is not a valid entry point\n";
12 require_once 'userDupes.inc';
14 require_once( "$IP/includes/Hooks.php" );
17 * @deprecated. Do not use, ever.
22 # For extensions only, should be populated via hooks
23 # $wgDBtype should be checked to specifiy the proper file
24 $wgExtNewTables = array(); // table, dir
25 $wgExtNewFields = array(); // table, column, dir
26 $wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
27 $wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
28 $wgExtNewIndexes = array(); // table, index, dir
29 $wgExtModifiedFields = array(); // table, index, dir
31 # Helper function: check if the given key is present in the updatelog table.
32 # Obviously, only use this for updates that occur after the updatelog table was
34 function update_row_exists( $key ) {
36 $row = $wgDatabase->selectRow(
39 array( 'ul_key' => $key ),
45 function modify_field( $table, $field, $patch, $fullpath = false ) {
47 if ( !$wgDatabase->tableExists( $table ) ) {
48 wfOut( "...$table table does not exist, skipping modify field patch\n" );
49 } elseif ( ! $wgDatabase->fieldExists( $table, $field ) ) {
50 wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
52 wfOut( "Modifying $field field of table $table..." );
54 $wgDatabase->sourceFile( $patch );
56 $wgDatabase->sourceFile( archive( $patch ) );
62 function drop_index_if_exists( $table, $index, $patch, $fullpath = false ) {
64 if ( $wgDatabase->indexExists( $table, $index ) ) {
65 wfOut( "Dropping $index from table $table... " );
67 $wgDatabase->sourceFile( $patch );
69 $wgDatabase->sourceFile( archive( $patch ) );
73 wfOut( "...$index doesn't exist.\n" );
77 function do_all_updates( $shared = false, $purge = true ) {
78 global $wgDatabase, $wgDBtype;
80 $updater = DatabaseUpdater::newForDb( $wgDatabase, $shared );
82 wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$updater ) );
84 $updater->doUpdates();
86 if ( !defined( 'MW_NO_SETUP' ) ) {
87 define( 'MW_NO_SETUP', true );
90 foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
91 call_user_func_array( array( new $maint, 'execute' ), array() );
94 if ( $wgDBtype === 'postgres' ) {
105 function archive( $name ) {
106 global $wgDBtype, $IP;
107 if ( file_exists( "$IP/maintenance/$wgDBtype/archives/$name" ) ) {
108 return "$IP/maintenance/$wgDBtype/archives/$name";
110 return "$IP/maintenance/archives/$name";
114 function do_interwiki_update() {
115 # Check that interwiki table exists; if it doesn't source it
116 global $wgDatabase, $IP;
117 if ( $wgDatabase->tableExists( "interwiki" ) ) {
118 wfOut( "...already have interwiki table\n" );
121 wfOut( "Creating interwiki table: " );
122 $wgDatabase->sourceFile( archive( "patch-interwiki.sql" ) );
124 wfOut( "Adding default interwiki definitions: " );
125 $wgDatabase->sourceFile( "$IP/maintenance/interwiki.sql" );
129 function do_index_update() {
130 # Check that proper indexes are in place
132 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
133 if ( !$meta->isMultipleKey() ) {
134 wfOut( "Updating indexes to 20031107: " );
135 $wgDatabase->sourceFile( archive( "patch-indexes.sql" ) );
139 wfOut( "...indexes seem up to 20031107 standards\n" );
143 function do_image_index_update() {
146 $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
147 if ( !$meta->isMultipleKey() ) {
148 wfOut( "Updating indexes to 20050912: " );
149 $wgDatabase->sourceFile( archive( "patch-mimesearch-indexes.sql" ) );
153 wfOut( "...indexes seem up to 20050912 standards\n" );
157 function do_image_name_unique_update() {
159 if ( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
160 wfOut( "...image primary key already set.\n" );
162 wfOut( "Making img_name the primary key... " );
163 $wgDatabase->sourceFile( archive( "patch-image_name_primary.sql" ) );
168 function do_watchlist_update() {
170 $fname = 'do_watchlist_update';
171 if ( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
172 wfOut( "...the watchlist table is already set up for email notification.\n" );
174 wfOut( "Adding wl_notificationtimestamp field for email notification management." );
175 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
176 $wgDatabase->sourceFile( archive( 'patch-email-notification.sql' ) );
179 # Check if we need to add talk page rows to the watchlist
180 $talk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
181 $nontalk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
182 if ( $talk != $nontalk ) {
183 wfOut( "Adding missing watchlist talk page rows... " );
186 $wgDatabase->insertSelect( 'watchlist', 'watchlist',
188 'wl_user' => 'wl_user',
189 'wl_namespace' => 'wl_namespace | 1',
190 'wl_title' => 'wl_title',
191 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
192 ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
195 wfOut( "...watchlist talk page rows already present\n" );
199 function do_copy_newtalk_to_watchlist() {
202 $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !',
203 $wgDatabase->tableName( 'user_newtalk' ) );
204 $num_newtalks = $wgDatabase->numRows( $res );
205 wfOut( "Now converting $num_newtalks user_newtalk entries to watchlist table entries ... \n" );
208 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
209 $wluser = $wgDatabase->fetchObject( $res );
210 if ( $wluser->user_id == 0 ) { # anonymous users ... have IP numbers as "names"
211 if ( $user->isIP( $wluser->user_ip ) ) { # do only if it really looks like an IP number (double checked)
212 $wgDatabase->replace( 'watchlist',
213 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
214 array( 'wl_user' => 0,
215 'wl_namespace' => NS_USER_TALK,
216 'wl_title' => $wluser->user_ip,
217 'wl_notificationtimestamp' => '19700101000000'
218 ), 'updaters.inc::do_watchlist_update2'
221 } else { # normal users ... have user_ids
222 $user->setID( $wluser->user_id );
223 $wgDatabase->replace( 'watchlist',
224 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
225 array( 'wl_user' => $user->getID(),
226 'wl_namespace' => NS_USER_TALK,
227 'wl_title' => $user->getName(),
228 'wl_notificationtimestamp' => '19700101000000'
229 ), 'updaters.inc::do_watchlist_update3'
237 * 1.4 betas were missing the 'binary' marker from logging.log_title,
238 * which causes a collation mismatch error on joins in MySQL 4.1.
240 function check_bin( $table, $field, $patchFile ) {
241 global $wgDatabase, $wgDBtype;
242 if ( $wgDBtype != 'mysql' )
244 $tableName = $wgDatabase->tableName( $table );
245 $res = $wgDatabase->query( "SELECT $field FROM $tableName LIMIT 0" );
246 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
248 if ( in_array( 'binary', $flags ) ) {
249 wfOut( "...$table table has correct $field encoding.\n" );
251 wfOut( "Fixing $field encoding on $table table... " );
252 $wgDatabase->sourceFile( archive( $patchFile ) );
257 function do_schema_restructuring() {
259 $fname = "do_schema_restructuring";
260 if ( $wgDatabase->tableExists( 'page' ) ) {
261 wfOut( "...page table already exists.\n" );
263 wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
264 wfOut( wfTimestamp( TS_DB ) );
265 wfOut( "......checking for duplicate entries.\n" );
267 list ( $cur, $old, $page, $revision, $text ) = $wgDatabase->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
269 $rows = $wgDatabase->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
270 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
272 if ( $wgDatabase->numRows( $rows ) > 0 ) {
273 wfOut( wfTimestamp( TS_DB ) );
274 wfOut( "......<b>Found duplicate entries</b>\n" );
275 wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
276 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
277 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
278 $duplicate[$row->cur_namespace] = array();
280 $duplicate[$row->cur_namespace][] = $row->cur_title;
281 wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
283 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
285 foreach ( $duplicate as $ns => $titles ) {
291 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
293 foreach ( $titles as $t ) {
295 $sql .= $wgDatabase->addQuotes( $t );
298 $sql .= ', ' . $wgDatabase->addQuotes( $t );
303 # By sorting descending, the most recent entry will be the first in the list.
304 # All following entries will be deleted by the next while-loop.
305 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
307 $rows = $wgDatabase->query( $sql, $fname );
309 $prev_title = $prev_namespace = false;
312 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
313 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
314 $deleteId[] = $row->cur_id;
316 $prev_title = $row->cur_title;
317 $prev_namespace = $row->cur_namespace;
319 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
320 $rows = $wgDatabase->query( $sql, $fname );
321 wfOut( wfTimestamp( TS_DB ) );
322 wfOut( "......<b>Deleted</b> " . $wgDatabase->affectedRows() . " records.\n" );
326 wfOut( wfTimestamp( TS_DB ) );
327 wfOut( "......Creating tables.\n" );
328 $wgDatabase->query( "CREATE TABLE $page (
329 page_id int(8) unsigned NOT NULL auto_increment,
330 page_namespace int NOT NULL,
331 page_title varchar(255) binary NOT NULL,
332 page_restrictions tinyblob NOT NULL,
333 page_counter bigint(20) unsigned NOT NULL default '0',
334 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
335 page_is_new tinyint(1) unsigned NOT NULL default '0',
336 page_random real unsigned NOT NULL,
337 page_touched char(14) binary NOT NULL default '',
338 page_latest int(8) unsigned NOT NULL,
339 page_len int(8) unsigned NOT NULL,
341 PRIMARY KEY page_id (page_id),
342 UNIQUE INDEX name_title (page_namespace,page_title),
345 ) ENGINE=InnoDB", $fname );
346 $wgDatabase->query( "CREATE TABLE $revision (
347 rev_id int(8) unsigned NOT NULL auto_increment,
348 rev_page int(8) unsigned NOT NULL,
349 rev_comment tinyblob NOT NULL,
350 rev_user int(5) unsigned NOT NULL default '0',
351 rev_user_text varchar(255) binary NOT NULL default '',
352 rev_timestamp char(14) binary NOT NULL default '',
353 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
354 rev_deleted tinyint(1) unsigned NOT NULL default '0',
355 rev_len int(8) unsigned,
356 rev_parent_id int(8) unsigned default NULL,
357 PRIMARY KEY rev_page_id (rev_page, rev_id),
358 UNIQUE INDEX rev_id (rev_id),
359 INDEX rev_timestamp (rev_timestamp),
360 INDEX page_timestamp (rev_page,rev_timestamp),
361 INDEX user_timestamp (rev_user,rev_timestamp),
362 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
363 ) ENGINE=InnoDB", $fname );
365 wfOut( wfTimestamp( TS_DB ) );
366 wfOut( "......Locking tables.\n" );
367 $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
369 $maxold = intval( $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname ) );
370 wfOut( wfTimestamp( TS_DB ) );
371 wfOut( "......maxold is {$maxold}\n" );
373 wfOut( wfTimestamp( TS_DB ) );
374 global $wgLegacySchemaConversion;
375 if ( $wgLegacySchemaConversion ) {
376 // Create HistoryBlobCurStub entries.
377 // Text will be pulled from the leftover 'cur' table at runtime.
378 wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
379 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
380 $cur_flags = "'object'";
382 // Copy all cur text in immediately: this may take longer but avoids
383 // having to keep an extra table around.
384 wfOut( "......Moving text from cur.\n" );
385 $cur_text = 'cur_text';
388 $wgDatabase->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
389 old_timestamp, old_minor_edit, old_flags)
390 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
391 FROM $cur", $fname );
393 wfOut( wfTimestamp( TS_DB ) );
394 wfOut( "......Setting up revision table.\n" );
395 $wgDatabase->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
397 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
398 old_timestamp, old_minor_edit
399 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
401 wfOut( wfTimestamp( TS_DB ) );
402 wfOut( "......Setting up page table.\n" );
403 $wgDatabase->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
404 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
405 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
406 cur_random, cur_touched, rev_id, LENGTH(cur_text)
408 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
410 wfOut( wfTimestamp( TS_DB ) );
411 wfOut( "......Unlocking tables.\n" );
412 $wgDatabase->query( "UNLOCK TABLES", $fname );
414 wfOut( wfTimestamp( TS_DB ) );
415 wfOut( "......Renaming old.\n" );
416 $wgDatabase->query( "ALTER TABLE $old RENAME TO $text", $fname );
418 wfOut( wfTimestamp( TS_DB ) );
419 wfOut( "...done.\n" );
423 function do_pagelinks_update() {
425 if ( $wgDatabase->tableExists( 'pagelinks' ) ) {
426 wfOut( "...already have pagelinks table.\n" );
428 wfOut( "Converting links and brokenlinks tables to pagelinks... " );
429 $wgDatabase->sourceFile( archive( 'patch-pagelinks.sql' ) );
433 global $wgCanonicalNamespaceNames;
434 foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
436 do_pagelinks_namespace( $ns );
442 function do_pagelinks_namespace( $namespace ) {
443 global $wgDatabase, $wgContLang;
445 $ns = intval( $namespace );
446 wfOut( "Cleaning up broken links for namespace $ns... " );
448 $pagelinks = $wgDatabase->tableName( 'pagelinks' );
449 $name = $wgContLang->getNsText( $ns );
450 $prefix = $wgDatabase->strencode( $name );
451 $likeprefix = str_replace( '_', '\\_', $prefix );
453 $sql = "UPDATE $pagelinks
454 SET pl_namespace=$ns,
455 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
457 AND pl_title LIKE '$likeprefix:%'";
459 $wgDatabase->query( $sql, 'do_pagelinks_namespace' );
463 function do_old_links_update() {
464 if( !defined( 'MW_NO_SETUP' ) ) {
465 define( 'MW_NO_SETUP', true );
467 require( "convertLinks.php" );
468 $cl = new ConvertLinks();
472 function fix_ancient_imagelinks() {
474 $info = $wgDatabase->fieldInfo( 'imagelinks', 'il_from' );
475 if ( $info && $info->type() === 'string' ) {
476 wfOut( "Fixing ancient broken imagelinks table.\n" );
477 wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
478 $wgDatabase->sourceFile( archive( 'patch-fix-il_from.sql' ) );
481 wfOut( "...il_from OK\n" );
485 function do_user_unique_update() {
487 $duper = new UserDupes( $wgDatabase );
488 if ( $duper->hasUniqueIndex() ) {
489 wfOut( "...already have unique user_name index.\n" );
491 if ( !$duper->clearDupes() ) {
492 wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
494 wfOut( "Adding unique index on user_name... " );
495 $wgDatabase->sourceFile( archive( 'patch-user_nameindex.sql' ) );
500 function do_user_groups_update() {
501 $fname = 'do_user_groups_update';
504 if ( $wgDatabase->tableExists( 'user_groups' ) ) {
505 wfOut( "...user_groups table already exists.\n" );
506 return do_user_groups_reformat();
509 wfOut( "Adding user_groups table... " );
510 $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) );
513 if ( !$wgDatabase->tableExists( 'user_rights' ) ) {
514 if ( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) {
515 wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
516 $wgDatabase->sourceFile( archive( 'patch-user_rights.sql' ) );
519 wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
520 wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
521 wfOut( "*** the user_groups table.\n" );
526 wfOut( "Converting user_rights table to user_groups... " );
527 $result = $wgDatabase->select( 'user_rights',
528 array( 'ur_user', 'ur_rights' ),
529 array( "ur_rights != ''" ),
532 while ( $row = $wgDatabase->fetchObject( $result ) ) {
533 $groups = array_unique(
535 explode( ',', $row->ur_rights ) ) );
537 foreach ( $groups as $group ) {
538 $wgDatabase->insert( 'user_groups',
540 'ug_user' => $row->ur_user,
541 'ug_group' => $group ),
548 function do_user_groups_reformat() {
549 # Check for bogus formats from previous 1.5 alpha code.
551 $info = $wgDatabase->fieldInfo( 'user_groups', 'ug_group' );
553 if ( $info->type() == 'int' ) {
554 $oldug = $wgDatabase->tableName( 'user_groups' );
555 $newug = $wgDatabase->tableName( 'user_groups_bogus' );
556 wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
557 $wgDatabase->query( "ALTER TABLE $oldug RENAME TO $newug" );
560 wfOut( "Re-adding fresh user_groups table... " );
561 $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) );
565 wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
566 wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
569 wfOut( "...user_groups is in current format.\n" );
574 function do_watchlist_null() {
575 # Make sure wl_notificationtimestamp can be NULL,
576 # and update old broken items.
578 $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
580 if ( !$info->nullable() ) {
581 wfOut( "Making wl_notificationtimestamp nullable... " );
582 $wgDatabase->sourceFile( archive( 'patch-watchlist-null.sql' ) );
585 wfOut( "...wl_notificationtimestamp is already nullable.\n" );
593 function do_page_random_update() {
596 wfOut( "Setting page_random to a random value on rows where it equals 0..." );
598 $page = $wgDatabase->tableName( 'page' );
599 $wgDatabase->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
600 $rows = $wgDatabase->affectedRows();
602 wfOut( "changed $rows rows\n" );
605 function do_templatelinks_update() {
607 $fname = 'do_templatelinks_update';
609 if ( $wgDatabase->tableExists( 'templatelinks' ) ) {
610 wfOut( "...templatelinks table already exists\n" );
613 wfOut( "Creating templatelinks table...\n" );
614 $wgDatabase->sourceFile( archive( 'patch-templatelinks.sql' ) );
615 wfOut( "Populating...\n" );
616 if ( wfGetLB()->getServerCount() > 1 ) {
617 // Slow, replication-friendly update
618 $res = $wgDatabase->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
619 array( 'pl_namespace' => NS_TEMPLATE ), $fname );
621 while ( $row = $wgDatabase->fetchObject( $res ) ) {
622 $count = ( $count + 1 ) % 100;
624 if ( function_exists( 'wfWaitForSlaves' ) ) {
625 wfWaitForSlaves( 10 );
630 $wgDatabase->insert( 'templatelinks',
632 'tl_from' => $row->pl_from,
633 'tl_namespace' => $row->pl_namespace,
634 'tl_title' => $row->pl_title,
641 $wgDatabase->insertSelect( 'templatelinks', 'pagelinks',
643 'tl_from' => 'pl_from',
644 'tl_namespace' => 'pl_namespace',
645 'tl_title' => 'pl_title'
651 wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
654 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
655 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
656 function do_rc_indices_update() {
658 wfOut( "Checking for additional recent changes indices...\n" );
661 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
662 'rc_user_text' => 'patch-rc_user_text-index.sql',
665 foreach ( $indexes as $index => $patch ) {
666 $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ );
668 wfOut( "...index `{$index}` not found; adding..." );
669 $wgDatabase->sourceFile( archive( $patch ) );
672 wfOut( "...index `{$index}` seems ok.\n" );
677 function index_has_field( $table, $index, $field ) {
679 wfOut( "Checking if $table index $index includes field $field...\n" );
680 $info = $wgDatabase->indexInfo( $table, $index, __METHOD__ );
682 foreach ( $info as $row ) {
683 if ( $row->Column_name == $field ) {
684 wfOut( "...index $index on table $table seems to be ok\n" );
689 wfOut( "...index $index on table $table has no field $field; adding\n" );
693 function do_backlinking_indices_update() {
695 wfOut( "Checking for backlinking indices...\n" );
696 if ( !index_has_field( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
697 !index_has_field( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
698 !index_has_field( 'imagelinks', 'il_to', 'il_from' ) )
700 $wgDatabase->sourceFile( archive( 'patch-backlinkindexes.sql' ) );
701 wfOut( "...backlinking indices updated\n" );
705 function do_categorylinks_indices_update() {
707 wfOut( "Checking for categorylinks indices...\n" );
708 if ( !index_has_field( 'categorylinks', 'cl_sortkey', 'cl_from' ) )
710 $wgDatabase->sourceFile( archive( 'patch-categorylinksindex.sql' ) );
711 wfOut( "...categorylinks indices updated\n" );
715 function do_filearchive_indices_update() {
717 wfOut( "Checking filearchive indices...\n" );
718 $info = $wgDatabase->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
721 $wgDatabase->sourceFile( archive( 'patch-filearchive-user-index.sql' ) );
722 wfOut( "...filearchive indices updated\n" );
726 function maybe_do_profiling_memory_update() {
728 if ( !$wgDatabase->tableExists( 'profiling' ) ) {
730 } elseif ( $wgDatabase->fieldExists( 'profiling', 'pf_memory' ) ) {
731 wfOut( "...profiling table has pf_memory field.\n" );
733 wfOut( "Adding pf_memory field to table profiling..." );
734 $wgDatabase->sourceFile( archive( 'patch-profiling-memory.sql' ) );
739 function do_stats_init() {
740 // Sometimes site_stats table is not properly populated.
742 wfOut( "\nChecking site_stats row..." );
743 $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
744 if ( $row === false ) {
745 wfOut( "data is missing! rebuilding...\n" );
746 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
747 wfOut( "missing ss_total_pages, rebuilding...\n" );
752 SiteStatsInit::doAllAndCommit( false );
755 function do_active_users_init() {
757 $activeUsers = $wgDatabase->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
758 if ( $activeUsers == -1 ) {
759 $activeUsers = $wgDatabase->selectField( 'recentchanges',
760 'COUNT( DISTINCT rc_user_text )',
761 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
763 $wgDatabase->update( 'site_stats',
764 array( 'ss_active_users' => intval( $activeUsers ) ),
765 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
768 wfOut( "...ss_active_users user count set...\n" );
771 function purge_cache() {
773 # We can't guarantee that the user will be able to use TRUNCATE,
774 # but we know that DELETE is available to us
775 wfOut( "Purging caches..." );
776 $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
781 * Adding page_restrictions table, obsoleting page.page_restrictions.
782 * Migrating old restrictions to new table
783 * -- Andrew Garrett, January 2007.
785 function do_restrictions_update() {
788 if ( $wgDatabase->tableExists( 'page_restrictions' ) ) {
789 wfOut( "...page_restrictions table already exists.\n" );
791 wfOut( "Creating page_restrictions table..." );
792 $wgDatabase->sourceFile( archive( 'patch-page_restrictions.sql' ) );
793 $wgDatabase->sourceFile( archive( 'patch-page_restrictions_sortkey.sql' ) );
796 wfOut( "Migrating old restrictions to new table...\n" );
797 require_once( 'updateRestrictions.php' );
798 $task = new UpdateRestrictions();
803 function do_category_population() {
804 if ( update_row_exists( 'populate category' ) ) {
805 wfOut( "...category table already populated.\n" );
808 require_once( 'populateCategory.php' );
810 "Populating category table, printing progress markers. " .
811 "For large databases, you\n" .
812 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
813 "populateCategory.php.\n"
815 $task = new PopulateCategory();
817 wfOut( "Done populating category table.\n" );
820 function do_populate_parent_id() {
821 if ( update_row_exists( 'populate rev_parent_id' ) ) {
822 wfOut( "...rev_parent_id column already populated.\n" );
825 require_once( 'populateParentId.php' );
826 $task = new PopulateParentId();
830 function do_populate_rev_len() {
831 if ( update_row_exists( 'populate rev_len' ) ) {
832 wfOut( "...rev_len column already populated.\n" );
835 require_once( 'populateRevisionLength.php' );
836 $task = new PopulateRevisionLength();
840 function do_collation_update() {
841 global $wgDatabase, $wgCollationVersion;
842 if ( $wgDatabase->selectField(
845 'cl_collation != ' . $wgDatabase->addQuotes( $wgCollationVersion ),
848 wfOut( "...collations up-to-date.\n" );
851 require_once( 'updateCollation.php' );
852 $task = new UpdateCollation();
856 function sqlite_initial_indexes() {
858 // initial-indexes.sql fails if the indexes are already present, so we perform a quick check if our database is newer.
859 if ( update_row_exists( 'initial_indexes' ) || $wgDatabase->indexExists( 'user', 'user_name' ) ) {
860 wfOut( "...have initial indexes\n" );
863 wfOut( "Adding initial indexes..." );
864 $wgDatabase->sourceFile( archive( 'initial-indexes.sql' ) );
868 function sqlite_setup_searchindex() {
870 $module = $wgDatabase->getFulltextSearchModule();
871 $fts3tTable = update_row_exists( 'fts3' );
872 if ( $fts3tTable && !$module ) {
873 wfOut( '...PHP is missing FTS3 support, downgrading tables...' );
874 $wgDatabase->sourceFile( archive( 'searchindex-no-fts.sql' ) );
876 } elseif ( !$fts3tTable && $module == 'FTS3' ) {
877 wfOut( '...adding FTS3 search capabilities...' );
878 $wgDatabase->sourceFile( archive( 'searchindex-fts3.sql' ) );
881 wfOut( "...fulltext search table appears to be in order.\n" );
885 function do_unique_pl_tl_il() {
887 $info = $wgDatabase->indexInfo( 'pagelinks', 'pl_namespace' );
888 if ( is_array( $info ) && !$info[0]->Non_unique ) {
889 wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
891 wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
892 $wgDatabase->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) );
897 function do_log_search_population() {
898 if ( update_row_exists( 'populate log_search' ) ) {
899 wfOut( "...log_search table already populated.\n" );
902 require_once( 'populateLogSearch.php' );
904 "Populating log_search table, printing progress markers. For large\n" .
905 "databases, you may want to hit Ctrl-C and do this manually with\n" .
906 "maintenance/populateLogSearch.php.\n" );
907 $task = new PopulateLogSearch();
909 wfOut( "Done populating log_search table.\n" );
912 function rename_eu_wiki_id() {
914 if ( $wgDatabase->fieldExists( 'external_user', 'eu_local_id' ) ) {
915 wfOut( "...eu_wiki_id already renamed to eu_local_id.\n" );
918 wfOut( "Renaming eu_wiki_id -> eu_local_id... " );
919 $wgDatabase->sourceFile( archive( 'patch-eu_local_id.sql' ) );
923 function do_update_transcache_field() {
925 if ( update_row_exists( 'convert transcache field' ) ) {
926 wfOut( "...transcache tc_time already converted.\n" );
929 wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
930 $wgDatabase->sourceFile( archive( 'patch-tc-timestamp.sql' ) );
935 function do_update_mime_minor_field() {
936 if ( update_row_exists( 'mime_minor_length' ) ) {
937 wfOut( "...*_mime_minor fields are already long enough.\n" );
940 wfOut( "Altering all *_mime_minor fields to 100 bytes in size ... " );
941 $wgDatabase->sourceFile( archive( 'patch-mime_minor_length.sql' ) );