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 $fname = 'do_watchlist_update';
105 if ( $dbw->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
106 wfOut( "...the watchlist table is already set up for email notification.\n" );
108 wfOut( "Adding wl_notificationtimestamp field for email notification management." );
109 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
110 $dbw->sourceFile( archive( 'patch-email-notification.sql' ) );
113 # Check if we need to add talk page rows to the watchlist
114 $talk = $dbw->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
115 $nontalk = $dbw->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
116 if ( $talk != $nontalk ) {
117 wfOut( "Adding missing watchlist talk page rows... " );
120 $dbw->insertSelect( 'watchlist', 'watchlist',
122 'wl_user' => 'wl_user',
123 'wl_namespace' => 'wl_namespace | 1',
124 'wl_title' => 'wl_title',
125 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
126 ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
129 wfOut( "...watchlist talk page rows already present\n" );
133 function do_copy_newtalk_to_watchlist() {
134 $dbw = wfGetDB( DB_MASTER );
135 $res = $dbw->safeQuery( 'SELECT user_id, user_ip FROM !',
136 $dbw->tableName( 'user_newtalk' ) );
137 $num_newtalks = $dbw->numRows( $res );
138 wfOut( "Now converting $num_newtalks user_newtalk entries to watchlist table entries ... \n" );
141 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
142 $wluser = $dbw->fetchObject( $res );
143 if ( $wluser->user_id == 0 ) { # anonymous users ... have IP numbers as "names"
144 if ( $user->isIP( $wluser->user_ip ) ) { # do only if it really looks like an IP number (double checked)
145 $dbw->replace( 'watchlist',
146 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
147 array( 'wl_user' => 0,
148 'wl_namespace' => NS_USER_TALK,
149 'wl_title' => $wluser->user_ip,
150 'wl_notificationtimestamp' => '19700101000000'
151 ), 'updaters.inc::do_watchlist_update2'
154 } else { # normal users ... have user_ids
155 $user->setID( $wluser->user_id );
156 $dbw->replace( 'watchlist',
157 array( array( 'wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ) ),
158 array( 'wl_user' => $user->getID(),
159 'wl_namespace' => NS_USER_TALK,
160 'wl_title' => $user->getName(),
161 'wl_notificationtimestamp' => '19700101000000'
162 ), 'updaters.inc::do_watchlist_update3'
170 * 1.4 betas were missing the 'binary' marker from logging.log_title,
171 * which causes a collation mismatch error on joins in MySQL 4.1.
173 function check_bin( $table, $field, $patchFile ) {
174 $dbw = wfGetDB( DB_MASTER );
175 if ( $dbw->getType() != 'mysql' )
177 $tableName = $dbw->tableName( $table );
178 $res = $dbw->query( "SELECT $field FROM $tableName LIMIT 0" );
179 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
181 if ( in_array( 'binary', $flags ) ) {
182 wfOut( "...$table table has correct $field encoding.\n" );
184 wfOut( "Fixing $field encoding on $table table... " );
185 $dbw->sourceFile( archive( $patchFile ) );
190 function do_schema_restructuring() {
191 $dbw = wfGetDB( DB_MASTER );
192 $fname = "do_schema_restructuring";
193 if ( $dbw->tableExists( 'page' ) ) {
194 wfOut( "...page table already exists.\n" );
196 wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
197 wfOut( wfTimestamp( TS_DB ) );
198 wfOut( "......checking for duplicate entries.\n" );
200 list ( $cur, $old, $page, $revision, $text ) = $dbw->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
202 $rows = $dbw->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
203 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
205 if ( $dbw->numRows( $rows ) > 0 ) {
206 wfOut( wfTimestamp( TS_DB ) );
207 wfOut( "......<b>Found duplicate entries</b>\n" );
208 wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
209 while ( $row = $dbw->fetchObject( $rows ) ) {
210 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
211 $duplicate[$row->cur_namespace] = array();
213 $duplicate[$row->cur_namespace][] = $row->cur_title;
214 wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
216 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
218 foreach ( $duplicate as $ns => $titles ) {
224 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
226 foreach ( $titles as $t ) {
228 $sql .= $dbw->addQuotes( $t );
231 $sql .= ', ' . $dbw->addQuotes( $t );
236 # By sorting descending, the most recent entry will be the first in the list.
237 # All following entries will be deleted by the next while-loop.
238 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
240 $rows = $dbw->query( $sql, $fname );
242 $prev_title = $prev_namespace = false;
245 while ( $row = $dbw->fetchObject( $rows ) ) {
246 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
247 $deleteId[] = $row->cur_id;
249 $prev_title = $row->cur_title;
250 $prev_namespace = $row->cur_namespace;
252 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
253 $rows = $dbw->query( $sql, $fname );
254 wfOut( wfTimestamp( TS_DB ) );
255 wfOut( "......<b>Deleted</b> " . $dbw->affectedRows() . " records.\n" );
259 wfOut( wfTimestamp( TS_DB ) );
260 wfOut( "......Creating tables.\n" );
261 $dbw->query( "CREATE TABLE $page (
262 page_id int(8) unsigned NOT NULL auto_increment,
263 page_namespace int NOT NULL,
264 page_title varchar(255) binary NOT NULL,
265 page_restrictions tinyblob NOT NULL,
266 page_counter bigint(20) unsigned NOT NULL default '0',
267 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
268 page_is_new tinyint(1) unsigned NOT NULL default '0',
269 page_random real unsigned NOT NULL,
270 page_touched char(14) binary NOT NULL default '',
271 page_latest int(8) unsigned NOT NULL,
272 page_len int(8) unsigned NOT NULL,
274 PRIMARY KEY page_id (page_id),
275 UNIQUE INDEX name_title (page_namespace,page_title),
278 ) ENGINE=InnoDB", $fname );
279 $dbw->query( "CREATE TABLE $revision (
280 rev_id int(8) unsigned NOT NULL auto_increment,
281 rev_page int(8) unsigned NOT NULL,
282 rev_comment tinyblob NOT NULL,
283 rev_user int(5) unsigned NOT NULL default '0',
284 rev_user_text varchar(255) binary NOT NULL default '',
285 rev_timestamp char(14) binary NOT NULL default '',
286 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
287 rev_deleted tinyint(1) unsigned NOT NULL default '0',
288 rev_len int(8) unsigned,
289 rev_parent_id int(8) unsigned default NULL,
290 PRIMARY KEY rev_page_id (rev_page, rev_id),
291 UNIQUE INDEX rev_id (rev_id),
292 INDEX rev_timestamp (rev_timestamp),
293 INDEX page_timestamp (rev_page,rev_timestamp),
294 INDEX user_timestamp (rev_user,rev_timestamp),
295 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
296 ) ENGINE=InnoDB", $fname );
298 wfOut( wfTimestamp( TS_DB ) );
299 wfOut( "......Locking tables.\n" );
300 $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
302 $maxold = intval( $dbw->selectField( 'old', 'max(old_id)', '', $fname ) );
303 wfOut( wfTimestamp( TS_DB ) );
304 wfOut( "......maxold is {$maxold}\n" );
306 wfOut( wfTimestamp( TS_DB ) );
307 global $wgLegacySchemaConversion;
308 if ( $wgLegacySchemaConversion ) {
309 // Create HistoryBlobCurStub entries.
310 // Text will be pulled from the leftover 'cur' table at runtime.
311 wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
312 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
313 $cur_flags = "'object'";
315 // Copy all cur text in immediately: this may take longer but avoids
316 // having to keep an extra table around.
317 wfOut( "......Moving text from cur.\n" );
318 $cur_text = 'cur_text';
321 $dbw->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
322 old_timestamp, old_minor_edit, old_flags)
323 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
324 FROM $cur", $fname );
326 wfOut( wfTimestamp( TS_DB ) );
327 wfOut( "......Setting up revision table.\n" );
328 $dbw->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
330 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
331 old_timestamp, old_minor_edit
332 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
334 wfOut( wfTimestamp( TS_DB ) );
335 wfOut( "......Setting up page table.\n" );
336 $dbw->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
337 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
338 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
339 cur_random, cur_touched, rev_id, LENGTH(cur_text)
341 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
343 wfOut( wfTimestamp( TS_DB ) );
344 wfOut( "......Unlocking tables.\n" );
345 $dbw->query( "UNLOCK TABLES", $fname );
347 wfOut( wfTimestamp( TS_DB ) );
348 wfOut( "......Renaming old.\n" );
349 $dbw->query( "ALTER TABLE $old RENAME TO $text", $fname );
351 wfOut( wfTimestamp( TS_DB ) );
352 wfOut( "...done.\n" );
356 function do_pagelinks_update() {
357 $dbw = wfGetDB( DB_MASTER );
358 if ( $dbw->tableExists( 'pagelinks' ) ) {
359 wfOut( "...already have pagelinks table.\n" );
361 wfOut( "Converting links and brokenlinks tables to pagelinks... " );
362 $dbw->sourceFile( archive( 'patch-pagelinks.sql' ) );
366 global $wgCanonicalNamespaceNames;
367 foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
369 do_pagelinks_namespace( $ns );
375 function do_pagelinks_namespace( $namespace ) {
378 $dbw = wfGetDB( DB_MASTER );
379 $ns = intval( $namespace );
380 wfOut( "Cleaning up broken links for namespace $ns... " );
382 $pagelinks = $dbw->tableName( 'pagelinks' );
383 $name = $wgContLang->getNsText( $ns );
384 $prefix = $dbw->strencode( $name );
385 $likeprefix = str_replace( '_', '\\_', $prefix );
387 $sql = "UPDATE $pagelinks
388 SET pl_namespace=$ns,
389 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
391 AND pl_title LIKE '$likeprefix:%'";
393 $dbw->query( $sql, 'do_pagelinks_namespace' );
397 function do_old_links_update() {
398 if( !defined( 'MW_NO_SETUP' ) ) {
399 define( 'MW_NO_SETUP', true );
401 require( "convertLinks.php" );
402 $cl = new ConvertLinks();
406 function fix_ancient_imagelinks() {
407 $dbw = wfGetDB( DB_MASTER );
408 $info = $dbw->fieldInfo( 'imagelinks', 'il_from' );
409 if ( $info && $info->type() === 'string' ) {
410 wfOut( "Fixing ancient broken imagelinks table.\n" );
411 wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
412 $dbw->sourceFile( archive( 'patch-fix-il_from.sql' ) );
415 wfOut( "...il_from OK\n" );
419 function do_user_unique_update() {
420 $dbw = wfGetDB( DB_MASTER );
421 require_once( "userDupes.inc" );
422 $duper = new UserDupes( $dbw );
423 if ( $duper->hasUniqueIndex() ) {
424 wfOut( "...already have unique user_name index.\n" );
426 if ( !$duper->clearDupes() ) {
427 wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
429 wfOut( "Adding unique index on user_name... " );
430 $dbw->sourceFile( archive( 'patch-user_nameindex.sql' ) );
435 function do_user_groups_update() {
436 $fname = 'do_user_groups_update';
437 $dbw = wfGetDB( DB_MASTER );
439 if ( $dbw->tableExists( 'user_groups' ) ) {
440 wfOut( "...user_groups table already exists.\n" );
441 return do_user_groups_reformat();
444 wfOut( "Adding user_groups table... " );
445 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
448 if ( !$dbw->tableExists( 'user_rights' ) ) {
449 if ( $dbw->fieldExists( 'user', 'user_rights' ) ) {
450 wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
451 $dbw->sourceFile( archive( 'patch-user_rights.sql' ) );
454 wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
455 wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
456 wfOut( "*** the user_groups table.\n" );
461 wfOut( "Converting user_rights table to user_groups... " );
462 $result = $dbw->select( 'user_rights',
463 array( 'ur_user', 'ur_rights' ),
464 array( "ur_rights != ''" ),
467 while ( $row = $dbw->fetchObject( $result ) ) {
468 $groups = array_unique(
470 explode( ',', $row->ur_rights ) ) );
472 foreach ( $groups as $group ) {
473 $dbw->insert( 'user_groups',
475 'ug_user' => $row->ur_user,
476 'ug_group' => $group ),
483 function do_user_groups_reformat() {
484 # Check for bogus formats from previous 1.5 alpha code.
485 $dbw = wfGetDB( DB_MASTER );
486 $info = $dbw->fieldInfo( 'user_groups', 'ug_group' );
488 if ( $info->type() == 'int' ) {
489 $oldug = $dbw->tableName( 'user_groups' );
490 $newug = $dbw->tableName( 'user_groups_bogus' );
491 wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
492 $dbw->query( "ALTER TABLE $oldug RENAME TO $newug" );
495 wfOut( "Re-adding fresh user_groups table... " );
496 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
500 wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
501 wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
504 wfOut( "...user_groups is in current format.\n" );
509 function do_watchlist_null() {
510 # Make sure wl_notificationtimestamp can be NULL,
511 # and update old broken items.
512 $dbw = wfGetDB( DB_MASTER );
513 $info = $dbw->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
515 if ( !$info->nullable() ) {
516 wfOut( "Making wl_notificationtimestamp nullable... " );
517 $dbw->sourceFile( archive( 'patch-watchlist-null.sql' ) );
520 wfOut( "...wl_notificationtimestamp is already nullable.\n" );
528 function do_page_random_update() {
529 wfOut( "Setting page_random to a random value on rows where it equals 0..." );
531 $dbw = wfGetDB( DB_MASTER );
532 $page = $dbw->tableName( 'page' );
533 $dbw->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
534 $rows = $dbw->affectedRows();
536 wfOut( "changed $rows rows\n" );
539 function do_templatelinks_update() {
540 $dbw = wfGetDB( DB_MASTER );
541 $fname = 'do_templatelinks_update';
543 if ( $dbw->tableExists( 'templatelinks' ) ) {
544 wfOut( "...templatelinks table already exists\n" );
547 wfOut( "Creating templatelinks table...\n" );
548 $dbw->sourceFile( archive( 'patch-templatelinks.sql' ) );
549 wfOut( "Populating...\n" );
550 if ( wfGetLB()->getServerCount() > 1 ) {
551 // Slow, replication-friendly update
552 $res = $dbw->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
553 array( 'pl_namespace' => NS_TEMPLATE ), $fname );
555 while ( $row = $dbw->fetchObject( $res ) ) {
556 $count = ( $count + 1 ) % 100;
558 if ( function_exists( 'wfWaitForSlaves' ) ) {
559 wfWaitForSlaves( 10 );
564 $dbw->insert( 'templatelinks',
566 'tl_from' => $row->pl_from,
567 'tl_namespace' => $row->pl_namespace,
568 'tl_title' => $row->pl_title,
575 $dbw->insertSelect( 'templatelinks', 'pagelinks',
577 'tl_from' => 'pl_from',
578 'tl_namespace' => 'pl_namespace',
579 'tl_title' => 'pl_title'
585 wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
588 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
589 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
590 function do_rc_indices_update() {
591 $dbw = wfGetDB( DB_MASTER );
592 wfOut( "Checking for additional recent changes indices...\n" );
595 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
596 'rc_user_text' => 'patch-rc_user_text-index.sql',
599 foreach ( $indexes as $index => $patch ) {
600 $info = $dbw->indexInfo( 'recentchanges', $index, __METHOD__ );
602 wfOut( "...index `{$index}` not found; adding..." );
603 $dbw->sourceFile( archive( $patch ) );
606 wfOut( "...index `{$index}` seems ok.\n" );
611 function index_has_field( $table, $index, $field ) {
612 wfOut( "Checking if $table index $index includes field $field...\n" );
613 $info = wfGetDB( DB_MASTER )->indexInfo( $table, $index, __METHOD__ );
615 foreach ( $info as $row ) {
616 if ( $row->Column_name == $field ) {
617 wfOut( "...index $index on table $table seems to be ok\n" );
622 wfOut( "...index $index on table $table has no field $field; adding\n" );
626 function do_backlinking_indices_update() {
627 wfOut( "Checking for backlinking indices...\n" );
628 if ( !index_has_field( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
629 !index_has_field( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
630 !index_has_field( 'imagelinks', 'il_to', 'il_from' ) )
632 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-backlinkindexes.sql' ) );
633 wfOut( "...backlinking indices updated\n" );
637 function do_categorylinks_indices_update() {
638 wfOut( "Checking for categorylinks indices...\n" );
639 if ( !index_has_field( 'categorylinks', 'cl_sortkey', 'cl_from' ) )
641 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinksindex.sql' ) );
642 wfOut( "...categorylinks indices updated\n" );
646 function do_filearchive_indices_update() {
647 $dbw = wfGetDB( DB_MASTER );
648 wfOut( "Checking filearchive indices...\n" );
649 $info = $dbw->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
652 $dbw->sourceFile( archive( 'patch-filearchive-user-index.sql' ) );
653 wfOut( "...filearchive indices updated\n" );
657 function maybe_do_profiling_memory_update() {
658 $dbw = wfGetDB( DB_MASTER );
659 if ( !$dbw->tableExists( 'profiling' ) ) {
661 } elseif ( $dbw->fieldExists( 'profiling', 'pf_memory' ) ) {
662 wfOut( "...profiling table has pf_memory field.\n" );
664 wfOut( "Adding pf_memory field to table profiling..." );
665 $dbw->sourceFile( archive( 'patch-profiling-memory.sql' ) );
670 function do_stats_init() {
671 // Sometimes site_stats table is not properly populated.
672 wfOut( "\nChecking site_stats row..." );
673 $row = wfGetDB( DB_MASTER )->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
674 if ( $row === false ) {
675 wfOut( "data is missing! rebuilding...\n" );
676 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
677 wfOut( "missing ss_total_pages, rebuilding...\n" );
682 SiteStatsInit::doAllAndCommit( false );
685 function do_active_users_init() {
686 $dbw = wfGetDB( DB_MASTER );
687 $activeUsers = $dbw->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
688 if ( $activeUsers == -1 ) {
689 $activeUsers = $dbw->selectField( 'recentchanges',
690 'COUNT( DISTINCT rc_user_text )',
691 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
693 $dbw->update( 'site_stats',
694 array( 'ss_active_users' => intval( $activeUsers ) ),
695 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
698 wfOut( "...ss_active_users user count set...\n" );
702 * Adding page_restrictions table, obsoleting page.page_restrictions.
703 * Migrating old restrictions to new table
704 * -- Andrew Garrett, January 2007.
706 function do_restrictions_update() {
707 $dbw = wfGetDB( DB_MASTER );
708 if ( $dbw->tableExists( 'page_restrictions' ) ) {
709 wfOut( "...page_restrictions table already exists.\n" );
711 wfOut( "Creating page_restrictions table..." );
712 $dbw->sourceFile( archive( 'patch-page_restrictions.sql' ) );
713 $dbw->sourceFile( archive( 'patch-page_restrictions_sortkey.sql' ) );
716 wfOut( "Migrating old restrictions to new table...\n" );
717 require_once( 'updateRestrictions.php' );
718 $task = new UpdateRestrictions();
723 function do_category_population() {
724 if ( update_row_exists( 'populate category' ) ) {
725 wfOut( "...category table already populated.\n" );
728 require_once( 'populateCategory.php' );
730 "Populating category table, printing progress markers. " .
731 "For large databases, you\n" .
732 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
733 "populateCategory.php.\n"
735 $task = new PopulateCategory();
737 wfOut( "Done populating category table.\n" );
740 function do_populate_parent_id() {
741 if ( update_row_exists( 'populate rev_parent_id' ) ) {
742 wfOut( "...rev_parent_id column already populated.\n" );
745 require_once( 'populateParentId.php' );
746 $task = new PopulateParentId();
750 function do_populate_rev_len() {
751 if ( update_row_exists( 'populate rev_len' ) ) {
752 wfOut( "...rev_len column already populated.\n" );
755 require_once( 'populateRevisionLength.php' );
756 $task = new PopulateRevisionLength();
760 function do_cl_fields_update() {
761 if ( update_row_exists( 'cl_fields_update' ) ) {
762 wfOut( "...categorylinks up-to-date.\n" );
765 wfOut( 'Updating categorylinks (again)...' );
766 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinks-better-collation2.sql' ) );
770 function do_collation_update() {
771 global $wgCategoryCollation;
772 $dbw = wfGetDB( DB_MASTER );
773 if ( $dbw->selectField(
776 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
779 wfOut( "...collations up-to-date.\n" );
782 require_once( 'updateCollation.php' );
783 $task = new UpdateCollation();
787 function sqlite_initial_indexes() {
788 $dbw = wfGetDB( DB_MASTER );
789 // initial-indexes.sql fails if the indexes are already present, so we perform a quick check if our database is newer.
790 if ( update_row_exists( 'initial_indexes' ) || $dbw->indexExists( 'user', 'user_name' ) ) {
791 wfOut( "...have initial indexes\n" );
794 wfOut( "Adding initial indexes..." );
795 $dbw->sourceFile( archive( 'initial-indexes.sql' ) );
799 function sqlite_setup_searchindex() {
800 $dbw = wfGetDB( DB_MASTER );
801 $module = $dbw->getFulltextSearchModule();
802 $fts3tTable = update_row_exists( 'fts3' );
803 if ( $fts3tTable && !$module ) {
804 wfOut( '...PHP is missing FTS3 support, downgrading tables...' );
805 $dbw->sourceFile( archive( 'searchindex-no-fts.sql' ) );
807 } elseif ( !$fts3tTable && $module == 'FTS3' ) {
808 wfOut( '...adding FTS3 search capabilities...' );
809 $dbw->sourceFile( archive( 'searchindex-fts3.sql' ) );
812 wfOut( "...fulltext search table appears to be in order.\n" );
816 function do_unique_pl_tl_il() {
817 $dbw = wfGetDB( DB_MASTER );
818 $info = $dbw->indexInfo( 'pagelinks', 'pl_namespace' );
819 if ( is_array( $info ) && !$info[0]->Non_unique ) {
820 wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
822 wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
823 $dbw->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) );
828 function do_log_search_population() {
829 if ( update_row_exists( 'populate log_search' ) ) {
830 wfOut( "...log_search table already populated.\n" );
833 require_once( 'populateLogSearch.php' );
835 "Populating log_search table, printing progress markers. For large\n" .
836 "databases, you may want to hit Ctrl-C and do this manually with\n" .
837 "maintenance/populateLogSearch.php.\n" );
838 $task = new PopulateLogSearch();
840 wfOut( "Done populating log_search table.\n" );
843 function rename_eu_wiki_id() {
844 $dbw = wfGetDB( DB_MASTER );
845 if ( $dbw->fieldExists( 'external_user', 'eu_local_id' ) ) {
846 wfOut( "...eu_wiki_id already renamed to eu_local_id.\n" );
849 wfOut( "Renaming eu_wiki_id -> eu_local_id... " );
850 $dbw->sourceFile( archive( 'patch-eu_local_id.sql' ) );
854 function do_update_transcache_field() {
855 if ( update_row_exists( 'convert transcache field' ) ) {
856 wfOut( "...transcache tc_time already converted.\n" );
859 wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
860 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-tc-timestamp.sql' ) );
865 function do_update_mime_minor_field() {
866 if ( update_row_exists( 'mime_minor_length' ) ) {
867 wfOut( "...*_mime_minor fields are already long enough.\n" );
869 wfOut( "Altering all *_mime_minor fields to 100 bytes in size ... " );
870 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-mime_minor_length.sql' ) );