7 if ( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is not a valid entry point\n";
12 function modify_field( $table, $field, $patch, $fullpath = false ) {
13 $dbw = wfGetDB( DB_MASTER );
14 if ( !$dbw->tableExists( $table ) ) {
15 wfOut( "...$table table does not exist, skipping modify field patch\n" );
16 } elseif ( !$dbw->fieldExists( $table, $field ) ) {
17 wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
19 wfOut( "Modifying $field field of table $table..." );
21 $dbw->sourceFile( $patch );
23 $dbw->sourceFile( archive( $patch ) );
29 function drop_index_if_exists( $table, $index, $patch, $fullpath = false ) {
30 $dbw = wfGetDB( DB_MASTER );
31 if ( $dbw->indexExists( $table, $index ) ) {
32 wfOut( "Dropping $index from table $table... " );
34 $dbw->sourceFile( $patch );
36 $dbw->sourceFile( archive( $patch ) );
40 wfOut( "...$index doesn't exist.\n" );
44 function archive( $name ) {
45 return DatabaseBase::patchPath( $name );
48 function do_interwiki_update() {
49 # Check that interwiki table exists; if it doesn't source it
51 $dbw = wfGetDB( DB_MASTER );
52 if ( $dbw->tableExists( "interwiki" ) ) {
53 wfOut( "...already have interwiki table\n" );
56 wfOut( "Creating interwiki table: " );
57 $dbw->sourceFile( archive( "patch-interwiki.sql" ) );
59 wfOut( "Adding default interwiki definitions: " );
60 $dbw->sourceFile( "$IP/maintenance/interwiki.sql" );
64 function do_index_update() {
65 # Check that proper indexes are in place
66 $dbw = wfGetDB( DB_MASTER );
67 $meta = $dbw->fieldInfo( "recentchanges", "rc_timestamp" );
68 if ( !$meta->isMultipleKey() ) {
69 wfOut( "Updating indexes to 20031107: " );
70 $dbw->sourceFile( archive( "patch-indexes.sql" ) );
74 wfOut( "...indexes seem up to 20031107 standards\n" );
78 function do_image_index_update() {
79 $dbw = wfGetDB( DB_MASTER );
80 $meta = $dbw->fieldInfo( "image", "img_major_mime" );
81 if ( !$meta->isMultipleKey() ) {
82 wfOut( "Updating indexes to 20050912: " );
83 $dbw->sourceFile( archive( "patch-mimesearch-indexes.sql" ) );
87 wfOut( "...indexes seem up to 20050912 standards\n" );
91 function do_image_name_unique_update() {
92 $dbw = wfGetDB( DB_MASTER );
93 if ( $dbw->indexExists( 'image', 'PRIMARY' ) ) {
94 wfOut( "...image primary key already set.\n" );
96 wfOut( "Making img_name the primary key... " );
97 $dbw->sourceFile( archive( "patch-image_name_primary.sql" ) );
102 function do_watchlist_update() {
103 $dbw = wfGetDB( DB_MASTER );
104 if ( $dbw->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
105 wfOut( "...the watchlist table is already set up for email notification.\n" );
107 wfOut( "Adding wl_notificationtimestamp field for email notification management." );
108 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
109 $dbw->sourceFile( archive( 'patch-email-notification.sql' ) );
112 # Check if we need to add talk page rows to the watchlist
113 $talk = $dbw->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', __METHOD__ );
114 $nontalk = $dbw->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', __METHOD__ );
115 if ( $talk != $nontalk ) {
116 wfOut( "Adding missing watchlist talk page rows... " );
119 $dbw->insertSelect( 'watchlist', 'watchlist',
121 'wl_user' => 'wl_user',
122 'wl_namespace' => 'wl_namespace | 1',
123 'wl_title' => 'wl_title',
124 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
125 ), array( 'NOT (wl_namespace & 1)' ), __METHOD__, 'IGNORE' );
128 wfOut( "...watchlist talk page rows already present\n" );
132 function do_copy_newtalk_to_watchlist() {
133 $dbw = wfGetDB( DB_MASTER );
134 $res = $dbw->safeQuery( 'SELECT user_id, user_ip FROM !',
135 $dbw->tableName( 'user_newtalk' ) );
136 $num_newtalks = $dbw->numRows( $res );
137 wfOut( "Now converting $num_newtalks user_newtalk entries to watchlist table entries ... \n" );
140 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
141 $wluser = $dbw->fetchObject( $res );
142 if ( $wluser->user_id == 0 ) { # anonymous users ... have IP numbers as "names"
143 if ( $user->isIP( $wluser->user_ip ) ) { # do only if it really looks like an IP number (double checked)
144 $dbw->replace( 'watchlist',
145 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
146 array( 'wl_user' => 0,
147 'wl_namespace' => NS_USER_TALK,
148 'wl_title' => $wluser->user_ip,
149 'wl_notificationtimestamp' => '19700101000000'
150 ), 'updaters.inc::do_watchlist_update2'
153 } else { # normal users ... have user_ids
154 $user->setID( $wluser->user_id );
155 $dbw->replace( 'watchlist',
156 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
157 array( 'wl_user' => $user->getID(),
158 'wl_namespace' => NS_USER_TALK,
159 'wl_title' => $user->getName(),
160 'wl_notificationtimestamp' => '19700101000000'
161 ), 'updaters.inc::do_watchlist_update3'
169 * 1.4 betas were missing the 'binary' marker from logging.log_title,
170 * which causes a collation mismatch error on joins in MySQL 4.1.
172 function check_bin( $table, $field, $patchFile ) {
173 $dbw = wfGetDB( DB_MASTER );
174 if ( $dbw->getType() != 'mysql' )
176 $tableName = $dbw->tableName( $table );
177 $res = $dbw->query( "SELECT $field FROM $tableName LIMIT 0" );
178 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
180 if ( in_array( 'binary', $flags ) ) {
181 wfOut( "...$table table has correct $field encoding.\n" );
183 wfOut( "Fixing $field encoding on $table table... " );
184 $dbw->sourceFile( archive( $patchFile ) );
189 function do_schema_restructuring() {
190 $dbw = wfGetDB( DB_MASTER );
191 if ( $dbw->tableExists( 'page' ) ) {
192 wfOut( "...page table already exists.\n" );
194 wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
195 wfOut( wfTimestamp( TS_DB ) );
196 wfOut( "......checking for duplicate entries.\n" );
198 list ( $cur, $old, $page, $revision, $text ) = $dbw->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
200 $rows = $dbw->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
201 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", __METHOD__ );
203 if ( $dbw->numRows( $rows ) > 0 ) {
204 wfOut( wfTimestamp( TS_DB ) );
205 wfOut( "......<b>Found duplicate entries</b>\n" );
206 wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
207 while ( $row = $dbw->fetchObject( $rows ) ) {
208 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
209 $duplicate[$row->cur_namespace] = array();
211 $duplicate[$row->cur_namespace][] = $row->cur_title;
212 wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
214 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
216 foreach ( $duplicate as $ns => $titles ) {
222 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
224 foreach ( $titles as $t ) {
226 $sql .= $dbw->addQuotes( $t );
229 $sql .= ', ' . $dbw->addQuotes( $t );
234 # By sorting descending, the most recent entry will be the first in the list.
235 # All following entries will be deleted by the next while-loop.
236 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
238 $rows = $dbw->query( $sql, __METHOD__ );
240 $prev_title = $prev_namespace = false;
243 while ( $row = $dbw->fetchObject( $rows ) ) {
244 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
245 $deleteId[] = $row->cur_id;
247 $prev_title = $row->cur_title;
248 $prev_namespace = $row->cur_namespace;
250 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
251 $rows = $dbw->query( $sql, __METHOD__ );
252 wfOut( wfTimestamp( TS_DB ) );
253 wfOut( "......<b>Deleted</b> " . $dbw->affectedRows() . " records.\n" );
257 wfOut( wfTimestamp( TS_DB ) );
258 wfOut( "......Creating tables.\n" );
259 $dbw->query( "CREATE TABLE $page (
260 page_id int(8) unsigned NOT NULL auto_increment,
261 page_namespace int NOT NULL,
262 page_title varchar(255) binary NOT NULL,
263 page_restrictions tinyblob NOT NULL,
264 page_counter bigint(20) unsigned NOT NULL default '0',
265 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
266 page_is_new tinyint(1) unsigned NOT NULL default '0',
267 page_random real unsigned NOT NULL,
268 page_touched char(14) binary NOT NULL default '',
269 page_latest int(8) unsigned NOT NULL,
270 page_len int(8) unsigned NOT NULL,
272 PRIMARY KEY page_id (page_id),
273 UNIQUE INDEX name_title (page_namespace,page_title),
276 ) ENGINE=InnoDB", __METHOD__ );
277 $dbw->query( "CREATE TABLE $revision (
278 rev_id int(8) unsigned NOT NULL auto_increment,
279 rev_page int(8) unsigned NOT NULL,
280 rev_comment tinyblob NOT NULL,
281 rev_user int(5) unsigned NOT NULL default '0',
282 rev_user_text varchar(255) binary NOT NULL default '',
283 rev_timestamp char(14) binary NOT NULL default '',
284 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
285 rev_deleted tinyint(1) unsigned NOT NULL default '0',
286 rev_len int(8) unsigned,
287 rev_parent_id int(8) unsigned default NULL,
288 PRIMARY KEY rev_page_id (rev_page, rev_id),
289 UNIQUE INDEX rev_id (rev_id),
290 INDEX rev_timestamp (rev_timestamp),
291 INDEX page_timestamp (rev_page,rev_timestamp),
292 INDEX user_timestamp (rev_user,rev_timestamp),
293 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
294 ) ENGINE=InnoDB", __METHOD__ );
296 wfOut( wfTimestamp( TS_DB ) );
297 wfOut( "......Locking tables.\n" );
298 $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", __METHOD__ );
300 $maxold = intval( $dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ) );
301 wfOut( wfTimestamp( TS_DB ) );
302 wfOut( "......maxold is {$maxold}\n" );
304 wfOut( wfTimestamp( TS_DB ) );
305 global $wgLegacySchemaConversion;
306 if ( $wgLegacySchemaConversion ) {
307 // Create HistoryBlobCurStub entries.
308 // Text will be pulled from the leftover 'cur' table at runtime.
309 wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
310 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
311 $cur_flags = "'object'";
313 // Copy all cur text in immediately: this may take longer but avoids
314 // having to keep an extra table around.
315 wfOut( "......Moving text from cur.\n" );
316 $cur_text = 'cur_text';
319 $dbw->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
320 old_timestamp, old_minor_edit, old_flags)
321 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
322 FROM $cur", __METHOD__ );
324 wfOut( wfTimestamp( TS_DB ) );
325 wfOut( "......Setting up revision table.\n" );
326 $dbw->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
328 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
329 old_timestamp, old_minor_edit
330 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", __METHOD__ );
332 wfOut( wfTimestamp( TS_DB ) );
333 wfOut( "......Setting up page table.\n" );
334 $dbw->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
335 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
336 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
337 cur_random, cur_touched, rev_id, LENGTH(cur_text)
339 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", __METHOD__ );
341 wfOut( wfTimestamp( TS_DB ) );
342 wfOut( "......Unlocking tables.\n" );
343 $dbw->query( "UNLOCK TABLES", __METHOD__ );
345 wfOut( wfTimestamp( TS_DB ) );
346 wfOut( "......Renaming old.\n" );
347 $dbw->query( "ALTER TABLE $old RENAME TO $text", __METHOD__ );
349 wfOut( wfTimestamp( TS_DB ) );
350 wfOut( "...done.\n" );
354 function do_pagelinks_update() {
355 $dbw = wfGetDB( DB_MASTER );
356 if ( $dbw->tableExists( 'pagelinks' ) ) {
357 wfOut( "...already have pagelinks table.\n" );
359 wfOut( "Converting links and brokenlinks tables to pagelinks... " );
360 $dbw->sourceFile( archive( 'patch-pagelinks.sql' ) );
364 global $wgCanonicalNamespaceNames;
365 foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
367 do_pagelinks_namespace( $ns );
373 function do_pagelinks_namespace( $namespace ) {
376 $dbw = wfGetDB( DB_MASTER );
377 $ns = intval( $namespace );
378 wfOut( "Cleaning up broken links for namespace $ns... " );
380 $pagelinks = $dbw->tableName( 'pagelinks' );
381 $name = $wgContLang->getNsText( $ns );
382 $prefix = $dbw->strencode( $name );
383 $likeprefix = str_replace( '_', '\\_', $prefix );
385 $sql = "UPDATE $pagelinks
386 SET pl_namespace=$ns,
387 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
389 AND pl_title LIKE '$likeprefix:%'";
391 $dbw->query( $sql, 'do_pagelinks_namespace' );
395 function do_old_links_update() {
396 $cl = new ConvertLinks();
400 function fix_ancient_imagelinks() {
401 $dbw = wfGetDB( DB_MASTER );
402 $info = $dbw->fieldInfo( 'imagelinks', 'il_from' );
403 if ( $info && $info->type() === 'string' ) {
404 wfOut( "Fixing ancient broken imagelinks table.\n" );
405 wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
406 $dbw->sourceFile( archive( 'patch-fix-il_from.sql' ) );
409 wfOut( "...il_from OK\n" );
413 function do_user_unique_update() {
414 $dbw = wfGetDB( DB_MASTER );
415 $duper = new UserDupes( $dbw );
416 if ( $duper->hasUniqueIndex() ) {
417 wfOut( "...already have unique user_name index.\n" );
419 if ( !$duper->clearDupes() ) {
420 wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
422 wfOut( "Adding unique index on user_name... " );
423 $dbw->sourceFile( archive( 'patch-user_nameindex.sql' ) );
428 function do_user_groups_update() {
429 $dbw = wfGetDB( DB_MASTER );
431 if ( $dbw->tableExists( 'user_groups' ) ) {
432 wfOut( "...user_groups table already exists.\n" );
433 return do_user_groups_reformat();
436 wfOut( "Adding user_groups table... " );
437 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
440 if ( !$dbw->tableExists( 'user_rights' ) ) {
441 if ( $dbw->fieldExists( 'user', 'user_rights' ) ) {
442 wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
443 $dbw->sourceFile( archive( 'patch-user_rights.sql' ) );
446 wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
447 wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
448 wfOut( "*** the user_groups table.\n" );
453 wfOut( "Converting user_rights table to user_groups... " );
454 $result = $dbw->select( 'user_rights',
455 array( 'ur_user', 'ur_rights' ),
456 array( "ur_rights != ''" ),
459 while ( $row = $dbw->fetchObject( $result ) ) {
460 $groups = array_unique(
462 explode( ',', $row->ur_rights ) ) );
464 foreach ( $groups as $group ) {
465 $dbw->insert( 'user_groups',
467 'ug_user' => $row->ur_user,
468 'ug_group' => $group ),
475 function do_user_groups_reformat() {
476 # Check for bogus formats from previous 1.5 alpha code.
477 $dbw = wfGetDB( DB_MASTER );
478 $info = $dbw->fieldInfo( 'user_groups', 'ug_group' );
480 if ( $info->type() == 'int' ) {
481 $oldug = $dbw->tableName( 'user_groups' );
482 $newug = $dbw->tableName( 'user_groups_bogus' );
483 wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
484 $dbw->query( "ALTER TABLE $oldug RENAME TO $newug" );
487 wfOut( "Re-adding fresh user_groups table... " );
488 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
492 wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
493 wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
496 wfOut( "...user_groups is in current format.\n" );
501 function do_watchlist_null() {
502 # Make sure wl_notificationtimestamp can be NULL,
503 # and update old broken items.
504 $dbw = wfGetDB( DB_MASTER );
505 $info = $dbw->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
507 if ( !$info->nullable() ) {
508 wfOut( "Making wl_notificationtimestamp nullable... " );
509 $dbw->sourceFile( archive( 'patch-watchlist-null.sql' ) );
512 wfOut( "...wl_notificationtimestamp is already nullable.\n" );
520 function do_page_random_update() {
521 wfOut( "Setting page_random to a random value on rows where it equals 0..." );
523 $dbw = wfGetDB( DB_MASTER );
524 $page = $dbw->tableName( 'page' );
525 $dbw->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
526 $rows = $dbw->affectedRows();
528 wfOut( "changed $rows rows\n" );
531 function do_templatelinks_update() {
532 $dbw = wfGetDB( DB_MASTER );
534 if ( $dbw->tableExists( 'templatelinks' ) ) {
535 wfOut( "...templatelinks table already exists\n" );
538 wfOut( "Creating templatelinks table...\n" );
539 $dbw->sourceFile( archive( 'patch-templatelinks.sql' ) );
540 wfOut( "Populating...\n" );
541 if ( wfGetLB()->getServerCount() > 1 ) {
542 // Slow, replication-friendly update
543 $res = $dbw->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
544 array( 'pl_namespace' => NS_TEMPLATE ), __METHOD__ );
546 while ( $row = $dbw->fetchObject( $res ) ) {
547 $count = ( $count + 1 ) % 100;
549 if ( function_exists( 'wfWaitForSlaves' ) ) {
550 wfWaitForSlaves( 10 );
555 $dbw->insert( 'templatelinks',
557 'tl_from' => $row->pl_from,
558 'tl_namespace' => $row->pl_namespace,
559 'tl_title' => $row->pl_title,
566 $dbw->insertSelect( 'templatelinks', 'pagelinks',
568 'tl_from' => 'pl_from',
569 'tl_namespace' => 'pl_namespace',
570 'tl_title' => 'pl_title'
576 wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
579 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
580 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
581 function do_rc_indices_update() {
582 $dbw = wfGetDB( DB_MASTER );
583 wfOut( "Checking for additional recent changes indices...\n" );
586 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
587 'rc_user_text' => 'patch-rc_user_text-index.sql',
590 foreach ( $indexes as $index => $patch ) {
591 $info = $dbw->indexInfo( 'recentchanges', $index, __METHOD__ );
593 wfOut( "...index `{$index}` not found; adding..." );
594 $dbw->sourceFile( archive( $patch ) );
597 wfOut( "...index `{$index}` seems ok.\n" );
602 function index_has_field( $table, $index, $field ) {
603 wfOut( "Checking if $table index $index includes field $field...\n" );
604 $info = wfGetDB( DB_MASTER )->indexInfo( $table, $index, __METHOD__ );
606 foreach ( $info as $row ) {
607 if ( $row->Column_name == $field ) {
608 wfOut( "...index $index on table $table seems to be ok\n" );
613 wfOut( "...index $index on table $table has no field $field; adding\n" );
617 function do_backlinking_indices_update() {
618 wfOut( "Checking for backlinking indices...\n" );
619 if ( !index_has_field( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
620 !index_has_field( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
621 !index_has_field( 'imagelinks', 'il_to', 'il_from' ) )
623 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-backlinkindexes.sql' ) );
624 wfOut( "...backlinking indices updated\n" );
628 function do_categorylinks_indices_update() {
629 wfOut( "Checking for categorylinks indices...\n" );
630 if ( !index_has_field( 'categorylinks', 'cl_sortkey', 'cl_from' ) )
632 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinksindex.sql' ) );
633 wfOut( "...categorylinks indices updated\n" );
637 function do_filearchive_indices_update() {
638 $dbw = wfGetDB( DB_MASTER );
639 wfOut( "Checking filearchive indices...\n" );
640 $info = $dbw->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
643 $dbw->sourceFile( archive( 'patch-filearchive-user-index.sql' ) );
644 wfOut( "...filearchive indices updated\n" );
648 function maybe_do_profiling_memory_update() {
649 $dbw = wfGetDB( DB_MASTER );
650 if ( !$dbw->tableExists( 'profiling' ) ) {
652 } elseif ( $dbw->fieldExists( 'profiling', 'pf_memory' ) ) {
653 wfOut( "...profiling table has pf_memory field.\n" );
655 wfOut( "Adding pf_memory field to table profiling..." );
656 $dbw->sourceFile( archive( 'patch-profiling-memory.sql' ) );
661 function do_stats_init() {
662 // Sometimes site_stats table is not properly populated.
663 wfOut( "\nChecking site_stats row..." );
664 $row = wfGetDB( DB_MASTER )->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
665 if ( $row === false ) {
666 wfOut( "data is missing! rebuilding...\n" );
667 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
668 wfOut( "missing ss_total_pages, rebuilding...\n" );
673 SiteStatsInit::doAllAndCommit( false );
676 function do_active_users_init() {
677 $dbw = wfGetDB( DB_MASTER );
678 $activeUsers = $dbw->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
679 if ( $activeUsers == -1 ) {
680 $activeUsers = $dbw->selectField( 'recentchanges',
681 'COUNT( DISTINCT rc_user_text )',
682 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
684 $dbw->update( 'site_stats',
685 array( 'ss_active_users' => intval( $activeUsers ) ),
686 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
689 wfOut( "...ss_active_users user count set...\n" );
693 * Adding page_restrictions table, obsoleting page.page_restrictions.
694 * Migrating old restrictions to new table
695 * -- Andrew Garrett, January 2007.
697 function do_restrictions_update() {
698 $dbw = wfGetDB( DB_MASTER );
699 if ( $dbw->tableExists( 'page_restrictions' ) ) {
700 wfOut( "...page_restrictions table already exists.\n" );
702 wfOut( "Creating page_restrictions table..." );
703 $dbw->sourceFile( archive( 'patch-page_restrictions.sql' ) );
704 $dbw->sourceFile( archive( 'patch-page_restrictions_sortkey.sql' ) );
707 wfOut( "Migrating old restrictions to new table...\n" );
708 $task = new UpdateRestrictions();
713 function do_category_population() {
714 if ( update_row_exists( 'populate category' ) ) {
715 wfOut( "...category table already populated.\n" );
720 "Populating category table, printing progress markers. " .
721 "For large databases, you\n" .
722 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
723 "populateCategory.php.\n"
725 $task = new PopulateCategory();
727 wfOut( "Done populating category table.\n" );
730 function do_populate_parent_id() {
731 if ( update_row_exists( 'populate rev_parent_id' ) ) {
732 wfOut( "...rev_parent_id column already populated.\n" );
736 $task = new PopulateParentId();
740 function do_populate_rev_len() {
741 if ( update_row_exists( 'populate rev_len' ) ) {
742 wfOut( "...rev_len column already populated.\n" );
746 $task = new PopulateRevisionLength();
750 function do_cl_fields_update() {
751 if ( update_row_exists( 'cl_fields_update' ) ) {
752 wfOut( "...categorylinks up-to-date.\n" );
755 wfOut( 'Updating categorylinks (again)...' );
756 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinks-better-collation2.sql' ) );
760 function do_collation_update() {
761 global $wgCategoryCollation;
762 $dbw = wfGetDB( DB_MASTER );
763 if ( $dbw->selectField(
766 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
769 wfOut( "...collations up-to-date.\n" );
773 $task = new UpdateCollation();
777 function sqlite_initial_indexes() {
778 $dbw = wfGetDB( DB_MASTER );
779 // initial-indexes.sql fails if the indexes are already present, so we perform a quick check if our database is newer.
780 if ( update_row_exists( 'initial_indexes' ) || $dbw->indexExists( 'user', 'user_name' ) ) {
781 wfOut( "...have initial indexes\n" );
784 wfOut( "Adding initial indexes..." );
785 $dbw->sourceFile( archive( 'initial-indexes.sql' ) );
789 function sqlite_setup_searchindex() {
790 $dbw = wfGetDB( DB_MASTER );
791 $module = $dbw->getFulltextSearchModule();
792 $fts3tTable = update_row_exists( 'fts3' );
793 if ( $fts3tTable && !$module ) {
794 wfOut( '...PHP is missing FTS3 support, downgrading tables...' );
795 $dbw->sourceFile( archive( 'searchindex-no-fts.sql' ) );
797 } elseif ( !$fts3tTable && $module == 'FTS3' ) {
798 wfOut( '...adding FTS3 search capabilities...' );
799 $dbw->sourceFile( archive( 'searchindex-fts3.sql' ) );
802 wfOut( "...fulltext search table appears to be in order.\n" );
806 function do_unique_pl_tl_il() {
807 $dbw = wfGetDB( DB_MASTER );
808 $info = $dbw->indexInfo( 'pagelinks', 'pl_namespace' );
809 if ( is_array( $info ) && !$info[0]->Non_unique ) {
810 wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
812 wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
813 $dbw->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) );
818 function do_log_search_population() {
819 if ( update_row_exists( 'populate log_search' ) ) {
820 wfOut( "...log_search table already populated.\n" );
824 "Populating log_search table, printing progress markers. For large\n" .
825 "databases, you may want to hit Ctrl-C and do this manually with\n" .
826 "maintenance/populateLogSearch.php.\n" );
827 $task = new PopulateLogSearch();
829 wfOut( "Done populating log_search table.\n" );
832 function rename_eu_wiki_id() {
833 $dbw = wfGetDB( DB_MASTER );
834 if ( $dbw->fieldExists( 'external_user', 'eu_local_id' ) ) {
835 wfOut( "...eu_wiki_id already renamed to eu_local_id.\n" );
838 wfOut( "Renaming eu_wiki_id -> eu_local_id... " );
839 $dbw->sourceFile( archive( 'patch-eu_local_id.sql' ) );
843 function do_update_transcache_field() {
844 if ( update_row_exists( 'convert transcache field' ) ) {
845 wfOut( "...transcache tc_time already converted.\n" );
848 wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
849 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-tc-timestamp.sql' ) );
854 function do_update_mime_minor_field() {
855 if ( update_row_exists( 'mime_minor_length' ) ) {
856 wfOut( "...*_mime_minor fields are already long enough.\n" );
858 wfOut( "Altering all *_mime_minor fields to 100 bytes in size ... " );
859 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-mime_minor_length.sql' ) );