* Use Maintenance::runChild() to get the child script instance
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance
5 */
6
7 if ( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is not a valid entry point\n";
9 exit( 1 );
10 }
11
12 function archive( $name ) {
13 return DatabaseBase::patchPath( $name );
14 }
15
16 function do_interwiki_update() {
17 # Check that interwiki table exists; if it doesn't source it
18 global $IP;
19 $dbw = wfGetDB( DB_MASTER );
20 if ( $dbw->tableExists( "interwiki" ) ) {
21 wfOut( "...already have interwiki table\n" );
22 return true;
23 }
24 wfOut( "Creating interwiki table: " );
25 $dbw->sourceFile( archive( "patch-interwiki.sql" ) );
26 wfOut( "ok\n" );
27 wfOut( "Adding default interwiki definitions: " );
28 $dbw->sourceFile( "$IP/maintenance/interwiki.sql" );
29 wfOut( "ok\n" );
30 }
31
32 function do_index_update() {
33 # Check that proper indexes are in place
34 $dbw = wfGetDB( DB_MASTER );
35 $meta = $dbw->fieldInfo( "recentchanges", "rc_timestamp" );
36 if ( !$meta->isMultipleKey() ) {
37 wfOut( "Updating indexes to 20031107: " );
38 $dbw->sourceFile( archive( "patch-indexes.sql" ) );
39 wfOut( "ok\n" );
40 return true;
41 }
42 wfOut( "...indexes seem up to 20031107 standards\n" );
43 return false;
44 }
45
46 function do_image_name_unique_update() {
47 $dbw = wfGetDB( DB_MASTER );
48 if ( $dbw->indexExists( 'image', 'PRIMARY' ) ) {
49 wfOut( "...image primary key already set.\n" );
50 } else {
51 wfOut( "Making img_name the primary key... " );
52 $dbw->sourceFile( archive( "patch-image_name_primary.sql" ) );
53 wfOut( "ok\n" );
54 }
55 }
56
57 function do_watchlist_update() {
58 $dbw = wfGetDB( DB_MASTER );
59 # Check if we need to add talk page rows to the watchlist
60 $talk = $dbw->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', __METHOD__ );
61 $nontalk = $dbw->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', __METHOD__ );
62 if ( $talk != $nontalk ) {
63 wfOut( "Adding missing watchlist talk page rows... " );
64
65 $dbw->insertSelect( 'watchlist', 'watchlist',
66 array(
67 'wl_user' => 'wl_user',
68 'wl_namespace' => 'wl_namespace | 1',
69 'wl_title' => 'wl_title',
70 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
71 ), array( 'NOT (wl_namespace & 1)' ), __METHOD__, 'IGNORE' );
72 wfOut( "ok\n" );
73 } else {
74 wfOut( "...watchlist talk page rows already present\n" );
75 }
76 }
77
78 /**
79 * 1.4 betas were missing the 'binary' marker from logging.log_title,
80 * which causes a collation mismatch error on joins in MySQL 4.1.
81 */
82 function check_bin( $table, $field, $patchFile ) {
83 $dbw = wfGetDB( DB_MASTER );
84 if ( $dbw->getType() != 'mysql' )
85 return;
86 $tableName = $dbw->tableName( $table );
87 $res = $dbw->query( "SELECT $field FROM $tableName LIMIT 0", __METHOD__ );
88 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
89
90 if ( in_array( 'binary', $flags ) ) {
91 wfOut( "...$table table has correct $field encoding.\n" );
92 } else {
93 wfOut( "Fixing $field encoding on $table table... " );
94 $dbw->sourceFile( archive( $patchFile ) );
95 wfOut( "ok\n" );
96 }
97 }
98
99 function do_schema_restructuring() {
100 $dbw = wfGetDB( DB_MASTER );
101 if ( $dbw->tableExists( 'page' ) ) {
102 wfOut( "...page table already exists.\n" );
103 } else {
104 wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
105 wfOut( wfTimestamp( TS_DB ) );
106 wfOut( "......checking for duplicate entries.\n" );
107
108 list ( $cur, $old, $page, $revision, $text ) = $dbw->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
109
110 $rows = $dbw->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
111 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", __METHOD__ );
112
113 if ( $dbw->numRows( $rows ) > 0 ) {
114 wfOut( wfTimestamp( TS_DB ) );
115 wfOut( "......<b>Found duplicate entries</b>\n" );
116 wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
117 while ( $row = $dbw->fetchObject( $rows ) ) {
118 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
119 $duplicate[$row->cur_namespace] = array();
120 }
121 $duplicate[$row->cur_namespace][] = $row->cur_title;
122 wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
123 }
124 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
125 $firstCond = true;
126 foreach ( $duplicate as $ns => $titles ) {
127 if ( $firstCond ) {
128 $firstCond = false;
129 } else {
130 $sql .= ' OR ';
131 }
132 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
133 $first = true;
134 foreach ( $titles as $t ) {
135 if ( $first ) {
136 $sql .= $dbw->addQuotes( $t );
137 $first = false;
138 } else {
139 $sql .= ', ' . $dbw->addQuotes( $t );
140 }
141 }
142 $sql .= ") ) \n";
143 }
144 # By sorting descending, the most recent entry will be the first in the list.
145 # All following entries will be deleted by the next while-loop.
146 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
147
148 $rows = $dbw->query( $sql, __METHOD__ );
149
150 $prev_title = $prev_namespace = false;
151 $deleteId = array();
152
153 while ( $row = $dbw->fetchObject( $rows ) ) {
154 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
155 $deleteId[] = $row->cur_id;
156 }
157 $prev_title = $row->cur_title;
158 $prev_namespace = $row->cur_namespace;
159 }
160 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
161 $rows = $dbw->query( $sql, __METHOD__ );
162 wfOut( wfTimestamp( TS_DB ) );
163 wfOut( "......<b>Deleted</b> " . $dbw->affectedRows() . " records.\n" );
164 }
165
166
167 wfOut( wfTimestamp( TS_DB ) );
168 wfOut( "......Creating tables.\n" );
169 $dbw->query( "CREATE TABLE $page (
170 page_id int(8) unsigned NOT NULL auto_increment,
171 page_namespace int NOT NULL,
172 page_title varchar(255) binary NOT NULL,
173 page_restrictions tinyblob NOT NULL,
174 page_counter bigint(20) unsigned NOT NULL default '0',
175 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
176 page_is_new tinyint(1) unsigned NOT NULL default '0',
177 page_random real unsigned NOT NULL,
178 page_touched char(14) binary NOT NULL default '',
179 page_latest int(8) unsigned NOT NULL,
180 page_len int(8) unsigned NOT NULL,
181
182 PRIMARY KEY page_id (page_id),
183 UNIQUE INDEX name_title (page_namespace,page_title),
184 INDEX (page_random),
185 INDEX (page_len)
186 ) ENGINE=InnoDB", __METHOD__ );
187 $dbw->query( "CREATE TABLE $revision (
188 rev_id int(8) unsigned NOT NULL auto_increment,
189 rev_page int(8) unsigned NOT NULL,
190 rev_comment tinyblob NOT NULL,
191 rev_user int(5) unsigned NOT NULL default '0',
192 rev_user_text varchar(255) binary NOT NULL default '',
193 rev_timestamp char(14) binary NOT NULL default '',
194 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
195 rev_deleted tinyint(1) unsigned NOT NULL default '0',
196 rev_len int(8) unsigned,
197 rev_parent_id int(8) unsigned default NULL,
198 PRIMARY KEY rev_page_id (rev_page, rev_id),
199 UNIQUE INDEX rev_id (rev_id),
200 INDEX rev_timestamp (rev_timestamp),
201 INDEX page_timestamp (rev_page,rev_timestamp),
202 INDEX user_timestamp (rev_user,rev_timestamp),
203 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
204 ) ENGINE=InnoDB", __METHOD__ );
205
206 wfOut( wfTimestamp( TS_DB ) );
207 wfOut( "......Locking tables.\n" );
208 $dbw->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", __METHOD__ );
209
210 $maxold = intval( $dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ) );
211 wfOut( wfTimestamp( TS_DB ) );
212 wfOut( "......maxold is {$maxold}\n" );
213
214 wfOut( wfTimestamp( TS_DB ) );
215 global $wgLegacySchemaConversion;
216 if ( $wgLegacySchemaConversion ) {
217 // Create HistoryBlobCurStub entries.
218 // Text will be pulled from the leftover 'cur' table at runtime.
219 wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
220 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
221 $cur_flags = "'object'";
222 } else {
223 // Copy all cur text in immediately: this may take longer but avoids
224 // having to keep an extra table around.
225 wfOut( "......Moving text from cur.\n" );
226 $cur_text = 'cur_text';
227 $cur_flags = "''";
228 }
229 $dbw->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
230 old_timestamp, old_minor_edit, old_flags)
231 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
232 FROM $cur", __METHOD__ );
233
234 wfOut( wfTimestamp( TS_DB ) );
235 wfOut( "......Setting up revision table.\n" );
236 $dbw->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
237 rev_minor_edit)
238 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
239 old_timestamp, old_minor_edit
240 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", __METHOD__ );
241
242 wfOut( wfTimestamp( TS_DB ) );
243 wfOut( "......Setting up page table.\n" );
244 $dbw->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
245 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
246 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
247 cur_random, cur_touched, rev_id, LENGTH(cur_text)
248 FROM $cur,$revision
249 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", __METHOD__ );
250
251 wfOut( wfTimestamp( TS_DB ) );
252 wfOut( "......Unlocking tables.\n" );
253 $dbw->query( "UNLOCK TABLES", __METHOD__ );
254
255 wfOut( wfTimestamp( TS_DB ) );
256 wfOut( "......Renaming old.\n" );
257 $dbw->query( "ALTER TABLE $old RENAME TO $text", __METHOD__ );
258
259 wfOut( wfTimestamp( TS_DB ) );
260 wfOut( "...done.\n" );
261 }
262 }
263
264 function do_pagelinks_update() {
265 $dbw = wfGetDB( DB_MASTER );
266 if ( $dbw->tableExists( 'pagelinks' ) ) {
267 wfOut( "...already have pagelinks table.\n" );
268 } else {
269 wfOut( "Converting links and brokenlinks tables to pagelinks... " );
270 $dbw->sourceFile( archive( 'patch-pagelinks.sql' ) );
271 wfOut( "ok\n" );
272
273 global $wgCanonicalNamespaceNames;
274 foreach ( $wgCanonicalNamespaceNames as $ns => $name ) {
275 if ( $ns != 0 ) {
276 do_pagelinks_namespace( $ns );
277 }
278 }
279 }
280 }
281
282 function do_pagelinks_namespace( $namespace ) {
283 global $wgContLang;
284
285 $dbw = wfGetDB( DB_MASTER );
286 $ns = intval( $namespace );
287 wfOut( "Cleaning up broken links for namespace $ns... " );
288
289 $pagelinks = $dbw->tableName( 'pagelinks' );
290 $name = $wgContLang->getNsText( $ns );
291 $prefix = $dbw->strencode( $name );
292 $likeprefix = str_replace( '_', '\\_', $prefix );
293
294 $sql = "UPDATE $pagelinks
295 SET pl_namespace=$ns,
296 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
297 WHERE pl_namespace=0
298 AND pl_title LIKE '$likeprefix:%'";
299
300 $dbw->query( $sql, 'do_pagelinks_namespace' );
301 wfOut( "ok\n" );
302 }
303
304 function do_old_links_update() {
305 $cl = new ConvertLinks();
306 $cl->execute();
307 }
308
309 function fix_ancient_imagelinks() {
310 $dbw = wfGetDB( DB_MASTER );
311 $info = $dbw->fieldInfo( 'imagelinks', 'il_from' );
312 if ( $info && $info->type() === 'string' ) {
313 wfOut( "Fixing ancient broken imagelinks table.\n" );
314 wfOut( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
315 $dbw->sourceFile( archive( 'patch-fix-il_from.sql' ) );
316 wfOut( "ok\n" );
317 } else {
318 wfOut( "...il_from OK\n" );
319 }
320 }
321
322 function do_user_unique_update() {
323 $dbw = wfGetDB( DB_MASTER );
324 $duper = new UserDupes( $dbw );
325 if ( $duper->hasUniqueIndex() ) {
326 wfOut( "...already have unique user_name index.\n" );
327 } else {
328 if ( !$duper->clearDupes() ) {
329 wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
330 }
331 wfOut( "Adding unique index on user_name... " );
332 $dbw->sourceFile( archive( 'patch-user_nameindex.sql' ) );
333 wfOut( "ok\n" );
334 }
335 }
336
337 function do_user_groups_update() {
338 $dbw = wfGetDB( DB_MASTER );
339
340 if ( $dbw->tableExists( 'user_groups' ) ) {
341 wfOut( "...user_groups table already exists.\n" );
342 return do_user_groups_reformat();
343 }
344
345 wfOut( "Adding user_groups table... " );
346 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
347 wfOut( "ok\n" );
348
349 if ( !$dbw->tableExists( 'user_rights' ) ) {
350 if ( $dbw->fieldExists( 'user', 'user_rights' ) ) {
351 wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
352 $dbw->sourceFile( archive( 'patch-user_rights.sql' ) );
353 wfOut( "ok\n" );
354 } else {
355 wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
356 wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
357 wfOut( "*** the user_groups table.\n" );
358 return;
359 }
360 }
361
362 wfOut( "Converting user_rights table to user_groups... " );
363 $result = $dbw->select( 'user_rights',
364 array( 'ur_user', 'ur_rights' ),
365 array( "ur_rights != ''" ),
366 __METHOD__ );
367
368 while ( $row = $dbw->fetchObject( $result ) ) {
369 $groups = array_unique(
370 array_map( 'trim',
371 explode( ',', $row->ur_rights ) ) );
372
373 foreach ( $groups as $group ) {
374 $dbw->insert( 'user_groups',
375 array(
376 'ug_user' => $row->ur_user,
377 'ug_group' => $group ),
378 __METHOD__ );
379 }
380 }
381 wfOut( "ok\n" );
382 }
383
384 function do_user_groups_reformat() {
385 # Check for bogus formats from previous 1.5 alpha code.
386 $dbw = wfGetDB( DB_MASTER );
387 $info = $dbw->fieldInfo( 'user_groups', 'ug_group' );
388
389 if ( $info->type() == 'int' ) {
390 $oldug = $dbw->tableName( 'user_groups' );
391 $newug = $dbw->tableName( 'user_groups_bogus' );
392 wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
393 $dbw->query( "ALTER TABLE $oldug RENAME TO $newug" );
394 wfOut( "ok\n" );
395
396 wfOut( "Re-adding fresh user_groups table... " );
397 $dbw->sourceFile( archive( 'patch-user_groups.sql' ) );
398 wfOut( "ok\n" );
399
400 wfOut( "***\n" );
401 wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
402 wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
403 wfOut( "***\n" );
404 } else {
405 wfOut( "...user_groups is in current format.\n" );
406 }
407
408 }
409
410 function do_watchlist_null() {
411 # Make sure wl_notificationtimestamp can be NULL,
412 # and update old broken items.
413 $dbw = wfGetDB( DB_MASTER );
414 $info = $dbw->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
415
416 if ( !$info->nullable() ) {
417 wfOut( "Making wl_notificationtimestamp nullable... " );
418 $dbw->sourceFile( archive( 'patch-watchlist-null.sql' ) );
419 wfOut( "ok\n" );
420 } else {
421 wfOut( "...wl_notificationtimestamp is already nullable.\n" );
422 }
423
424 }
425
426 /**
427 * @bug 3946
428 */
429 function do_page_random_update() {
430 wfOut( "Setting page_random to a random value on rows where it equals 0..." );
431
432 $dbw = wfGetDB( DB_MASTER );
433 $page = $dbw->tableName( 'page' );
434 $dbw->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
435 $rows = $dbw->affectedRows();
436
437 wfOut( "changed $rows rows\n" );
438 }
439
440 function do_templatelinks_update() {
441 $dbw = wfGetDB( DB_MASTER );
442
443 if ( $dbw->tableExists( 'templatelinks' ) ) {
444 wfOut( "...templatelinks table already exists\n" );
445 return;
446 }
447 wfOut( "Creating templatelinks table...\n" );
448 $dbw->sourceFile( archive( 'patch-templatelinks.sql' ) );
449 wfOut( "Populating...\n" );
450 if ( wfGetLB()->getServerCount() > 1 ) {
451 // Slow, replication-friendly update
452 $res = $dbw->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
453 array( 'pl_namespace' => NS_TEMPLATE ), __METHOD__ );
454 $count = 0;
455 while ( $row = $dbw->fetchObject( $res ) ) {
456 $count = ( $count + 1 ) % 100;
457 if ( $count == 0 ) {
458 if ( function_exists( 'wfWaitForSlaves' ) ) {
459 wfWaitForSlaves( 10 );
460 } else {
461 sleep( 1 );
462 }
463 }
464 $dbw->insert( 'templatelinks',
465 array(
466 'tl_from' => $row->pl_from,
467 'tl_namespace' => $row->pl_namespace,
468 'tl_title' => $row->pl_title,
469 ), __METHOD__
470 );
471
472 }
473 } else {
474 // Fast update
475 $dbw->insertSelect( 'templatelinks', 'pagelinks',
476 array(
477 'tl_from' => 'pl_from',
478 'tl_namespace' => 'pl_namespace',
479 'tl_title' => 'pl_title'
480 ), array(
481 'pl_namespace' => 10
482 ), __METHOD__
483 );
484 }
485 wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
486 }
487
488 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
489 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
490 function do_rc_indices_update() {
491 $dbw = wfGetDB( DB_MASTER );
492 wfOut( "Checking for additional recent changes indices...\n" );
493
494 $indexes = array(
495 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
496 'rc_user_text' => 'patch-rc_user_text-index.sql',
497 );
498
499 foreach ( $indexes as $index => $patch ) {
500 $info = $dbw->indexInfo( 'recentchanges', $index, __METHOD__ );
501 if ( !$info ) {
502 wfOut( "...index `{$index}` not found; adding..." );
503 $dbw->sourceFile( archive( $patch ) );
504 wfOut( "done.\n" );
505 } else {
506 wfOut( "...index `{$index}` seems ok.\n" );
507 }
508 }
509 }
510
511 function index_has_field( $table, $index, $field ) {
512 wfOut( "Checking if $table index $index includes field $field...\n" );
513 $info = wfGetDB( DB_MASTER )->indexInfo( $table, $index, __METHOD__ );
514 if ( $info ) {
515 foreach ( $info as $row ) {
516 if ( $row->Column_name == $field ) {
517 wfOut( "...index $index on table $table seems to be ok\n" );
518 return true;
519 }
520 }
521 }
522 wfOut( "...index $index on table $table has no field $field; adding\n" );
523 return false;
524 }
525
526 function do_backlinking_indices_update() {
527 wfOut( "Checking for backlinking indices...\n" );
528 if ( !index_has_field( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
529 !index_has_field( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
530 !index_has_field( 'imagelinks', 'il_to', 'il_from' ) )
531 {
532 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-backlinkindexes.sql' ) );
533 wfOut( "...backlinking indices updated\n" );
534 }
535 }
536
537 function do_categorylinks_indices_update() {
538 wfOut( "Checking for categorylinks indices...\n" );
539 if ( !index_has_field( 'categorylinks', 'cl_sortkey', 'cl_from' ) )
540 {
541 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinksindex.sql' ) );
542 wfOut( "...categorylinks indices updated\n" );
543 }
544 }
545
546 function do_filearchive_indices_update() {
547 $dbw = wfGetDB( DB_MASTER );
548 wfOut( "Checking filearchive indices...\n" );
549 $info = $dbw->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
550 if ( !$info )
551 {
552 $dbw->sourceFile( archive( 'patch-filearchive-user-index.sql' ) );
553 wfOut( "...filearchive indices updated\n" );
554 }
555 }
556
557 function maybe_do_profiling_memory_update() {
558 $dbw = wfGetDB( DB_MASTER );
559 if ( !$dbw->tableExists( 'profiling' ) ) {
560 // Simply ignore
561 } elseif ( $dbw->fieldExists( 'profiling', 'pf_memory' ) ) {
562 wfOut( "...profiling table has pf_memory field.\n" );
563 } else {
564 wfOut( "Adding pf_memory field to table profiling..." );
565 $dbw->sourceFile( archive( 'patch-profiling-memory.sql' ) );
566 wfOut( "ok\n" );
567 }
568 }
569
570 function do_active_users_init() {
571 $dbw = wfGetDB( DB_MASTER );
572 $activeUsers = $dbw->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
573 if ( $activeUsers == -1 ) {
574 $activeUsers = $dbw->selectField( 'recentchanges',
575 'COUNT( DISTINCT rc_user_text )',
576 array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
577 );
578 $dbw->update( 'site_stats',
579 array( 'ss_active_users' => intval( $activeUsers ) ),
580 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
581 );
582 }
583 wfOut( "...ss_active_users user count set...\n" );
584 }
585
586 /**
587 * Adding page_restrictions table, obsoleting page.page_restrictions.
588 * Migrating old restrictions to new table
589 * -- Andrew Garrett, January 2007.
590 */
591 function do_restrictions_update() {
592 $dbw = wfGetDB( DB_MASTER );
593 if ( $dbw->tableExists( 'page_restrictions' ) ) {
594 wfOut( "...page_restrictions table already exists.\n" );
595 } else {
596 wfOut( "Creating page_restrictions table..." );
597 $dbw->sourceFile( archive( 'patch-page_restrictions.sql' ) );
598 $dbw->sourceFile( archive( 'patch-page_restrictions_sortkey.sql' ) );
599 wfOut( "ok\n" );
600
601 wfOut( "Migrating old restrictions to new table...\n" );
602 $task = new UpdateRestrictions();
603 $task->execute();
604 }
605 }
606
607 function do_category_population() {
608 if ( update_row_exists( 'populate category' ) ) {
609 wfOut( "...category table already populated.\n" );
610 return;
611 }
612
613 wfOut(
614 "Populating category table, printing progress markers. " .
615 "For large databases, you\n" .
616 "may want to hit Ctrl-C and do this manually with maintenance/\n" .
617 "populateCategory.php.\n"
618 );
619 $task = new PopulateCategory();
620 $task->execute();
621 wfOut( "Done populating category table.\n" );
622 }
623
624 function do_populate_parent_id() {
625 if ( update_row_exists( 'populate rev_parent_id' ) ) {
626 wfOut( "...rev_parent_id column already populated.\n" );
627 return;
628 }
629
630 $task = new PopulateParentId();
631 $task->execute();
632 }
633
634 function do_populate_rev_len() {
635 if ( update_row_exists( 'populate rev_len' ) ) {
636 wfOut( "...rev_len column already populated.\n" );
637 return;
638 }
639
640 $task = new PopulateRevisionLength();
641 $task->execute();
642 }
643
644 function do_cl_fields_update() {
645 if ( update_row_exists( 'cl_fields_update' ) ) {
646 wfOut( "...categorylinks up-to-date.\n" );
647 return;
648 }
649 wfOut( 'Updating categorylinks (again)...' );
650 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-categorylinks-better-collation2.sql' ) );
651 wfOut( "done.\n" );
652 }
653
654 function do_collation_update() {
655 global $wgCategoryCollation;
656 $dbw = wfGetDB( DB_MASTER );
657 if ( $dbw->selectField(
658 'categorylinks',
659 'COUNT(*)',
660 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
661 __FUNCTION__
662 ) == 0 ) {
663 wfOut( "...collations up-to-date.\n" );
664 return;
665 }
666
667 $task = new UpdateCollation();
668 $task->execute();
669 }
670
671 function do_unique_pl_tl_il() {
672 $dbw = wfGetDB( DB_MASTER );
673 $info = $dbw->indexInfo( 'pagelinks', 'pl_namespace' );
674 if ( is_array( $info ) && !$info[0]->Non_unique ) {
675 wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
676 } else {
677 wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
678 $dbw->sourceFile( archive( 'patch-pl-tl-il-unique.sql' ) );
679 wfOut( "ok\n" );
680 }
681 }
682
683 function do_log_search_population() {
684 if ( update_row_exists( 'populate log_search' ) ) {
685 wfOut( "...log_search table already populated.\n" );
686 return;
687 }
688 wfOut(
689 "Populating log_search table, printing progress markers. For large\n" .
690 "databases, you may want to hit Ctrl-C and do this manually with\n" .
691 "maintenance/populateLogSearch.php.\n" );
692 $task = new PopulateLogSearch();
693 $task->execute();
694 wfOut( "Done populating log_search table.\n" );
695 }
696
697 function rename_eu_wiki_id() {
698 $dbw = wfGetDB( DB_MASTER );
699 if ( $dbw->fieldExists( 'external_user', 'eu_local_id' ) ) {
700 wfOut( "...eu_wiki_id already renamed to eu_local_id.\n" );
701 return;
702 }
703 wfOut( "Renaming eu_wiki_id -> eu_local_id... " );
704 $dbw->sourceFile( archive( 'patch-eu_local_id.sql' ) );
705 wfOut( "ok\n" );
706 }
707
708 function do_update_transcache_field() {
709 if ( update_row_exists( 'convert transcache field' ) ) {
710 wfOut( "...transcache tc_time already converted.\n" );
711 return;
712 } else {
713 wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
714 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-tc-timestamp.sql' ) );
715 wfOut( "ok\n" );
716 }
717 }
718
719 function do_update_mime_minor_field() {
720 if ( update_row_exists( 'mime_minor_length' ) ) {
721 wfOut( "...*_mime_minor fields are already long enough.\n" );
722 } else {
723 wfOut( "Altering all *_mime_minor fields to 100 bytes in size ... " );
724 wfGetDB( DB_MASTER )->sourceFile( archive( 'patch-mime_minor_length.sql' ) );
725 wfOut( "ok\n" );
726 }
727 }