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 wfDeprecated( __FUNCTION__ );
107 return DatabaseBase::patchPath( $name );
110 function do_interwiki_update() {
111 # Check that interwiki table exists; if it doesn't source it
112 global $wgDatabase, $IP;
113 if ( $wgDatabase->tableExists( "interwiki" ) ) {
114 wfOut( "...already have interwiki table\n" );
117 wfOut( "Creating interwiki table: " );
118 $wgDatabase->sourceFile( archive( "patch-interwiki.sql" ) );
120 wfOut( "Adding default interwiki definitions: " );
121 $wgDatabase->sourceFile( "$IP/maintenance/interwiki.sql" );
125 function do_index_update() {
126 # Check that proper indexes are in place
128 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
129 if ( !$meta->isMultipleKey() ) {
130 wfOut( "Updating indexes to 20031107: " );
131 $wgDatabase->sourceFile( archive( "patch-indexes.sql" ) );
135 wfOut( "...indexes seem up to 20031107 standards\n" );
139 function do_image_index_update() {
142 $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
143 if ( !$meta->isMultipleKey() ) {
144 wfOut( "Updating indexes to 20050912: " );
145 $wgDatabase->sourceFile( archive( "patch-mimesearch-indexes.sql" ) );
149 wfOut( "...indexes seem up to 20050912 standards\n" );
153 function do_image_name_unique_update() {
155 if ( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
156 wfOut( "...image primary key already set.\n" );
158 wfOut( "Making img_name the primary key... " );
159 $wgDatabase->sourceFile( archive( "patch-image_name_primary.sql" ) );
164 function do_watchlist_update() {
166 $fname = 'do_watchlist_update';
167 if ( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
168 wfOut( "...the watchlist table is already set up for email notification.\n" );
170 wfOut( "Adding wl_notificationtimestamp field for email notification management." );
171 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
172 $wgDatabase->sourceFile( archive( 'patch-email-notification.sql' ) );
175 # Check if we need to add talk page rows to the watchlist
176 $talk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
177 $nontalk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
178 if ( $talk != $nontalk ) {
179 wfOut( "Adding missing watchlist talk page rows... " );
182 $wgDatabase->insertSelect( 'watchlist', 'watchlist',
184 'wl_user' => 'wl_user',
185 'wl_namespace' => 'wl_namespace | 1',
186 'wl_title' => 'wl_title',
187 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
188 ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
191 wfOut( "...watchlist talk page rows already present\n" );
195 function do_copy_newtalk_to_watchlist() {
198 $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !',
199 $wgDatabase->tableName( 'user_newtalk' ) );
200 $num_newtalks = $wgDatabase->numRows( $res );
201 wfOut( "Now converting $num_newtalks user_newtalk entries to watchlist table entries ... \n" );
204 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
205 $wluser = $wgDatabase->fetchObject( $res );
206 if ( $wluser->user_id == 0 ) { # anonymous users ... have IP numbers as "names"
207 if ( $user->isIP( $wluser->user_ip ) ) { # do only if it really looks like an IP number (double checked)
208 $wgDatabase->replace( 'watchlist',
209 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
210 array( 'wl_user' => 0,
211 'wl_namespace' => NS_USER_TALK,
212 'wl_title' => $wluser->user_ip,
213 'wl_notificationtimestamp' => '19700101000000'
214 ), 'updaters.inc::do_watchlist_update2'
217 } else { # normal users ... have user_ids
218 $user->setID( $wluser->user_id );
219 $wgDatabase->replace( 'watchlist',
220 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
221 array( 'wl_user' => $user->getID(),
222 'wl_namespace' => NS_USER_TALK,
223 'wl_title' => $user->getName(),
224 'wl_notificationtimestamp' => '19700101000000'
225 ), 'updaters.inc::do_watchlist_update3'
233 * 1.4 betas were missing the 'binary' marker from logging.log_title,
234 * which causes a collation mismatch error on joins in MySQL 4.1.
236 function check_bin( $table, $field, $patchFile ) {
237 global $wgDatabase, $wgDBtype;
238 if ( $wgDBtype != 'mysql' )
240 $tableName = $wgDatabase->tableName( $table );
241 $res = $wgDatabase->query( "SELECT $field FROM $tableName LIMIT 0" );
242 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
244 if ( in_array( 'binary', $flags ) ) {
245 wfOut( "...$table table has correct $field encoding.\n" );
247 wfOut( "Fixing $field encoding on $table table... " );
248 $wgDatabase->sourceFile( archive( $patchFile ) );
253 function do_schema_restructuring() {
255 $fname = "do_schema_restructuring";
256 if ( $wgDatabase->tableExists( 'page' ) ) {
257 wfOut( "...page table already exists.\n" );
259 wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
260 wfOut( wfTimestamp( TS_DB ) );
261 wfOut( "......checking for duplicate entries.\n" );
263 list ( $cur, $old, $page, $revision, $text ) = $wgDatabase->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
265 $rows = $wgDatabase->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
266 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
268 if ( $wgDatabase->numRows( $rows ) > 0 ) {
269 wfOut( wfTimestamp( TS_DB ) );
270 wfOut( "......<b>Found duplicate entries</b>\n" );
271 wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
272 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
273 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
274 $duplicate[$row->cur_namespace] = array();
276 $duplicate[$row->cur_namespace][] = $row->cur_title;
277 wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
279 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
281 foreach ( $duplicate as $ns => $titles ) {
287 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
289 foreach ( $titles as $t ) {
291 $sql .= $wgDatabase->addQuotes( $t );
294 $sql .= ', ' . $wgDatabase->addQuotes( $t );
299 # By sorting descending, the most recent entry will be the first in the list.
300 # All following entries will be deleted by the next while-loop.
301 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
303 $rows = $wgDatabase->query( $sql, $fname );
305 $prev_title = $prev_namespace = false;
308 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
309 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
310 $deleteId[] = $row->cur_id;
312 $prev_title = $row->cur_title;
313 $prev_namespace = $row->cur_namespace;
315 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
316 $rows = $wgDatabase->query( $sql, $fname );
317 wfOut( wfTimestamp( TS_DB ) );
318 wfOut( "......<b>Deleted</b> " . $wgDatabase->affectedRows() . " records.\n" );
322 wfOut( wfTimestamp( TS_DB ) );
323 wfOut( "......Creating tables.\n" );
324 $wgDatabase->query( "CREATE TABLE $page (
325 page_id int(8) unsigned NOT NULL auto_increment,
326 page_namespace int NOT NULL,
327 page_title varchar(255) binary NOT NULL,
328 page_restrictions tinyblob NOT NULL,
329 page_counter bigint(20) unsigned NOT NULL default '0',
330 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
331 page_is_new tinyint(1) unsigned NOT NULL default '0',
332 page_random real unsigned NOT NULL,
333 page_touched char(14) binary NOT NULL default '',
334 page_latest int(8) unsigned NOT NULL,
335 page_len int(8) unsigned NOT NULL,
337 PRIMARY KEY page_id (page_id),
338 UNIQUE INDEX name_title (page_namespace,page_title),
341 ) ENGINE=InnoDB", $fname );
342 $wgDatabase->query( "CREATE TABLE $revision (
343 rev_id int(8) unsigned NOT NULL auto_increment,
344 rev_page int(8) unsigned NOT NULL,
345 rev_comment tinyblob NOT NULL,
346 rev_user int(5) unsigned NOT NULL default '0',
347 rev_user_text varchar(255) binary NOT NULL default '',
348 rev_timestamp char(14) binary NOT NULL default '',
349 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
350 rev_deleted tinyint(1) unsigned NOT NULL default '0',
351 rev_len int(8) unsigned,
352 rev_parent_id int(8) unsigned default NULL,
353 PRIMARY KEY rev_page_id (rev_page, rev_id),
354 UNIQUE INDEX rev_id (rev_id),
355 INDEX rev_timestamp (rev_timestamp),
356 INDEX page_timestamp (rev_page,rev_timestamp),
357 INDEX user_timestamp (rev_user,rev_timestamp),
358 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
359 ) ENGINE=InnoDB", $fname );
361 wfOut( wfTimestamp( TS_DB ) );
362 wfOut( "......Locking tables.\n" );
363 $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
365 $maxold = intval( $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname ) );
366 wfOut( wfTimestamp( TS_DB ) );
367 wfOut( "......maxold is {$maxold}\n" );
369 wfOut( wfTimestamp( TS_DB ) );
370 global $wgLegacySchemaConversion;
371 if ( $wgLegacySchemaConversion ) {
372 // Create HistoryBlobCurStub entries.
373 // Text will be pulled from the leftover 'cur' table at runtime.
374 wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
375 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
376 $cur_flags = "'object'";
378 // Copy all cur text in immediately: this may take longer but avoids
379 // having to keep an extra table around.
380 wfOut( "......Moving text from cur.\n" );
381 $cur_text = 'cur_text';
384 $wgDatabase->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
385 old_timestamp, old_minor_edit, old_flags)
386 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
387 FROM $cur", $fname );
389 wfOut( wfTimestamp( TS_DB ) );
390 wfOut( "......Setting up revision table.\n" );
391 $wgDatabase->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
393 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
394 old_timestamp, old_minor_edit
395 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
397 wfOut( wfTimestamp( TS_DB ) );
398 wfOut( "......Setting up page table.\n" );
399 $wgDatabase->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
400 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
401 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
402 cur_random, cur_touched, rev_id, LENGTH(cur_text)
404 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
406 wfOut( wfTimestamp( TS_DB ) );
407 wfOut( "......Unlocking tables.\n" );
408 $wgDatabase->query( "UNLOCK TABLES", $fname );
410 wfOut( wfTimestamp( TS_DB ) );
411 wfOut( "......Renaming old.\n" );
412 $wgDatabase->query( "ALTER TABLE $old RENAME TO $text", $fname );
414 wfOut( wfTimestamp( TS_DB ) );
415 wfOut( "...done.\n" );
419 function do_pagelinks_update() {
421 if ( $wgDatabase->tableExists( 'pagelinks' ) ) {
422 wfOut( "...already have pagelinks table.\n" );
424 wfOut( "Converting links and brokenlinks tables to pagelinks... " );
425 $wgDatabase->sourceFile( archive( 'patch-pagelinks.sql' ) );
429 global $wgCanonicalNamespaceNames;
430 foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
432 do_pagelinks_namespace( $ns );
438 function do_pagelinks_namespace( $namespace ) {
439 global $wgDatabase, $wgContLang;
441 $ns = intval( $namespace );
442 wfOut( "Cleaning up broken links for namespace $ns... " );
444 $pagelinks = $wgDatabase->tableName( 'pagelinks' );
445 $name = $wgContLang->getNsText( $ns );
446 $prefix = $wgDatabase->strencode( $name );
447 $likeprefix = str_replace( '_', '\\_', $prefix );
449 $sql = "UPDATE $pagelinks
450 SET pl_namespace=$ns,
451 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
453 AND pl_title LIKE '$likeprefix:%'";
455 $wgDatabase->query( $sql, 'do_pagelinks_namespace' );
459 function do_old_links_update() {
460 if( !defined( 'MW_NO_SETUP' ) ) {
461 define( 'MW_NO_SETUP', true );
463 require( "convertLinks.php" );
464 $cl = new ConvertLinks();
468 function fix_ancient_imagelinks() {
470 $info = $wgDatabase->fieldInfo( 'imagelinks', 'il_from' );
471 if ( $info && $info->type() === 'string' ) {
472 wfOut( "Fixing ancient broken imagelinks table.\n" );
473 wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
474 $wgDatabase->sourceFile( archive( 'patch-fix-il_from.sql' ) );
477 wfOut( "...il_from OK\n" );
481 function do_user_unique_update() {
483 $duper = new UserDupes( $wgDatabase );
484 if ( $duper->hasUniqueIndex() ) {
485 wfOut( "...already have unique user_name index.\n" );
487 if ( !$duper->clearDupes() ) {
488 wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
490 wfOut( "Adding unique index on user_name... " );
491 $wgDatabase->sourceFile( archive( 'patch-user_nameindex.sql' ) );
496 function do_user_groups_update() {
497 $fname = 'do_user_groups_update';
500 if ( $wgDatabase->tableExists( 'user_groups' ) ) {
501 wfOut( "...user_groups table already exists.\n" );
502 return do_user_groups_reformat();
505 wfOut( "Adding user_groups table... " );
506 $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) );
509 if ( !$wgDatabase->tableExists( 'user_rights' ) ) {
510 if ( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) {
511 wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
512 $wgDatabase->sourceFile( archive( 'patch-user_rights.sql' ) );
515 wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
516 wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
517 wfOut( "*** the user_groups table.\n" );
522 wfOut( "Converting user_rights table to user_groups... " );
523 $result = $wgDatabase->select( 'user_rights',
524 array( 'ur_user', 'ur_rights' ),
525 array( "ur_rights != ''" ),
528 while ( $row = $wgDatabase->fetchObject( $result ) ) {
529 $groups = array_unique(
531 explode( ',', $row->ur_rights ) ) );
533 foreach ( $groups as $group ) {
534 $wgDatabase->insert( 'user_groups',
536 'ug_user' => $row->ur_user,
537 'ug_group' => $group ),
544 function do_user_groups_reformat() {
545 # Check for bogus formats from previous 1.5 alpha code.
547 $info = $wgDatabase->fieldInfo( 'user_groups', 'ug_group' );
549 if ( $info->type() == 'int' ) {
550 $oldug = $wgDatabase->tableName( 'user_groups' );
551 $newug = $wgDatabase->tableName( 'user_groups_bogus' );
552 wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
553 $wgDatabase->query( "ALTER TABLE $oldug RENAME TO $newug" );
556 wfOut( "Re-adding fresh user_groups table... " );
557 $wgDatabase->sourceFile( archive( 'patch-user_groups.sql' ) );
561 wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
562 wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
565 wfOut( "...user_groups is in current format.\n" );
570 function do_watchlist_null() {
571 # Make sure wl_notificationtimestamp can be NULL,
572 # and update old broken items.
574 $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
576 if ( !$info->nullable() ) {
577 wfOut( "Making wl_notificationtimestamp nullable... " );
578 $wgDatabase->sourceFile( archive( 'patch-watchlist-null.sql' ) );
581 wfOut( "...wl_notificationtimestamp is already nullable.\n" );
589 function do_page_random_update() {
592 wfOut( "Setting page_random to a random value on rows where it equals 0..." );
594 $page = $wgDatabase->tableName( 'page' );
595 $wgDatabase->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
596 $rows = $wgDatabase->affectedRows();
598 wfOut( "changed $rows rows\n" );
601 function do_templatelinks_update() {
603 $fname = 'do_templatelinks_update';
605 if ( $wgDatabase->tableExists( 'templatelinks' ) ) {
606 wfOut( "...templatelinks table already exists\n" );
609 wfOut( "Creating templatelinks table...\n" );
610 $wgDatabase->sourceFile( archive( 'patch-templatelinks.sql' ) );
611 wfOut( "Populating...\n" );
612 if ( wfGetLB()->getServerCount() > 1 ) {
613 // Slow, replication-friendly update
614 $res = $wgDatabase->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
615 array( 'pl_namespace' => NS_TEMPLATE ), $fname );
617 while ( $row = $wgDatabase->fetchObject( $res ) ) {
618 $count = ( $count + 1 ) % 100;
620 if ( function_exists( 'wfWaitForSlaves' ) ) {
621 wfWaitForSlaves( 10 );
626 $wgDatabase->insert( 'templatelinks',
628 'tl_from' => $row->pl_from,
629 'tl_namespace' => $row->pl_namespace,
630 'tl_title' => $row->pl_title,
637 $wgDatabase->insertSelect( 'templatelinks', 'pagelinks',
639 'tl_from' => 'pl_from',
640 'tl_namespace' => 'pl_namespace',
641 'tl_title' => 'pl_title'
647 wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
650 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
651 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
652 function do_rc_indices_update() {
654 wfOut( "Checking for additional recent changes indices...\n" );
657 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
658 'rc_user_text' => 'patch-rc_user_text-index.sql',
661 foreach ( $indexes as $index => $patch ) {
662 $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ );
664 wfOut( "...index `{$index}` not found; adding..." );
665 $wgDatabase->sourceFile( archive( $patch ) );
668 wfOut( "...index `{$index}` seems ok.\n" );
673 function index_has_field( $table, $index, $field ) {
675 wfOut( "Checking if $table index $index includes field $field...\n" );
676 $info = $wgDatabase->indexInfo( $table, $index, __METHOD__ );
678 foreach ( $info as $row ) {
679 if ( $row->Column_name == $field ) {
680 wfOut( "...index $index on table $table seems to be ok\n" );
685 wfOut( "...index $index on table $table has no field $field; adding\n" );
689 function do_backlinking_indices_update() {
691 wfOut( "Checking for backlinking indices...\n" );
692 if ( !index_has_field( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
693 !index_has_field( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
694 !index_has_field( 'imagelinks', 'il_to', 'il_from' ) )
696 $wgDatabase->sourceFile( archive( 'patch-backlinkindexes.sql' ) );
697 wfOut( "...backlinking indices updated\n" );
701 function do_categorylinks_indices_update() {
703 wfOut( "Checking for categorylinks indices...\n" );
704 if ( !index_has_field( 'categorylinks', 'cl_sortkey', 'cl_from' ) )
706 $wgDatabase->sourceFile( archive( 'patch-categorylinksindex.sql' ) );
707 wfOut( "...categorylinks indices updated\n" );
711 function do_filearchive_indices_update() {
713 wfOut( "Checking filearchive indices...\n" );
714 $info = $wgDatabase->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
717 $wgDatabase->sourceFile( archive( 'patch-filearchive-user-index.sql' ) );
718 wfOut( "...filearchive indices updated\n" );
722 function maybe_do_profiling_memory_update() {
724 if ( !$wgDatabase->tableExists( 'profiling' ) ) {
726 } elseif ( $wgDatabase->fieldExists( 'profiling', 'pf_memory' ) ) {
727 wfOut( "...profiling table has pf_memory field.\n" );
729 wfOut( "Adding pf_memory field to table profiling..." );
730 $wgDatabase->sourceFile( archive( 'patch-profiling-memory.sql' ) );
735 function do_stats_init() {
736 // Sometimes site_stats table is not properly populated.
738 wfOut( "\nChecking site_stats row..." );
739 $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
740 if ( $row === false ) {
741 wfOut( "data is missing! rebuilding...\n" );
742 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
743 wfOut( "missing ss_total_pages, rebuilding...\n" );
748 SiteStatsInit::doAllAndCommit( false );
751 function do_active_users_init() {
753 $activeUsers = $wgDatabase->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
754 if ( $activeUsers == -1 ) {
755 $activeUsers = $wgDatabase->selectField( 'recentchanges',
756 'COUNT( DISTINCT rc_user_text )',
757 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
759 $wgDatabase->update( 'site_stats',
760 array( 'ss_active_users' => intval( $activeUsers ) ),
761 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
764 wfOut( "...ss_active_users user count set...\n" );
767 function purge_cache() {
769 # We can't guarantee that the user will be able to use TRUNCATE,
770 # but we know that DELETE is available to us
771 wfOut( "Purging caches..." );
772 $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
777 * Adding page_restrictions table, obsoleting page.page_restrictions.
778 * Migrating old restrictions to new table
779 * -- Andrew Garrett, January 2007.
781 function do_restrictions_update() {
784 if ( $wgDatabase->tableExists( 'page_restrictions' ) ) {
785 wfOut( "...page_restrictions table already exists.\n" );
787 wfOut( "Creating page_restrictions table..." );
788 $wgDatabase->sourceFile( archive( 'patch-page_restrictions.sql' ) );
789 $wgDatabase->sourceFile( archive( 'patch-page_restrictions_sortkey.sql' ) );
792 wfOut( "Migrating old restrictions to new table...\n" );
793 require_once( 'updateRestrictions.php' );
794 $task = new UpdateRestrictions();
799 function do_category_population() {
800 if ( update_row_exists( 'populate category' ) ) {
801 wfOut( "...category table already populated.\n" );
804 require_once( 'populateCategory.php' );
806 "Populating category table, printing progress markers. " .
807 "For large databases, you\n" .
808 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
809 "populateCategory.php.\n"
811 $task = new PopulateCategory();
813 wfOut( "Done populating category table.\n" );
816 function do_populate_parent_id() {
817 if ( update_row_exists( 'populate rev_parent_id' ) ) {
818 wfOut( "...rev_parent_id column already populated.\n" );
821 require_once( 'populateParentId.php' );
822 $task = new PopulateParentId();
826 function do_populate_rev_len() {
827 if ( update_row_exists( 'populate rev_len' ) ) {
828 wfOut( "...rev_len column already populated.\n" );
831 require_once( 'populateRevisionLength.php' );
832 $task = new PopulateRevisionLength();
836 function do_collation_update() {
837 global $wgDatabase, $wgCollationVersion;
838 if ( $wgDatabase->selectField(
841 'cl_collation != ' . $wgDatabase->addQuotes( $wgCollationVersion ),
844 wfOut( "...collations up-to-date.\n" );
847 require_once( 'updateCollation.php' );
848 $task = new UpdateCollation();
852 function sqlite_initial_indexes() {
854 // initial-indexes.sql fails if the indexes are already present, so we perform a quick check if our database is newer.
855 if ( update_row_exists( 'initial_indexes' ) || $wgDatabase->indexExists( 'user', 'user_name' ) ) {
856 wfOut( "...have initial indexes\n" );
859 wfOut( "Adding initial indexes..." );
860 $wgDatabase->sourceFile( archive( 'initial-indexes.sql' ) );
864 function sqlite_setup_searchindex() {
866 $module = $wgDatabase->getFulltextSearchModule();
867 $fts3tTable = update_row_exists( 'fts3' );
868 if ( $fts3tTable && !$module ) {
869 wfOut( '...PHP is missing FTS3 support, downgrading tables...' );
870 $wgDatabase->sourceFile( archive( 'searchindex-no-fts.sql' ) );
872 } elseif ( !$fts3tTable && $module == 'FTS3' ) {
873 wfOut( '...adding FTS3 search capabilities...' );
874 $wgDatabase->sourceFile( archive( 'searchindex-fts3.sql' ) );
877 wfOut( "...fulltext search table appears to be in order.\n" );
881 function do_unique_pl_tl_il() {
883 $info = $wgDatabase->indexInfo( 'pagelinks', 'pl_namespace' );
884 if ( is_array( $info ) && !$info[0]->Non_unique ) {
885 wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
887 wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
888 $wgDatabase->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) );
893 function do_log_search_population() {
894 if ( update_row_exists( 'populate log_search' ) ) {
895 wfOut( "...log_search table already populated.\n" );
898 require_once( 'populateLogSearch.php' );
900 "Populating log_search table, printing progress markers. For large\n" .
901 "databases, you may want to hit Ctrl-C and do this manually with\n" .
902 "maintenance/populateLogSearch.php.\n" );
903 $task = new PopulateLogSearch();
905 wfOut( "Done populating log_search table.\n" );
908 function rename_eu_wiki_id() {
910 if ( $wgDatabase->fieldExists( 'external_user', 'eu_local_id' ) ) {
911 wfOut( "...eu_wiki_id already renamed to eu_local_id.\n" );
914 wfOut( "Renaming eu_wiki_id -> eu_local_id... " );
915 $wgDatabase->sourceFile( archive( 'patch-eu_local_id.sql' ) );
919 function do_update_transcache_field() {
921 if ( update_row_exists( 'convert transcache field' ) ) {
922 wfOut( "...transcache tc_time already converted.\n" );
925 wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
926 $wgDatabase->sourceFile( archive( 'patch-tc-timestamp.sql' ) );
931 function do_update_mime_minor_field() {
932 if ( update_row_exists( 'mime_minor_length' ) ) {
933 wfOut( "...*_mime_minor fields are already long enough.\n" );
936 wfOut( "Altering all *_mime_minor fields to 100 bytes in size ... " );
937 $wgDatabase->sourceFile( archive( 'patch-mime_minor_length.sql' ) );