r46840 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46839‎ | r46840 | r46841 >
Date:08:56, 5 February 2009
Author:tstarling
Status:deferred
Tags:
Comment:
* Fixed a whole lot of XSS vulnerabilities in the installer. All require a live installer, i.e. with no LocalSettings.php present.
* Implemented taint support in the installer and fixed some false positives (and false negatives)
Modified paths:
  • /trunk/phase3/config/index.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/maintenance/convertLinks.inc (modified) (history)
  • /trunk/phase3/maintenance/initStats.inc (modified) (history)
  • /trunk/phase3/maintenance/populateCategory.inc (modified) (history)
  • /trunk/phase3/maintenance/populateParentId.inc (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)
  • /trunk/phase3/maintenance/userDupes.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/initStats.inc
@@ -7,34 +7,34 @@
88 function wfInitStats( $options=array() ) {
99 $dbr = wfGetDB( DB_SLAVE );
1010
11 - echo "Counting total edits...";
 11+ wfOut( "Counting total edits..." );
1212 $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ );
1313 $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ );
14 - echo "{$edits}\nCounting number of articles...";
 14+ wfOut( "{$edits}\nCounting number of articles..." );
1515
1616 global $wgContentNamespaces;
1717 $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ );
18 - echo "{$good}\nCounting total pages...";
 18+ wfOut( "{$good}\nCounting total pages..." );
1919
2020 $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ );
21 - echo "{$pages}\nCounting number of users...";
 21+ wfOut( "{$pages}\nCounting number of users..." );
2222
2323 $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ );
24 - echo "{$users}\nCounting number of admins...";
 24+ wfOut( "{$users}\nCounting number of admins..." );
2525
2626 $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ );
27 - echo "{$admin}\nCounting number of images...";
 27+ wfOut( "{$admin}\nCounting number of images..." );
2828
2929 $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ );
30 - echo "{$image}\n";
 30+ wfOut( "{$image}\n" );
3131
3232 if( !isset( $options['noviews'] ) ) {
33 - echo "Counting total page views...";
 33+ wfOut( "Counting total page views..." );
3434 $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ );
35 - echo "{$views}\n";
 35+ wfOut( "{$views}\n" );
3636 }
3737
38 - echo "\nUpdating site statistics...";
 38+ wfOut( "\nUpdating site statistics..." );
3939
4040 $dbw = wfGetDB( DB_MASTER );
4141 $values = array( 'ss_total_edits' => $edits,
@@ -53,5 +53,5 @@
5454 $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ );
5555 }
5656
57 - echo( "done.\n" );
 57+ wfOut( "done.\n" );
5858 }
Index: trunk/phase3/maintenance/populateCategory.inc
@@ -18,9 +18,9 @@
1919 __FUNCTION__
2020 );
2121 if( $row ) {
22 - echo "Category table already populated. Use php ".
 22+ wfOut( "Category table already populated. Use php ".
2323 "maintenance/populateCategory.php\n--force from the command line ".
24 - "to override.\n";
 24+ "to override.\n" );
2525 return true;
2626 }
2727 }
@@ -56,14 +56,14 @@
5757 # Use the row to update the category count
5858 $cat = Category::newFromName( $name );
5959 if( !is_object( $cat ) ) {
60 - echo "The category named $name is not valid?!\n";
 60+ wfOut( "The category named $name is not valid?!\n" );
6161 } else {
6262 $cat->refreshCounts();
6363 }
6464
6565 ++$i;
6666 if( !($i % REPORTING_INTERVAL) ) {
67 - echo "$name\n";
 67+ wfOut( "$name\n" );
6868 wfWaitForSlaves( $maxlag );
6969 }
7070 usleep( $throttle*1000 );
@@ -76,10 +76,10 @@
7777 'IGNORE'
7878 )
7979 ) {
80 - echo "Category population complete.\n";
 80+ wfOut( "Category population complete.\n" );
8181 return true;
8282 } else {
83 - echo "Could not insert category population row.\n";
 83+ wfOut( "Could not insert category population row.\n" );
8484 return false;
8585 }
8686 }
Index: trunk/phase3/maintenance/updaters.inc
@@ -190,11 +190,11 @@
191191 global $wgDatabase;
192192 if ( $wgDatabase->tableExists( $from ) ) {
193193 if ( $wgDatabase->tableExists( $to ) ) {
194 - echo "...can't move table $from to $to, $to already exists.\n";
 194+ wfOut( "...can't move table $from to $to, $to already exists.\n" );
195195 } else {
196 - echo "Moving table $from to $to...";
 196+ wfOut( "Moving table $from to $to..." );
197197 dbsource( archive($patch), $wgDatabase );
198 - echo "ok\n";
 198+ wfOut( "ok\n" );
199199 }
200200 } else {
201201 // Source table does not exist
@@ -206,47 +206,47 @@
207207 function add_table( $name, $patch, $fullpath=false ) {
208208 global $wgDatabase;
209209 if ( $wgDatabase->tableExists( $name ) ) {
210 - echo "...$name table already exists.\n";
 210+ wfOut( "...$name table already exists.\n" );
211211 } else {
212 - echo "Creating $name table...";
 212+ wfOut( "Creating $name table..." );
213213 if( $fullpath ) {
214214 dbsource( $patch, $wgDatabase );
215215 } else {
216216 dbsource( archive($patch), $wgDatabase );
217217 }
218 - echo "ok\n";
 218+ wfOut( "ok\n" );
219219 }
220220 }
221221
222222 function add_field( $table, $field, $patch, $fullpath=false ) {
223223 global $wgDatabase;
224224 if ( !$wgDatabase->tableExists( $table ) ) {
225 - echo "...$table table does not exist, skipping new field patch\n";
 225+ wfOut( "...$table table does not exist, skipping new field patch\n" );
226226 } elseif ( $wgDatabase->fieldExists( $table, $field ) ) {
227 - echo "...have $field field in $table table.\n";
 227+ wfOut( "...have $field field in $table table.\n" );
228228 } else {
229 - echo "Adding $field field to table $table...";
 229+ wfOut( "Adding $field field to table $table..." );
230230 if( $fullpath ) {
231231 dbsource( $patch, $wgDatabase );
232232 } else {
233233 dbsource( archive($patch), $wgDatabase );
234234 }
235 - echo "ok\n";
 235+ wfOut( "ok\n" );
236236 }
237237 }
238238
239239 function add_index( $table, $index, $patch, $fullpath=false ) {
240240 global $wgDatabase;
241241 if( $wgDatabase->indexExists( $table, $index ) ) {
242 - echo "...$index key already set on $table table.\n";
 242+ wfOut( "...$index key already set on $table table.\n" );
243243 } else {
244 - echo "Adding $index key to table $table... ";
 244+ wfOut( "Adding $index key to table $table... " );
245245 if( $fullpath ) {
246246 dbsource( $patch, $wgDatabase );
247247 } else {
248248 dbsource( archive($patch), $wgDatabase );
249249 }
250 - echo "ok\n";
 250+ wfOut( "ok\n" );
251251 }
252252 }
253253
@@ -262,11 +262,11 @@
263263
264264 global $wgDatabase;
265265 $fname = "Update script: update_passwords()";
266 - print "\nIt appears that you need to update the user passwords in your\n" .
 266+ wfOut( "\nIt appears that you need to update the user passwords in your\n" .
267267 "database. If you have already done this (if you've run this update\n" .
268268 "script once before, for example), doing so again will make all your\n" .
269269 "user accounts inaccessible, so be sure you only do this once.\n" .
270 - "Update user passwords? (yes/no)";
 270+ "Update user passwords? (yes/no)" );
271271
272272 $resp = readconsole();
273273 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
@@ -289,15 +289,15 @@
290290 # Check that interwiki table exists; if it doesn't source it
291291 global $wgDatabase, $IP;
292292 if( $wgDatabase->tableExists( "interwiki" ) ) {
293 - echo "...already have interwiki table\n";
 293+ wfOut( "...already have interwiki table\n" );
294294 return true;
295295 }
296 - echo "Creating interwiki table: ";
 296+ wfOut( "Creating interwiki table: " );
297297 dbsource( archive("patch-interwiki.sql") );
298 - echo "ok\n";
299 - echo "Adding default interwiki definitions: ";
 298+ wfOut( "ok\n" );
 299+ wfOut( "Adding default interwiki definitions: " );
300300 dbsource( "$IP/maintenance/interwiki.sql" );
301 - echo "ok\n";
 301+ wfOut( "ok\n" );
302302 }
303303
304304 function do_index_update() {
@@ -305,12 +305,12 @@
306306 global $wgDatabase;
307307 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
308308 if( !$meta->isMultipleKey() ) {
309 - echo "Updating indexes to 20031107: ";
 309+ wfOut( "Updating indexes to 20031107: " );
310310 dbsource( archive("patch-indexes.sql") );
311 - echo "ok\n";
 311+ wfOut( "ok\n" );
312312 return true;
313313 }
314 - echo "...indexes seem up to 20031107 standards\n";
 314+ wfOut( "...indexes seem up to 20031107 standards\n" );
315315 return false;
316316 }
317317
@@ -319,67 +319,67 @@
320320
321321 $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
322322 if( !$meta->isMultipleKey() ) {
323 - echo "Updating indexes to 20050912: ";
 323+ wfOut( "Updating indexes to 20050912: " );
324324 dbsource( archive("patch-mimesearch-indexes.sql") );
325 - echo "ok\n";
 325+ wfOut( "ok\n" );
326326 return true;
327327 }
328 - echo "...indexes seem up to 20050912 standards\n";
 328+ wfOut( "...indexes seem up to 20050912 standards\n" );
329329 return false;
330330 }
331331
332332 function do_image_name_unique_update() {
333333 global $wgDatabase;
334334 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
335 - echo "...image primary key already set.\n";
 335+ wfOut( "...image primary key already set.\n" );
336336 } else {
337 - echo "Making img_name the primary key... ";
 337+ wfOut( "Making img_name the primary key... " );
338338 dbsource( archive("patch-image_name_primary.sql"), $wgDatabase );
339 - echo "ok\n";
 339+ wfOut( "ok\n" );
340340 }
341341 }
342342
343343 function do_logging_timestamp_index() {
344344 global $wgDatabase;
345345 if( $wgDatabase->indexExists( 'logging', 'times' ) ) {
346 - echo "...timestamp key on logging already exists.\n";
 346+ wfOut( "...timestamp key on logging already exists.\n" );
347347 } else {
348 - echo "Adding timestamp key on logging table... ";
 348+ wfOut( "Adding timestamp key on logging table... " );
349349 dbsource( archive("patch-logging-times-index.sql"), $wgDatabase );
350 - echo "ok\n";
 350+ wfOut( "ok\n" );
351351 }
352352 }
353353
354354 function do_archive_user_index() {
355355 global $wgDatabase;
356356 if( $wgDatabase->indexExists( 'archive', 'usertext_timestamp' ) ) {
357 - echo "...usertext,timestamp key on archive already exists.\n";
 357+ wfOut( "...usertext,timestamp key on archive already exists.\n" );
358358 } else {
359 - echo "Adding usertext,timestamp key on archive table... ";
 359+ wfOut( "Adding usertext,timestamp key on archive table... " );
360360 dbsource( archive("patch-archive-user-index.sql"), $wgDatabase );
361 - echo "ok\n";
 361+ wfOut( "ok\n" );
362362 }
363363 }
364364
365365 function do_image_user_index() {
366366 global $wgDatabase;
367367 if( $wgDatabase->indexExists( 'image', 'img_usertext_timestamp' ) ) {
368 - echo "...usertext,timestamp key on image already exists.\n";
 368+ wfOut( "...usertext,timestamp key on image already exists.\n" );
369369 } else {
370 - echo "Adding usertext,timestamp key on image table... ";
 370+ wfOut( "Adding usertext,timestamp key on image table... " );
371371 dbsource( archive("patch-image-user-index.sql"), $wgDatabase );
372 - echo "ok\n";
 372+ wfOut( "ok\n" );
373373 }
374374 }
375375
376376 function do_oldimage_user_index() {
377377 global $wgDatabase;
378378 if( $wgDatabase->indexExists( 'oldimage', 'oi_usertext_timestamp' ) ) {
379 - echo "...usertext,timestamp key on oldimage already exists.\n";
 379+ wfOut( "...usertext,timestamp key on oldimage already exists.\n" );
380380 } else {
381 - echo "Adding usertext,timestamp key on oldimage table... ";
 381+ wfOut( "Adding usertext,timestamp key on oldimage table... " );
382382 dbsource( archive("patch-oldimage-user-index.sql"), $wgDatabase );
383 - echo "ok\n";
 383+ wfOut( "ok\n" );
384384 }
385385 }
386386
@@ -387,18 +387,18 @@
388388 global $wgDatabase;
389389 $fname = 'do_watchlist_update';
390390 if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
391 - echo "The watchlist table is already set up for email notification.\n";
 391+ wfOut( "The watchlist table is already set up for email notification.\n" );
392392 } else {
393 - echo "Adding wl_notificationtimestamp field for email notification management.";
 393+ wfOut( "Adding wl_notificationtimestamp field for email notification management." );
394394 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
395395 dbsource( archive( 'patch-email-notification.sql' ), $wgDatabase );
396 - echo "ok\n";
 396+ wfOut( "ok\n" );
397397 }
398398 # Check if we need to add talk page rows to the watchlist
399399 $talk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
400400 $nontalk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
401401 if ( $talk != $nontalk ) {
402 - echo "Adding missing watchlist talk page rows... ";
 402+ wfOut( "Adding missing watchlist talk page rows... " );
403403 flush();
404404
405405 $wgDatabase->insertSelect( 'watchlist', 'watchlist',
@@ -408,9 +408,9 @@
409409 'wl_title' => 'wl_title',
410410 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
411411 ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
412 - echo "ok\n";
 412+ wfOut( "ok\n" );
413413 } else {
414 - echo "...watchlist talk page rows already present\n";
 414+ wfOut( "...watchlist talk page rows already present\n" );
415415 }
416416 }
417417
@@ -421,7 +421,7 @@
422422 $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !',
423423 $wgDatabase->tableName( 'user_newtalk' ) );
424424 $num_newtalks=$wgDatabase->numRows($res);
425 - echo "Now converting ".$num_newtalks." user_newtalk entries to watchlist table entries ... \n";
 425+ wfOut( "Now converting $num_newtalks user_newtalk entries to watchlist table entries ... \n" );
426426
427427 $user = new User();
428428 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
@@ -449,18 +449,18 @@
450450 );
451451 }
452452 }
453 - echo "Done.\n";
 453+ wfOut( "Done.\n" );
454454 }
455455
456456
457457 function do_user_update() {
458458 global $wgDatabase;
459459 if( $wgDatabase->fieldExists( 'user', 'user_emailauthenticationtimestamp' ) ) {
460 - echo "User table contains old email authentication field. Dropping... ";
 460+ wfOut( "User table contains old email authentication field. Dropping... " );
461461 dbsource( archive( 'patch-email-authentication.sql' ), $wgDatabase );
462 - echo "ok\n";
 462+ wfOut( "ok\n" );
463463 } else {
464 - echo "...user table does not contain old email authentication field.\n";
 464+ wfOut( "...user table does not contain old email authentication field.\n" );
465465 }
466466 }
467467
@@ -478,11 +478,11 @@
479479 $wgDatabase->freeResult( $res );
480480
481481 if( in_array( 'binary', $flags ) ) {
482 - echo "$table table has correct $field encoding.\n";
 482+ wfOut( "$table table has correct $field encoding.\n" );
483483 } else {
484 - echo "Fixing $field encoding on $table table... ";
 484+ wfOut( "Fixing $field encoding on $table table... " );
485485 dbsource( archive( $patchFile ), $wgDatabase );
486 - echo "ok\n";
 486+ wfOut( "ok\n" );
487487 }
488488 }
489489
@@ -490,11 +490,11 @@
491491 global $wgDatabase;
492492 $fname="do_schema_restructuring";
493493 if ( $wgDatabase->tableExists( 'page' ) ) {
494 - echo "...page table already exists.\n";
 494+ wfOut( "...page table already exists.\n" );
495495 } else {
496 - echo "...converting from cur/old to page/revision/text DB structure.\n"; flush();
497 - echo wfTimestamp( TS_DB );
498 - echo "......checking for duplicate entries.\n"; flush();
 496+ wfOut( "...converting from cur/old to page/revision/text DB structure.\n" );
 497+ wfOut( wfTimestamp( TS_DB ) );
 498+ wfOut( "......checking for duplicate entries.\n" );
499499
500500 list ($cur, $old, $page, $revision, $text) = $wgDatabase->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
501501
@@ -502,15 +502,15 @@
503503 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
504504
505505 if ( $wgDatabase->numRows( $rows ) > 0 ) {
506 - echo wfTimestamp( TS_DB );
507 - echo "......<b>Found duplicate entries</b>\n";
508 - echo ( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
 506+ wfOut( wfTimestamp( TS_DB ) );
 507+ wfOut( "......<b>Found duplicate entries</b>\n" );
 508+ wfOut( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
509509 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
510510 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
511511 $duplicate[$row->cur_namespace] = array();
512512 }
513513 $duplicate[$row->cur_namespace][] = $row->cur_title;
514 - echo ( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
 514+ wfOut( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
515515 }
516516 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
517517 $firstCond = true;
@@ -550,13 +550,13 @@
551551 }
552552 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
553553 $rows = $wgDatabase->query( $sql, $fname );
554 - echo wfTimestamp( TS_DB );
555 - echo "......<b>Deleted</b> ".$wgDatabase->affectedRows()." records.\n";
 554+ wfOut( wfTimestamp( TS_DB ) );
 555+ wfOut( "......<b>Deleted</b> ".$wgDatabase->affectedRows()." records.\n" );
556556 }
557557
558558
559 - echo wfTimestamp( TS_DB );
560 - echo "......Creating tables.\n";
 559+ wfOut( wfTimestamp( TS_DB ) );
 560+ wfOut( "......Creating tables.\n" );
561561 $wgDatabase->query("CREATE TABLE $page (
562562 page_id int(8) unsigned NOT NULL auto_increment,
563563 page_namespace int NOT NULL,
@@ -594,26 +594,26 @@
595595 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
596596 ) ENGINE=InnoDB", $fname );
597597
598 - echo wfTimestamp( TS_DB );
599 - echo "......Locking tables.\n";
 598+ wfOut( wfTimestamp( TS_DB ) );
 599+ wfOut( "......Locking tables.\n" );
600600 $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
601601
602602 $maxold = intval( $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname ) );
603 - echo wfTimestamp( TS_DB );
604 - echo "......maxold is {$maxold}\n";
 603+ wfOut( wfTimestamp( TS_DB ) );
 604+ wfOut( "......maxold is {$maxold}\n" );
605605
606 - echo wfTimestamp( TS_DB );
 606+ wfOut( wfTimestamp( TS_DB ) );
607607 global $wgLegacySchemaConversion;
608608 if( $wgLegacySchemaConversion ) {
609609 // Create HistoryBlobCurStub entries.
610610 // Text will be pulled from the leftover 'cur' table at runtime.
611 - echo "......Moving metadata from cur; using blob references to text in cur table.\n";
 611+ wfOut( "......Moving metadata from cur; using blob references to text in cur table.\n" );
612612 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
613613 $cur_flags = "'object'";
614614 } else {
615615 // Copy all cur text in immediately: this may take longer but avoids
616616 // having to keep an extra table around.
617 - echo "......Moving text from cur.\n";
 617+ wfOut( "......Moving text from cur.\n" );
618618 $cur_text = 'cur_text';
619619 $cur_flags = "''";
620620 }
@@ -622,16 +622,16 @@
623623 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
624624 FROM $cur", $fname );
625625
626 - echo wfTimestamp( TS_DB );
627 - echo "......Setting up revision table.\n";
 626+ wfOut( wfTimestamp( TS_DB ) );
 627+ wfOut( "......Setting up revision table.\n" );
628628 $wgDatabase->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
629629 rev_minor_edit)
630630 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
631631 old_timestamp, old_minor_edit
632632 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
633633
634 - echo wfTimestamp( TS_DB );
635 - echo "......Setting up page table.\n";
 634+ wfOut( wfTimestamp( TS_DB ) );
 635+ wfOut( "......Setting up page table.\n" );
636636 $wgDatabase->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
637637 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
638638 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
@@ -639,38 +639,38 @@
640640 FROM $cur,$revision
641641 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
642642
643 - echo wfTimestamp( TS_DB );
644 - echo "......Unlocking tables.\n";
 643+ wfOut( wfTimestamp( TS_DB ) );
 644+ wfOut( "......Unlocking tables.\n" );
645645 $wgDatabase->query( "UNLOCK TABLES", $fname );
646646
647 - echo wfTimestamp( TS_DB );
648 - echo "......Renaming old.\n";
 647+ wfOut( wfTimestamp( TS_DB ) );
 648+ wfOut( "......Renaming old.\n" );
649649 $wgDatabase->query( "ALTER TABLE $old RENAME TO $text", $fname );
650650
651 - echo wfTimestamp( TS_DB );
652 - echo "...done.\n";
 651+ wfOut( wfTimestamp( TS_DB ) );
 652+ wfOut( "...done.\n" );
653653 }
654654 }
655655
656656 function do_inverse_timestamp() {
657657 global $wgDatabase;
658658 if( $wgDatabase->fieldExists( 'revision', 'inverse_timestamp' ) ) {
659 - echo "Removing revision.inverse_timestamp and fixing indexes... ";
 659+ wfOut( "Removing revision.inverse_timestamp and fixing indexes... " );
660660 dbsource( archive( 'patch-inverse_timestamp.sql' ), $wgDatabase );
661 - echo "ok\n";
 661+ wfOut( "ok\n" );
662662 } else {
663 - echo "revision timestamp indexes already up to 2005-03-13\n";
 663+ wfOut( "revision timestamp indexes already up to 2005-03-13\n" );
664664 }
665665 }
666666
667667 function do_text_id() {
668668 global $wgDatabase;
669669 if( $wgDatabase->fieldExists( 'revision', 'rev_text_id' ) ) {
670 - echo "...rev_text_id already in place.\n";
 670+ wfOut( "...rev_text_id already in place.\n" );
671671 } else {
672 - echo "Adding rev_text_id field... ";
 672+ wfOut( "Adding rev_text_id field... " );
673673 dbsource( archive( 'patch-rev_text_id.sql' ), $wgDatabase );
674 - echo "ok\n";
 674+ wfOut( "ok\n" );
675675 }
676676 }
677677
@@ -701,25 +701,25 @@
702702 $wgDatabase->freeResult( $result );
703703
704704 if( substr( $info->Type, 0, 3 ) == 'int' ) {
705 - echo "...$field is already a full int ($info->Type).\n";
 705+ wfOut( "...$field is already a full int ($info->Type).\n" );
706706 } else {
707 - echo "Promoting $field from $info->Type to int... ";
 707+ wfOut( "Promoting $field from $info->Type to int... " );
708708
709709 $sql = "ALTER TABLE $tablename MODIFY $field int NOT NULL";
710710 $wgDatabase->query( $sql );
711711
712 - echo "ok\n";
 712+ wfOut( "ok\n" );
713713 }
714714 }
715715
716716 function do_pagelinks_update() {
717717 global $wgDatabase;
718718 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
719 - echo "...already have pagelinks table.\n";
 719+ wfOut( "...already have pagelinks table.\n" );
720720 } else {
721 - echo "Converting links and brokenlinks tables to pagelinks... ";
 721+ wfOut( "Converting links and brokenlinks tables to pagelinks... " );
722722 dbsource( archive( 'patch-pagelinks.sql' ), $wgDatabase );
723 - echo "ok\n";
 723+ wfOut( "ok\n" );
724724 flush();
725725
726726 global $wgCanonicalNamespaceNames;
@@ -735,7 +735,7 @@
736736 global $wgDatabase, $wgContLang;
737737
738738 $ns = intval( $namespace );
739 - echo "Cleaning up broken links for namespace $ns... ";
 739+ wfOut( "Cleaning up broken links for namespace $ns... " );
740740
741741 $pagelinks = $wgDatabase->tableName( 'pagelinks' );
742742 $name = $wgContLang->getNsText( $ns );
@@ -749,25 +749,25 @@
750750 AND pl_title LIKE '$likeprefix:%'";
751751
752752 $wgDatabase->query( $sql, 'do_pagelinks_namespace' );
753 - echo "ok\n";
 753+ wfOut( "ok\n" );
754754 }
755755
756756 function do_drop_img_type() {
757757 global $wgDatabase;
758758
759759 if( $wgDatabase->fieldExists( 'image', 'img_type' ) ) {
760 - echo "Dropping unused img_type field in image table... ";
 760+ wfOut( "Dropping unused img_type field in image table... " );
761761 dbsource( archive( 'patch-drop_img_type.sql' ), $wgDatabase );
762 - echo "ok\n";
 762+ wfOut( "ok\n" );
763763 } else {
764 - echo "No img_type field in image table; Good.\n";
 764+ wfOut( "No img_type field in image table; Good.\n" );
765765 }
766766 }
767767
768768 function do_old_links_update() {
769769 global $wgDatabase;
770770 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
771 - echo "Already have pagelinks; skipping old links table updates.\n";
 771+ wfOut( "Already have pagelinks; skipping old links table updates.\n" );
772772 } else {
773773 convertLinks(); flush();
774774 }
@@ -777,14 +777,14 @@
778778 global $wgDatabase;
779779 $duper = new UserDupes( $wgDatabase );
780780 if( $duper->hasUniqueIndex() ) {
781 - echo "Already have unique user_name index.\n";
 781+ wfOut( "Already have unique user_name index.\n" );
782782 } else {
783783 if( !$duper->clearDupes() ) {
784 - echo "WARNING: This next step will probably fail due to unfixed duplicates...\n";
 784+ wfOut( "WARNING: This next step will probably fail due to unfixed duplicates...\n" );
785785 }
786 - echo "Adding unique index on user_name... ";
 786+ wfOut( "Adding unique index on user_name... " );
787787 dbsource( archive( 'patch-user_nameindex.sql' ), $wgDatabase );
788 - echo "ok\n";
 788+ wfOut( "ok\n" );
789789 }
790790 }
791791
@@ -793,28 +793,28 @@
794794 global $wgDatabase;
795795
796796 if( $wgDatabase->tableExists( 'user_groups' ) ) {
797 - echo "...user_groups table already exists.\n";
 797+ wfOut( "...user_groups table already exists.\n" );
798798 return do_user_groups_reformat();
799799 }
800800
801 - echo "Adding user_groups table... ";
 801+ wfOut( "Adding user_groups table... " );
802802 dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase );
803 - echo "ok\n";
 803+ wfOut( "ok\n" );
804804
805805 if( !$wgDatabase->tableExists( 'user_rights' ) ) {
806806 if( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) {
807 - echo "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion...";
 807+ wfOut( "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion..." );
808808 dbsource( archive( 'patch-user_rights.sql' ), $wgDatabase );
809 - echo "ok\n";
 809+ wfOut( "ok\n" );
810810 } else {
811 - echo "*** WARNING: couldn't locate user_rights table or field for upgrade.\n";
812 - echo "*** You may need to manually configure some sysops by manipulating\n";
813 - echo "*** the user_groups table.\n";
 811+ wfOut( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
 812+ wfOut( "*** You may need to manually configure some sysops by manipulating\n" );
 813+ wfOut( "*** the user_groups table.\n" );
814814 return;
815815 }
816816 }
817817
818 - echo "Converting user_rights table to user_groups... ";
 818+ wfOut( "Converting user_rights table to user_groups... " );
819819 $result = $wgDatabase->select( 'user_rights',
820820 array( 'ur_user', 'ur_rights' ),
821821 array( "ur_rights != ''" ),
@@ -834,7 +834,7 @@
835835 }
836836 }
837837 $wgDatabase->freeResult( $result );
838 - echo "ok\n";
 838+ wfOut( "ok\n" );
839839 }
840840
841841 function do_user_groups_reformat() {
@@ -845,20 +845,20 @@
846846 if( $info->type() == 'int' ) {
847847 $oldug = $wgDatabase->tableName( 'user_groups' );
848848 $newug = $wgDatabase->tableName( 'user_groups_bogus' );
849 - echo "user_groups is in bogus intermediate format. Renaming to $newug... ";
 849+ wfOut( "user_groups is in bogus intermediate format. Renaming to $newug... " );
850850 $wgDatabase->query( "ALTER TABLE $oldug RENAME TO $newug" );
851 - echo "ok\n";
 851+ wfOut( "ok\n" );
852852
853 - echo "Re-adding fresh user_groups table... ";
 853+ wfOut( "Re-adding fresh user_groups table... " );
854854 dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase );
855 - echo "ok\n";
 855+ wfOut( "ok\n" );
856856
857 - echo "***\n";
858 - echo "*** WARNING: You will need to manually fix up user permissions in the user_groups\n";
859 - echo "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n";
860 - echo "***\n";
 857+ wfOut( "***\n" );
 858+ wfOut( "*** WARNING: You will need to manually fix up user permissions in the user_groups\n" );
 859+ wfOut( "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n" );
 860+ wfOut( "***\n" );
861861 } else {
862 - echo "...user_groups is in current format.\n";
 862+ wfOut( "...user_groups is in current format.\n" );
863863 }
864864
865865 }
@@ -870,11 +870,11 @@
871871 $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
872872
873873 if( !$info->nullable() ) {
874 - echo "Making wl_notificationtimestamp nullable... ";
 874+ wfOut( "Making wl_notificationtimestamp nullable... " );
875875 dbsource( archive( 'patch-watchlist-null.sql' ), $wgDatabase );
876 - echo "ok\n";
 876+ wfOut( "ok\n" );
877877 } else {
878 - echo "...wl_notificationtimestamp is already nullable.\n";
 878+ wfOut( "...wl_notificationtimestamp is already nullable.\n" );
879879 }
880880
881881 }
@@ -885,13 +885,13 @@
886886 function do_page_random_update() {
887887 global $wgDatabase;
888888
889 - echo "Setting page_random to a random value on rows where it equals 0...";
 889+ wfOut( "Setting page_random to a random value on rows where it equals 0..." );
890890
891891 $page = $wgDatabase->tableName( 'page' );
892892 $wgDatabase->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
893893 $rows = $wgDatabase->affectedRows();
894894
895 - echo "changed $rows rows\n";
 895+ wfOut( "changed $rows rows\n" );
896896 }
897897
898898 function do_templatelinks_update() {
@@ -899,12 +899,12 @@
900900 $fname = 'do_templatelinks_update';
901901
902902 if ( $wgDatabase->tableExists( 'templatelinks' ) ) {
903 - echo "...templatelinks table already exists\n";
 903+ wfOut( "...templatelinks table already exists\n" );
904904 return;
905905 }
906 - echo "Creating templatelinks table...\n";
 906+ wfOut( "Creating templatelinks table...\n" );
907907 dbsource( archive('patch-templatelinks.sql'), $wgDatabase );
908 - echo "Populating...\n";
 908+ wfOut( "Populating...\n" );
909909 if ( isset( $wgLoadBalancer ) && $wgLoadBalancer->getServerCount() > 1 ) {
910910 // Slow, replication-friendly update
911911 $res = $wgDatabase->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
@@ -941,14 +941,14 @@
942942 ), $fname
943943 );
944944 }
945 - echo "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n";
 945+ wfOut( "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n" );
946946 }
947947
948948 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
949949 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
950950 function do_rc_indices_update() {
951951 global $wgDatabase;
952 - echo( "Checking for additional recent changes indices...\n" );
 952+ wfOut( "Checking for additional recent changes indices...\n" );
953953
954954 $indexes = array(
955955 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
@@ -958,59 +958,59 @@
959959 foreach( $indexes as $index => $patch ) {
960960 $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ );
961961 if( !$info ) {
962 - echo( "...index `{$index}` not found; adding..." );
 962+ wfOut( "...index `{$index}` not found; adding..." );
963963 dbsource( archive( $patch ) );
964 - echo( "done.\n" );
 964+ wfOut( "done.\n" );
965965 } else {
966 - echo( "...index `{$index}` seems ok.\n" );
 966+ wfOut( "...index `{$index}` seems ok.\n" );
967967 }
968968 }
969969 }
970970
971971 function index_has_field($table, $index, $field) {
972972 global $wgDatabase;
973 - echo( "Checking if $table index $index includes field $field...\n" );
 973+ wfOut( "Checking if $table index $index includes field $field...\n" );
974974 $info = $wgDatabase->indexInfo( $table, $index, __METHOD__ );
975975 if( $info ) {
976976 foreach($info as $row) {
977977 if($row->Column_name == $field) {
978 - echo( "...index $index on table $table seems to be ok\n" );
 978+ wfOut( "...index $index on table $table seems to be ok\n" );
979979 return true;
980980 }
981981 }
982982 }
983 - echo( "...index $index on table $table has no field $field; adding\n" );
 983+ wfOut( "...index $index on table $table has no field $field; adding\n" );
984984 return false;
985985 }
986986
987987 function do_backlinking_indices_update() {
988 - echo( "Checking for backlinking indices...\n" );
 988+ wfOut( "Checking for backlinking indices...\n" );
989989 if (!index_has_field('pagelinks', 'pl_namespace', 'pl_from') ||
990990 !index_has_field('templatelinks', 'tl_namespace', 'tl_from') ||
991991 !index_has_field('imagelinks', 'il_to', 'il_from'))
992992 {
993993 dbsource( archive( 'patch-backlinkindexes.sql' ) );
994 - echo( "...backlinking indices updated\n" );
 994+ wfOut( "...backlinking indices updated\n" );
995995 }
996996 }
997997
998998 function do_categorylinks_indices_update() {
999 - echo( "Checking for categorylinks indices...\n" );
 999+ wfOut( "Checking for categorylinks indices...\n" );
10001000 if (!index_has_field('categorylinks', 'cl_sortkey', 'cl_from'))
10011001 {
10021002 dbsource( archive( 'patch-categorylinksindex.sql' ) );
1003 - echo( "...categorylinks indices updated\n" );
 1003+ wfOut( "...categorylinks indices updated\n" );
10041004 }
10051005 }
10061006
10071007 function do_filearchive_indices_update() {
10081008 global $wgDatabase;
1009 - echo( "Checking filearchive indices...\n" );
 1009+ wfOut( "Checking filearchive indices...\n" );
10101010 $info = $wgDatabase->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
10111011 if ( !$info )
10121012 {
10131013 dbsource( archive( 'patch-filearhive-user-index.sql' ) );
1014 - echo( "...filearchive indices updated\n" );
 1014+ wfOut( "...filearchive indices updated\n" );
10151015 }
10161016 }
10171017
@@ -1019,25 +1019,25 @@
10201020 if ( !$wgDatabase->tableExists( 'profiling' ) ) {
10211021 // Simply ignore
10221022 } elseif ( $wgDatabase->fieldExists( 'profiling', 'pf_memory' ) ) {
1023 - echo "profiling table has pf_memory field.\n";
 1023+ wfOut( "profiling table has pf_memory field.\n" );
10241024 } else {
1025 - echo "Adding pf_memory field to table profiling...";
 1025+ wfOut( "Adding pf_memory field to table profiling..." );
10261026 dbsource( archive( 'patch-profiling-memory.sql' ), $wgDatabase );
1027 - echo "ok\n";
 1027+ wfOut( "ok\n" );
10281028 }
10291029 }
10301030
10311031 function do_stats_init() {
10321032 // Sometimes site_stats table is not properly populated.
10331033 global $wgDatabase;
1034 - echo "Checking site_stats row...";
 1034+ wfOut( "Checking site_stats row..." );
10351035 $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
10361036 if( $row === false ) {
1037 - echo "data is missing! rebuilding...\n";
 1037+ wfOut( "data is missing! rebuilding...\n" );
10381038 } elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
1039 - echo "missing ss_total_pages, rebuilding...\n";
 1039+ wfOut( "missing ss_total_pages, rebuilding...\n" );
10401040 } else {
1041 - echo "ok.\n";
 1041+ wfOut( "ok.\n" );
10421042 return;
10431043 }
10441044
@@ -1059,16 +1059,16 @@
10601060 array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
10611061 );
10621062 }
1063 - echo( "...ss_active_users user count set...\n" );
 1063+ wfOut( "...ss_active_users user count set...\n" );
10641064 }
10651065
10661066 function purge_cache() {
10671067 global $wgDatabase;
10681068 # We can't guarantee that the user will be able to use TRUNCATE,
10691069 # but we know that DELETE is available to us
1070 - echo( "Purging caches..." );
 1070+ wfOut( "Purging caches..." );
10711071 $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
1072 - echo( "done.\n" );
 1072+ wfOut( "done.\n" );
10731073 }
10741074
10751075 function do_all_updates( $shared = false, $purge = true ) {
@@ -1114,15 +1114,14 @@
11151115 }
11161116
11171117
1118 - echo "Deleting old default messages (this may take a long time!)..."; flush();
 1118+ wfOut( "Deleting old default messages (this may take a long time!)..." );
11191119 deleteDefaultMessages();
1120 - echo "Done\n"; flush();
 1120+ wfOut( "Done\n" );
11211121
1122 - do_stats_init(); flush();
 1122+ do_stats_init();
11231123
11241124 if( $purge ) {
11251125 purge_cache();
1126 - flush();
11271126 }
11281127 }
11291128
@@ -1147,14 +1146,14 @@
11481147 $patch2 = 'patch-page_restrictions_sortkey.sql';
11491148
11501149 if ( $wgDatabase->tableExists( $name ) ) {
1151 - echo "...$name table already exists.\n";
 1150+ wfOut( "...$name table already exists.\n" );
11521151 } else {
1153 - echo "Creating $name table...";
 1152+ wfOut( "Creating $name table..." );
11541153 dbsource( archive($patch), $wgDatabase );
11551154 dbsource( archive($patch2), $wgDatabase );
1156 - echo "ok\n";
 1155+ wfOut( "ok\n" );
11571156
1158 - echo "Migrating old restrictions to new table...";
 1157+ wfOut( "Migrating old restrictions to new table..." );
11591158
11601159 $res = $wgDatabase->select( 'page', array( 'page_id', 'page_restrictions' ), array("page_restrictions!=''", "page_restrictions!='edit=:move='"), __METHOD__ );
11611160
@@ -1206,27 +1205,27 @@
12071206 __METHOD__ );
12081207 }
12091208 }
1210 - print "ok\n";
 1209+ wfOut( "ok\n" );
12111210 }
12121211 }
12131212
12141213 function do_category_population() {
12151214 if( update_row_exists( 'populate category' ) ) {
1216 - echo "...category table already populated.\n";
 1215+ wfOut( "...category table already populated.\n" );
12171216 return;
12181217 }
12191218 require_once( 'populateCategory.inc' );
1220 - echo "Populating category table, printing progress markers. ".
 1219+ wfOut( "Populating category table, printing progress markers. " ).
12211220 "For large databases, you\n".
12221221 "may want to hit Ctrl-C and do this manually with maintenance/\n".
12231222 "populateCategory.php.\n";
12241223 populateCategory( '', 10, 0, true );
1225 - echo "Done populating category table.\n";
 1224+ wfOut( "Done populating category table.\n" );
12261225 }
12271226
12281227 function do_populate_parent_id() {
12291228 if( update_row_exists( 'populate rev_parent_id' ) ) {
1230 - echo "...rev_parent_id column already populated.\n";
 1229+ wfOut( "...rev_parent_id column already populated.\n" );
12311230 return;
12321231 }
12331232 require_once( 'populateParentId.inc' );
@@ -1237,11 +1236,11 @@
12381237
12391238 function update_password_format() {
12401239 if ( update_row_exists( 'password format' ) ) {
1241 - echo "...password hash format already changed\n";
 1240+ wfOut( "...password hash format already changed\n" );
12421241 return;
12431242 }
12441243
1245 - echo "Updating password hash format...";
 1244+ wfOut( "Updating password hash format..." );
12461245
12471246 global $wgDatabase, $wgPasswordSalt;
12481247 $user = $wgDatabase->tableName( 'user' );
@@ -1255,29 +1254,29 @@
12561255 $wgDatabase->query( $sql, __METHOD__ );
12571256 $wgDatabase->insert( 'updatelog', array( 'ul_key' => 'password format' ), __METHOD__ );
12581257
1259 - echo "done\n";
 1258+ wfOut( "done\n" );
12601259 }
12611260
12621261 function sqlite_initial_indexes() {
12631262 global $wgDatabase;
12641263 if ( update_row_exists( 'initial_indexes' ) ) {
1265 - echo "...have initial indexes\n";
 1264+ wfOut( "...have initial indexes\n" );
12661265 return;
12671266 }
1268 - echo "Adding initial indexes...";
 1267+ wfOut( "Adding initial indexes..." );
12691268 $wgDatabase->sourceFile( archive( 'initial-indexes.sql' ) );
1270 - echo "done\n";
 1269+ wfOut( "done\n" );
12711270 }
12721271
12731272 function do_unique_pl_tl_il() {
12741273 global $wgDatabase;
12751274 $info = $wgDatabase->indexInfo( 'pagelinks', 'pl_namespace' );
12761275 if( is_array($info) && !$info[0]->Non_unique ) {
1277 - echo "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n";
 1276+ wfOut( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
12781277 } else {
1279 - echo "Making pl_namespace, tl_namespace and il_to indices UNIQUE... ";
 1278+ wfOut( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
12801279 dbsource( archive( 'patch-pl-tl-il-unique.sql' ), $wgDatabase );
1281 - echo "ok\n";
 1280+ wfOut( "ok\n" );
12821281 }
12831282 }
12841283
@@ -1443,11 +1442,11 @@
14441443 $search_path = $conf['search_path'];
14451444 }
14461445 if( strpos( $search_path, $wgDBmwschema ) === false ) {
1447 - echo "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n";
 1446+ wfOut( "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n" );
14481447 $search_path = "$wgDBmwschema, $search_path";
14491448 }
14501449 if( strpos( $search_path, $wgDBts2schema ) === false ) {
1451 - echo "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n";
 1450+ wfOut( "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n" );
14521451 $search_path = "$search_path, $wgDBts2schema";
14531452 }
14541453 $search_path = str_replace( ', ,', ',', $search_path);
@@ -1457,7 +1456,7 @@
14581457 }
14591458 else {
14601459 $path = $conf['search_path'];
1461 - echo "... search_path for user \"$wgDBuser\" looks correct ($path)\n";
 1460+ wfOut( "... search_path for user \"$wgDBuser\" looks correct ($path)\n" );
14621461 }
14631462 $goodconf = array(
14641463 'client_min_messages' => 'error',
@@ -1467,12 +1466,12 @@
14681467 foreach( array_keys( $goodconf ) AS $key ) {
14691468 $value = $goodconf[$key];
14701469 if( !array_key_exists( $key, $conf ) or $conf[$key] !== $value ) {
1471 - echo "Setting $key to '$value' for user \"$wgDBuser\"\n";
 1470+ wfOut( "Setting $key to '$value' for user \"$wgDBuser\"\n" );
14721471 $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" );
14731472 $wgDatabase->doQuery( "SET $key = '$value'" );
14741473 }
14751474 else {
1476 - echo "... default value of \"$key\" is correctly set to \"$value\" for user \"$wgDBuser\"\n";
 1475+ wfOut( "... default value of \"$key\" is correctly set to \"$value\" for user \"$wgDBuser\"\n" );
14771476 }
14781477 }
14791478
@@ -1601,62 +1600,62 @@
16021601
16031602 foreach ($newsequences as $ns) {
16041603 if ($wgDatabase->sequenceExists($ns)) {
1605 - echo "... sequence \"$ns\" already exists\n";
 1604+ wfOut( "... sequence \"$ns\" already exists\n" );
16061605 continue;
16071606 }
16081607
1609 - echo "Creating sequence \"$ns\"\n";
 1608+ wfOut( "Creating sequence \"$ns\"\n" );
16101609 $wgDatabase->query("CREATE SEQUENCE $ns");
16111610 }
16121611
16131612 foreach ($newtables as $nt) {
16141613 if ($wgDatabase->tableExists($nt[0])) {
1615 - echo "... table \"$nt[0]\" already exists\n";
 1614+ wfOut( "... table \"$nt[0]\" already exists\n" );
16161615 continue;
16171616 }
16181617
1619 - echo "Creating table \"$nt[0]\"\n";
 1618+ wfOut( "Creating table \"$nt[0]\"\n" );
16201619 dbsource(archive($nt[1]));
16211620 }
16221621
16231622 ## Needed before newcols
16241623 if ($wgDatabase->tableExists("archive2")) {
1625 - echo "Converting \"archive2\" back to normal archive table\n";
 1624+ wfOut( "Converting \"archive2\" back to normal archive table\n" );
16261625 if ($wgDatabase->ruleExists("archive", "archive_insert")) {
1627 - echo "Dropping rule \"archive_insert\"\n";
 1626+ wfOut( "Dropping rule \"archive_insert\"\n" );
16281627 $wgDatabase->query("DROP RULE archive_insert ON archive");
16291628 }
16301629 if ($wgDatabase->ruleExists("archive", "archive_delete")) {
1631 - echo "Dropping rule \"archive_delete\"\n";
 1630+ wfOut( "Dropping rule \"archive_delete\"\n" );
16321631 $wgDatabase->query("DROP RULE archive_delete ON archive");
16331632 }
16341633 dbsource(archive("patch-remove-archive2.sql"));
16351634 }
16361635 else
1637 - echo "... obsolete table \"archive2\" does not exist\n";
 1636+ wfOut( "... obsolete table \"archive2\" does not exist\n" );
16381637
16391638 foreach ($newcols as $nc) {
16401639 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
16411640 if (!is_null($fi)) {
1642 - echo "... column \"$nc[0].$nc[1]\" already exists\n";
 1641+ wfOut( "... column \"$nc[0].$nc[1]\" already exists\n" );
16431642 continue;
16441643 }
16451644
1646 - echo "Adding column \"$nc[0].$nc[1]\"\n";
 1645+ wfOut( "Adding column \"$nc[0].$nc[1]\"\n" );
16471646 $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]");
16481647 }
16491648
16501649 foreach ($typechanges as $tc) {
16511650 $fi = $wgDatabase->fieldInfo($tc[0], $tc[1]);
16521651 if (is_null($fi)) {
1653 - echo "... error: expected column $tc[0].$tc[1] to exist\n";
 1652+ wfOut( "... error: expected column $tc[0].$tc[1] to exist\n" );
16541653 exit(1);
16551654 }
16561655
16571656 if ($fi->type() === $tc[2])
1658 - echo "... column \"$tc[0].$tc[1]\" is already of type \"$tc[2]\"\n";
 1657+ wfOut( "... column \"$tc[0].$tc[1]\" is already of type \"$tc[2]\"\n" );
16591658 else {
1660 - echo "Changing column type of \"$tc[0].$tc[1]\" from \"{$fi->type()}\" to \"$tc[2]\"\n";
 1659+ wfOut( "Changing column type of \"$tc[0].$tc[1]\" from \"{$fi->type()}\" to \"$tc[2]\"\n" );
16611660 $sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]";
16621661 if (strlen($tc[3])) {
16631662 $default = array();
@@ -1673,91 +1672,91 @@
16741673 }
16751674
16761675 if ($wgDatabase->fieldInfo('oldimage','oi_deleted')->type() !== 'smallint') {
1677 - echo "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n";
 1676+ wfOut( "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n" );
16781677 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
16791678 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
16801679 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
16811680 }
16821681 else
1683 - echo "... column \"oldimage.oi_deleted\" is already of type \"smallint\"\n";
 1682+ wfOut( "... column \"oldimage.oi_deleted\" is already of type \"smallint\"\n" );
16841683
16851684
16861685 foreach ($newindexes as $ni) {
16871686 if (pg_index_exists($ni[0], $ni[1])) {
1688 - echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
 1687+ wfOut( "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n" );
16891688 continue;
16901689 }
1691 - echo "Creating index \"$ni[1]\" on table \"$ni[0]\" $ni[2]\n";
 1690+ wfOut( "Creating index \"$ni[1]\" on table \"$ni[0]\" $ni[2]\n" );
16921691 $wgDatabase->query( "CREATE INDEX $ni[1] ON $ni[0] $ni[2]" );
16931692 }
16941693
16951694 foreach ($newrules as $nr) {
16961695 if ($wgDatabase->ruleExists($nr[0], $nr[1])) {
1697 - echo "... rule \"$nr[1]\" on table \"$nr[0]\" already exists\n";
 1696+ wfOut( "... rule \"$nr[1]\" on table \"$nr[0]\" already exists\n" );
16981697 continue;
16991698 }
1700 - echo "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n";
 1699+ wfOut( "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n" );
17011700 dbsource(archive($nr[2]));
17021701 }
17031702
17041703 if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) {
1705 - echo "Making foriegn key on table \"oldimage\" (to image) a cascade delete\n";
 1704+ wfOut( "Making foriegn key on table \"oldimage\" (to image) a cascade delete\n" );
17061705 $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
17071706 $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
17081707 "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE" );
17091708 }
17101709 else
1711 - echo "... table \"oldimage\" has correct cascade delete foreign key to image\n";
 1710+ wfOut( "... table \"oldimage\" has correct cascade delete foreign key to image\n" );
17121711
17131712 if (!$wgDatabase->triggerExists("page", "page_deleted")) {
1714 - echo "Adding function and trigger \"page_deleted\" to table \"page\"\n";
 1713+ wfOut( "Adding function and trigger \"page_deleted\" to table \"page\"\n" );
17151714 dbsource(archive('patch-page_deleted.sql'));
17161715 }
17171716 else
1718 - echo "... table \"page\" has \"page_deleted\" trigger\n";
 1717+ wfOut( "... table \"page\" has \"page_deleted\" trigger\n" );
17191718
17201719 $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id");
17211720 if (!$fi->nullable()) {
1722 - echo "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n";
 1721+ wfOut( "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n" );
17231722 dbsource(archive('patch-rc_cur_id-not-null.sql'));
17241723 }
17251724 else
1726 - echo "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n";
 1725+ wfOut( "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n" );
17271726
17281727 $pu = pg_describe_index("pagelink_unique");
17291728 if (!is_null($pu) && ($pu[0] != "pl_from" || $pu[1] != "pl_namespace" || $pu[2] != "pl_title")) {
1730 - echo "Dropping obsolete version of index \"pagelink_unique index\"\n";
 1729+ wfOut( "Dropping obsolete version of index \"pagelink_unique index\"\n" );
17311730 $wgDatabase->query("DROP INDEX pagelink_unique");
17321731 $pu = null;
17331732 }
17341733 else
1735 - echo "... obsolete version of index \"pagelink_unique index\" does not exist\n";
 1734+ wfOut( "... obsolete version of index \"pagelink_unique index\" does not exist\n" );
17361735
17371736 if (is_null($pu)) {
1738 - echo "Creating index \"pagelink_unique index\"\n";
 1737+ wfOut( "Creating index \"pagelink_unique index\"\n" );
17391738 $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
17401739 }
17411740 else
1742 - echo "... index \"pagelink_unique_index\" already exists\n";
 1741+ wfOut( "... index \"pagelink_unique_index\" already exists\n" );
17431742
17441743 if (pg_fkey_deltype("revision_rev_user_fkey") == 'r') {
1745 - echo "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n";
 1744+ wfOut( "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n" );
17461745 }
17471746 else {
1748 - echo "Changing constraint \"revision_rev_user_fkey\" to ON DELETE RESTRICT\n";
 1747+ wfOut( "Changing constraint \"revision_rev_user_fkey\" to ON DELETE RESTRICT\n" );
17491748 dbsource(archive('patch-revision_rev_user_fkey.sql'));
17501749 }
17511750
17521751 # Fix ipb_address index
17531752 if (pg_index_exists('ipblocks', 'ipb_address' )) {
1754 - echo "Removing deprecated index 'ipb_address'...\n";
 1753+ wfOut( "Removing deprecated index 'ipb_address'...\n" );
17551754 $wgDatabase->query('DROP INDEX ipb_address');
17561755 }
17571756 if (pg_index_exists('ipblocks', 'ipb_address_unique' )) {
1758 - echo "... have ipb_address_unique\n";
 1757+ wfOut( "... have ipb_address_unique\n" );
17591758 }
17601759 else {
1761 - echo "Adding ipb_address_unique index\n";
 1760+ wfOut( "Adding ipb_address_unique index\n" );
17621761 dbsource(archive('patch-ipb_address_unique.sql'));
17631762 }
17641763
@@ -1765,29 +1764,29 @@
17661765 # Add missing extension tables
17671766 foreach ( $wgExtNewTables as $nt ) {
17681767 if ($wgDatabase->tableExists($nt[0])) {
1769 - echo "... table \"$nt[0]\" already exists\n";
 1768+ wfOut( "... table \"$nt[0]\" already exists\n" );
17701769 continue;
17711770 }
1772 - echo "Creating table \"$nt[0]\"\n";
 1771+ wfOut( "Creating table \"$nt[0]\"\n" );
17731772 dbsource($nt[1]);
17741773 }
17751774 # Add missing extension fields
17761775 foreach ( $wgExtPGNewFields as $nc ) {
17771776 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
17781777 if (!is_null($fi)) {
1779 - echo "... column \"$nc[0].$nc[1]\" already exists\n";
 1778+ wfOut( "... column \"$nc[0].$nc[1]\" already exists\n" );
17801779 continue;
17811780 }
1782 - echo "Adding column \"$nc[0].$nc[1]\"\n";
 1781+ wfOut( "Adding column \"$nc[0].$nc[1]\"\n" );
17831782 $wgDatabase->query( "ALTER TABLE $nc[0] ADD $nc[1] $nc[2]" );
17841783 }
17851784 # Add missing extension indexes
17861785 foreach ( $wgExtNewIndexes as $ni ) {
17871786 if (pg_index_exists($ni[0], $ni[1])) {
1788 - echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
 1787+ wfOut( "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n" );
17891788 continue;
17901789 }
1791 - echo "Creating index \"$ni[1]\" on table \"$ni[0]\"\n";
 1790+ wfOut( "Creating index \"$ni[1]\" on table \"$ni[0]\"\n" );
17921791 dbsource($ni[2]);
17931792 }
17941793
Index: trunk/phase3/maintenance/userDupes.inc
@@ -45,7 +45,7 @@
4646 $fname = 'UserDupes::hasUniqueIndex';
4747 $info = $this->db->indexInfo( 'user', 'user_name', $fname );
4848 if( !$info ) {
49 - echo "WARNING: doesn't seem to have user_name index at all!\n";
 49+ wfOut( "WARNING: doesn't seem to have user_name index at all!\n" );
5050 return false;
5151 }
5252
@@ -92,11 +92,11 @@
9393
9494 $this->lock();
9595
96 - echo "Checking for duplicate accounts...\n";
 96+ wfOut( "Checking for duplicate accounts...\n" );
9797 $dupes = $this->getDupes();
9898 $count = count( $dupes );
9999
100 - echo "Found $count accounts with duplicate records on ".wfWikiID().".\n";
 100+ wfOut( "Found $count accounts with duplicate records on ".wfWikiID().".\n" );
101101 $this->trimmed = 0;
102102 $this->reassigned = 0;
103103 $this->failed = 0;
@@ -106,34 +106,34 @@
107107
108108 $this->unlock();
109109
110 - echo "\n";
 110+ wfOut( "\n" );
111111
112112 if( $this->reassigned > 0 ) {
113113 if( $doDelete ) {
114 - echo "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n";
 114+ wfOut( "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n" );
115115 } else {
116 - echo "$this->reassigned duplicate accounts need to have edits reassigned.\n";
 116+ wfOut( "$this->reassigned duplicate accounts need to have edits reassigned.\n" );
117117 }
118118 }
119119
120120 if( $this->trimmed > 0 ) {
121121 if( $doDelete ) {
122 - echo "$this->trimmed duplicate user records were deleted from ".wfWikiID().".\n";
 122+ wfOut( "$this->trimmed duplicate user records were deleted from ".wfWikiID().".\n" );
123123 } else {
124 - echo "$this->trimmed duplicate user accounts were found on ".wfWikiID()." which can be removed safely.\n";
 124+ wfOut( "$this->trimmed duplicate user accounts were found on ".wfWikiID()." which can be removed safely.\n" );
125125 }
126126 }
127127
128128 if( $this->failed > 0 ) {
129 - echo "Something terribly awry; $this->failed duplicate accounts were not removed.\n";
 129+ wfOut( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
130130 return false;
131131 }
132132
133133 if( $this->trimmed == 0 || $doDelete ) {
134 - echo "It is now safe to apply the unique index on user_name.\n";
 134+ wfOut( "It is now safe to apply the unique index on user_name.\n" );
135135 return true;
136136 } else {
137 - echo "Run this script again with the --fix option to automatically delete them.\n";
 137+ wfOut( "Run this script again with the --fix option to automatically delete them.\n" );
138138 return false;
139139 }
140140 }
@@ -215,36 +215,36 @@
216216
217217 $firstRow = $this->db->fetchObject( $result );
218218 $firstId = $firstRow->user_id;
219 - echo "Record that will be used for '$name' is user_id=$firstId\n";
 219+ wfOut( "Record that will be used for '$name' is user_id=$firstId\n" );
220220
221221 while( $row = $this->db->fetchObject( $result ) ) {
222222 $dupeId = $row->user_id;
223 - echo "... dupe id $dupeId: ";
 223+ wfOut( "... dupe id $dupeId: " );
224224 $edits = $this->editCount( $dupeId );
225225 if( $edits > 0 ) {
226226 $this->reassigned++;
227 - echo "has $edits edits! ";
 227+ wfOut( "has $edits edits! " );
228228 if( $doDelete ) {
229229 $this->reassignEdits( $dupeId, $firstId );
230230 $newEdits = $this->editCount( $dupeId );
231231 if( $newEdits == 0 ) {
232 - echo "confirmed cleaned. ";
 232+ wfOut( "confirmed cleaned. " );
233233 } else {
234234 $this->failed++;
235 - echo "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n";
 235+ wfOut( "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n" );
236236 continue;
237237 }
238238 } else {
239 - echo "(will need to reassign edits on fix)";
 239+ wfOut( "(will need to reassign edits on fix)" );
240240 }
241241 } else {
242 - echo "ok, no edits. ";
 242+ wfOut( "ok, no edits. " );
243243 }
244244 $this->trimmed++;
245245 if( $doDelete ) {
246246 $this->trimAccount( $dupeId );
247247 }
248 - echo "\n";
 248+ wfOut( "\n" );
249249 }
250250 $this->db->freeResult( $result );
251251 }
@@ -306,12 +306,12 @@
307307 */
308308 function reassignEditsOn( $table, $field, $from, $to ) {
309309 $fname = 'UserDupes::reassignEditsOn';
310 - echo "reassigning on $table... ";
 310+ wfOut( "reassigning on $table... " );
311311 $this->db->update( $table,
312312 array( $field => $to ),
313313 array( $field => $from ),
314314 $fname );
315 - echo "ok. ";
 315+ wfOut( "ok. " );
316316 }
317317
318318 /**
@@ -321,9 +321,9 @@
322322 */
323323 function trimAccount( $userid ) {
324324 $fname = 'UserDupes::trimAccount';
325 - echo "deleting...";
 325+ wfOut( "deleting..." );
326326 $this->db->delete( 'user', array( 'user_id' => $userid ), $fname );
327 - echo " ok";
 327+ wfOut( " ok" );
328328 }
329329
330330 }
Index: trunk/phase3/maintenance/populateParentId.inc
@@ -3,11 +3,11 @@
44 define( 'BATCH_SIZE', 200 );
55
66 function populate_rev_parent_id( $db ) {
7 - echo "Populating rev_parent_id column\n";
 7+ wfOut( "Populating rev_parent_id column\n" );
88 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
99 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
1010 if( is_null( $start ) || is_null( $end ) ){
11 - echo "...revision table seems to be empty.\n";
 11+ wfOut( "...revision table seems to be empty.\n" );
1212 $db->insert( 'updatelog',
1313 array( 'ul_key' => 'populate rev_parent_id' ),
1414 __FUNCTION__,
@@ -16,12 +16,12 @@
1717 }
1818 # Do remaining chunk
1919 $end += BATCH_SIZE - 1;
20 - $blockStart = $start;
21 - $blockEnd = $start + BATCH_SIZE - 1;
 20+ $blockStart = intval( $start );
 21+ $blockEnd = intval( $start ) + BATCH_SIZE - 1;
2222 $count = 0;
2323 $changed = 0;
2424 while( $blockEnd <= $end ) {
25 - echo "...doing rev_id from $blockStart to $blockEnd\n";
 25+ wfOut( "...doing rev_id from $blockStart to $blockEnd\n" );
2626 $cond = "rev_id BETWEEN $blockStart AND $blockEnd";
2727 $res = $db->select( 'revision',
2828 array('rev_id','rev_page','rev_timestamp','rev_parent_id'),
@@ -36,14 +36,14 @@
3737 # as timestamp can only decrease and never loops with IDs (from parent to parent)
3838 $previousID = $db->selectField( 'revision', 'rev_id',
3939 array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $row->rev_timestamp,
40 - "rev_id < {$row->rev_id}" ),
 40+ "rev_id < " . intval( $row->rev_id ) ),
4141 __FUNCTION__,
4242 array( 'ORDER BY' => 'rev_id DESC' ) );
4343 # If there are none, check the the highest ID with a lower timestamp
4444 if( !$previousID ) {
4545 # Get the highest older timestamp
4646 $lastTimestamp = $db->selectField( 'revision', 'rev_timestamp',
47 - array( 'rev_page' => $row->rev_page, "rev_timestamp < '{$row->rev_timestamp}'" ),
 47+ array( 'rev_page' => $row->rev_page, "rev_timestamp < " . $db->addQuotes( $row->rev_timestamp ) ),
4848 __FUNCTION__,
4949 array( 'ORDER BY' => 'rev_timestamp DESC' ) );
5050 # If there is one, let the highest rev ID win
@@ -73,10 +73,10 @@
7474 __FUNCTION__,
7575 'IGNORE' );
7676 if( $logged ) {
77 - echo "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n";
 77+ wfOut( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
7878 return true;
7979 } else {
80 - echo "Could not insert rev_parent_id population row.\n";
 80+ wfOut( "Could not insert rev_parent_id population row.\n" );
8181 return false;
8282 }
8383 }
Index: trunk/phase3/maintenance/convertLinks.inc
@@ -9,11 +9,11 @@
1010 function convertLinks() {
1111 global $wgDBtype;
1212 if( $wgDBtype == 'postgres' ) {
13 - print "Links table already ok on Postgres.\n";
 13+ wfOut( "Links table already ok on Postgres.\n" );
1414 return;
1515 }
1616
17 - print "Converting links table to ID-ID...\n";
 17+ wfOut( "Converting links table to ID-ID...\n" );
1818
1919 global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
2020 global $noKeys, $logPerformance, $fh;
@@ -48,7 +48,7 @@
4949
5050 $res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" );
5151 if ( $dbw->fieldType( $res, 0 ) == "int" ) {
52 - print "Schema already converted\n";
 52+ wfOut( "Schema already converted\n" );
5353 return;
5454 }
5555
@@ -58,13 +58,13 @@
5959 $dbw->freeResult( $res );
6060
6161 if ( $numRows == 0 ) {
62 - print "Updating schema (no rows to convert)...\n";
 62+ wfOut( "Updating schema (no rows to convert)...\n" );
6363 createTempTable();
6464 } else {
6565 if ( $logPerformance ) { $fh = fopen ( $perfLogFilename, "w" ); }
6666 $baseTime = $startTime = getMicroTime();
6767 # Create a title -> cur_id map
68 - print "Loading IDs from $cur table...\n";
 68+ wfOut( "Loading IDs from $cur table...\n" );
6969 performanceLog ( "Reading $numRows rows from cur table...\n" );
7070 performanceLog ( "rows read vs seconds elapsed:\n" );
7171
@@ -82,13 +82,13 @@
8383 if ($reportCurReadProgress) {
8484 if (($curRowsRead % $curReadReportInterval) == 0) {
8585 performanceLog( $curRowsRead . " " . (getMicroTime() - $baseTime) . "\n" );
86 - print "\t$curRowsRead rows of $cur table read.\n";
 86+ wfOut( "\t$curRowsRead rows of $cur table read.\n" );
8787 }
8888 }
8989 }
9090 $dbw->freeResult( $res );
9191 $dbw->bufferResults( true );
92 - print "Finished loading IDs.\n\n";
 92+ wfOut( "Finished loading IDs.\n\n" );
9393 performanceLog( "Took " . (getMicroTime() - $baseTime) . " seconds to load IDs.\n\n" );
9494 #--------------------------------------------------------------------
9595
@@ -97,7 +97,7 @@
9898 createTempTable();
9999 performanceLog( "Resetting timer.\n\n" );
100100 $baseTime = getMicroTime();
101 - print "Processing $numRows rows from $links table...\n";
 101+ wfOut( "Processing $numRows rows from $links table...\n" );
102102 performanceLog( "Processing $numRows rows from $links table...\n" );
103103 performanceLog( "rows inserted vs seconds elapsed:\n" );
104104
@@ -127,19 +127,19 @@
128128 }
129129 }
130130 $dbw->freeResult($res);
131 - #print "rowOffset: $rowOffset\ttuplesAdded: $tuplesAdded\tnumBadLinks: $numBadLinks\n";
 131+ #wfOut( "rowOffset: $rowOffset\ttuplesAdded: $tuplesAdded\tnumBadLinks: $numBadLinks\n" );
132132 if ( $tuplesAdded != 0 ) {
133133 if ($reportLinksConvProgress) {
134 - print "Inserting $tuplesAdded tuples into $links_temp...";
 134+ wfOut( "Inserting $tuplesAdded tuples into $links_temp..." );
135135 }
136136 $dbw->query( implode("",$sqlWrite) );
137137 $totalTuplesInserted += $tuplesAdded;
138138 if ($reportLinksConvProgress)
139 - print " done. Total $totalTuplesInserted tuples inserted.\n";
 139+ wfOut( " done. Total $totalTuplesInserted tuples inserted.\n" );
140140 performanceLog( $totalTuplesInserted . " " . (getMicroTime() - $baseTime) . "\n" );
141141 }
142142 }
143 - print "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n\n";
 143+ wfOut( "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n\n" );
144144 performanceLog( "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n" );
145145 performanceLog( "Total execution time: " . (getMicroTime() - $startTime) . " seconds.\n" );
146146 if ( $logPerformance ) { fclose ( $fh ); }
@@ -149,25 +149,25 @@
150150 if ( $overwriteLinksTable ) {
151151 $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
152152 if (!($dbConn->isOpen())) {
153 - print "Opening connection to database failed.\n";
 153+ wfOut( "Opening connection to database failed.\n" );
154154 return;
155155 }
156156 # Check for existing links_backup, and delete it if it exists.
157 - print "Dropping backup links table if it exists...";
 157+ wfOut( "Dropping backup links table if it exists..." );
158158 $dbConn->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER);
159 - print " done.\n";
 159+ wfOut( " done.\n" );
160160
161161 # Swap in the new table, and move old links table to links_backup
162 - print "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'...";
 162+ wfOut( "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." );
163163 $dbConn->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER );
164 - print " done.\n\n";
 164+ wfOut( " done.\n\n" );
165165
166166 $dbConn->close();
167 - print "Conversion complete. The old table remains at $links_backup;\n";
168 - print "delete at your leisure.\n";
 167+ wfOut( "Conversion complete. The old table remains at $links_backup;\n" );
 168+ wfOut( "delete at your leisure.\n" );
169169 } else {
170 - print "Conversion complete. The converted table is at $links_temp;\n";
171 - print "the original links table is unchanged.\n";
 170+ wfOut( "Conversion complete. The converted table is at $links_temp;\n" );
 171+ wfOut( "the original links table is unchanged.\n" );
172172 }
173173 }
174174
@@ -179,16 +179,16 @@
180180 $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
181181
182182 if (!($dbConn->isOpen())) {
183 - print "Opening connection to database failed.\n";
 183+ wfOut( "Opening connection to database failed.\n" );
184184 return;
185185 }
186186 $links_temp = $dbConn->tableName( 'links_temp' );
187187
188 - print "Dropping temporary links table if it exists...";
 188+ wfOut( "Dropping temporary links table if it exists..." );
189189 $dbConn->query( "DROP TABLE IF EXISTS $links_temp");
190 - print " done.\n";
 190+ wfOut( " done.\n" );
191191
192 - print "Creating temporary links table...";
 192+ wfOut( "Creating temporary links table..." );
193193 if ( $noKeys ) {
194194 $dbConn->query( "CREATE TABLE $links_temp ( " .
195195 "l_from int(8) unsigned NOT NULL default '0', " .
@@ -200,7 +200,7 @@
201201 "UNIQUE KEY l_from(l_from,l_to), " .
202202 "KEY (l_to))");
203203 }
204 - print " done.\n\n";
 204+ wfOut( " done.\n\n" );
205205 }
206206
207207 function performanceLog( $text ) {
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2955,6 +2955,21 @@
29562956 }
29572957 }
29582958
 2959+/**
 2960+ * Output some plain text in command-line mode or in the installer (updaters.inc).
 2961+ * Do not use it in any other context, its behaviour is subject to change.
 2962+ */
 2963+function wfOut( $s ) {
 2964+ static $lineStarted = false;
 2965+ global $wgCommandLineMode;
 2966+ if ( $wgCommandLineMode && !defined( 'MEDIAWIKI_INSTALL' ) ) {
 2967+ echo $s;
 2968+ } else {
 2969+ echo htmlspecialchars( $s );
 2970+ }
 2971+ flush();
 2972+}
 2973+
29592974 /** Generate a random 32-character hexadecimal token.
29602975 * @param mixed $salt Some sort of salt, if necessary, to add to random characters before hashing.
29612976 */
Index: trunk/phase3/config/index.php
@@ -92,7 +92,8 @@
9393 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
9494 <head>
9595 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
96 - <title>MediaWiki <?php echo( $wgVersion ); ?> Installation</title>
 96+ <meta name="robots" content="noindex,nofollow"/>
 97+ <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?> Installation</title>
9798 <style type="text/css">
9899
99100 @import "../skins/monobook/main.css";
@@ -210,7 +211,7 @@
211212 <div id="content">
212213 <div id="bodyContent">
213214
214 -<h1>MediaWiki <?php print $wgVersion ?> Installation</h1>
 215+<h1>MediaWiki <?php print htmlspecialchars( $wgVersion ) ?> Installation</h1>
215216
216217 <?php
217218 $mainListOpened = false; # Is the main list (environement checking) opend ? Used by dieout
@@ -310,7 +311,7 @@
311312 install_version_checks();
312313 $self = 'Installer'; # Maintenance script name, to please Setup.php
313314
314 -print "<li>PHP " . phpversion() . " installed</li>\n";
 315+print "<li>PHP " . htmlspecialchars( phpversion() ) . " installed</li>\n";
315316
316317 error_reporting( 0 );
317318 $phpdatabases = array();
@@ -410,7 +411,7 @@
411412 $conf->safeMode = false;
412413 }
413414
414 -$sapi = php_sapi_name();
 415+$sapi = htmlspecialchars( php_sapi_name() );
415416 print "<li>PHP server API is $sapi; ";
416417 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
417418 if( $wgUsePathInfo ) {
@@ -593,6 +594,9 @@
594595 : $_SERVER["SERVER_ADMIN"];
595596 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
596597 $conf->DBtype = importPost( "DBtype", $DefaultDBtype );
 598+ if ( !isset( $ourdb[$conf->DBtype] ) ) {
 599+ $conf->DBtype = $DefaultDBtype;
 600+ }
597601
598602 $conf->DBserver = importPost( "DBserver", "localhost" );
599603 $conf->DBname = importPost( "DBname", "wikidb" );
@@ -652,6 +656,8 @@
653657 }
654658 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
655659 $errs["DBprefix"] = "Invalid table prefix";
 660+} else {
 661+ untaint( $conf->DBprefix, TC_MYSQL );
656662 }
657663
658664 error_reporting( E_ALL );
@@ -728,7 +734,7 @@
729735 /* Test memcached servers */
730736
731737 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
732 - $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
 738+ $conf->MCServerArray = wfArrayMap( 'trim', explode( ',', $conf->MCServers ) );
733739 foreach ( $conf->MCServerArray as $server ) {
734740 $error = testMemcachedServer( $server );
735741 if ( $error ) {
@@ -781,7 +787,7 @@
782788 $errs["DBtype"] = "Unknown database type '$conf->DBtype'";
783789 continue;
784790 }
785 - print "<li>Database type: {$conf->DBtypename}</li>\n";
 791+ print "<li>Database type: " . htmlspecialchars( $conf->DBtypename ) . "</li>\n";
786792 $dbclass = 'Database'.ucfirst($conf->DBtype);
787793 $wgDBtype = $conf->DBtype;
788794 $wgDBadminuser = "root";
@@ -812,7 +818,7 @@
813819
814820 $wgTitle = Title::newFromText( "Installation script" );
815821 error_reporting( E_ALL );
816 - print "<li>Loading class: $dbclass</li>\n";
 822+ print "<li>Loading class: " . htmlspecialchars( $dbclass ) . "</li>\n";
817823 $dbc = new $dbclass;
818824
819825 if( $conf->DBtype == 'mysql' ) {
@@ -836,7 +842,7 @@
837843 }
838844
839845 # Attempt to connect
840 - echo( "<li>Attempting to connect to database server as $db_user..." );
 846+ echo( "<li>Attempting to connect to database server as " . htmlspecialchars( $db_user ) . "..." );
841847 $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
842848
843849 # Check the connection and respond to errors
@@ -871,7 +877,7 @@
872878 case 2003:
873879 default:
874880 # General connection problem
875 - echo( "failed with error [$errno] $errtx.</li>\n" );
 881+ echo( htmlspecialchars( "failed with error [$errno] $errtx." ) . "</li>\n" );
876882 $errs["DBserver"] = "Connection failed";
877883 break;
878884 } # switch
@@ -888,10 +894,11 @@
889895 $db_pass = $wgDBpassword;
890896 }
891897
892 - echo( "<li>Attempting to connect to database \"$wgDBname\" as \"$db_user\"..." );
 898+ echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
 899+ "\" as \"" . htmlspecialchars( $db_user ) . "\"..." );
893900 $wgDatabase = $dbc->newFromParams($wgDBserver, $db_user, $db_pass, $wgDBname, 1);
894901 if (!$wgDatabase->isOpen()) {
895 - print " error: " . $wgDatabase->lastError() . "</li>\n";
 902+ print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
896903 } else {
897904 $myver = $wgDatabase->getServerVersion();
898905 }
@@ -904,10 +911,11 @@
905912 // Changed !mysql to postgres check since it seems to only apply to postgres
906913 if( $useRoot && $conf->DBtype == 'postgres' ) {
907914 $wgDBsuperuser = $conf->RootUser;
908 - echo( "<li>Attempting to connect to database \"postgres\" as superuser \"$wgDBsuperuser\"..." );
 915+ echo( "<li>Attempting to connect to database \"postgres\" as superuser \"" .
 916+ htmlspecialchars( $wgDBsuperuser ) . "\"..." );
909917 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
910918 if (!$wgDatabase->isOpen()) {
911 - print " error: " . $wgDatabase->lastError() . "</li>\n";
 919+ print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
912920 $errs["DBserver"] = "Could not connect to database as superuser";
913921 $errs["RootUser"] = "Check username";
914922 $errs["RootPW"] = "and password";
@@ -915,10 +923,11 @@
916924 }
917925 $wgDatabase->initial_setup($conf->RootPW, 'postgres');
918926 }
919 - echo( "<li>Attempting to connect to database \"$wgDBname\" as \"$wgDBuser\"..." );
 927+ echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
 928+ "\" as \"" . htmlspecialchars( $wgDBuser ) . "\"..." );
920929 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
921930 if (!$wgDatabase->isOpen()) {
922 - print " error: " . $wgDatabase->lastError() . "</li>\n";
 931+ print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
923932 } else {
924933 $myver = $wgDatabase->getServerVersion();
925934 }
@@ -930,7 +939,7 @@
931940 continue;
932941 }
933942
934 - print "<li>Connected to {$conf->DBtype} $myver";
 943+ print "<li>Connected to " . htmlspecialchars( "{$conf->DBtype} $myver" );
935944 if ($conf->DBtype == 'mysql') {
936945 if( version_compare( $myver, "4.0.14" ) < 0 ) {
937946 print "</li>\n";
@@ -1017,15 +1026,19 @@
10181027 }
10191028 }
10201029 if ( $existingSchema && $existingSchema != $conf->DBschema ) {
1021 - print "<li><strong>Warning:</strong> you requested the {$conf->DBschema} schema, " .
1022 - "but the existing database has the $existingSchema schema. This upgrade script ".
1023 - "can't convert it, so it will remain $existingSchema.</li>\n";
 1030+ $encExisting = htmlspecialchars( $existingSchema );
 1031+ $encRequested = htmlspecialchars( $conf->DBschema );
 1032+ print "<li><strong>Warning:</strong> you requested the $encRequested schema, " .
 1033+ "but the existing database has the $encExisting schema. This upgrade script ".
 1034+ "can't convert it, so it will remain $encExisting.</li>\n";
10241035 $conf->setSchema( $existingSchema, $conf->DBengine );
10251036 }
10261037 if ( $existingEngine && $existingEngine != $conf->DBengine ) {
1027 - print "<li><strong>Warning:</strong> you requested the {$conf->DBengine} storage " .
1028 - "engine, but the existing database uses the $existingEngine engine. This upgrade " .
1029 - "script can't convert it, so it will remain $existingEngine.</li>\n";
 1038+ $encExisting = htmlspecialchars( $existingEngine );
 1039+ $encRequested = htmlspecialchars( $conf->DBengine );
 1040+ print "<li><strong>Warning:</strong> you requested the $encRequested storage " .
 1041+ "engine, but the existing database uses the $encExisting engine. This upgrade " .
 1042+ "script can't convert it, so it will remain $encExisting.</li>\n";
10301043 $conf->setSchema( $conf->DBschema, $existingEngine );
10311044 }
10321045 }
@@ -1066,7 +1079,8 @@
10671080 }
10681081 $wgDatabase->freeResult( $res );
10691082 if ( !$found && $conf->DBengine != 'MyISAM' ) {
1070 - echo "<li><strong>Warning:</strong> {$conf->DBengine} storage engine not available, " .
 1083+ echo "<li><strong>Warning:</strong> " . htmlspecialchars( $conf->DBengine ) .
 1084+ " storage engine not available, " .
10711085 "using MyISAM instead</li>\n";
10721086 $conf->setSchema( $conf->DBschema, 'MyISAM' );
10731087 }
@@ -1105,10 +1119,10 @@
11061120 if( $wgDatabase2->isOpen() ) {
11071121 # Nope, just close the test connection and continue
11081122 $wgDatabase2->close();
1109 - echo( "<li>User $wgDBuser exists. Skipping grants.</li>\n" );
 1123+ echo( "<li>User " . htmlspecialchars( $wgDBuser ) . " exists. Skipping grants.</li>\n" );
11101124 } else {
11111125 # Yes, so run the grants
1112 - echo( "<li>Granting user permissions to $wgDBuser on $wgDBname..." );
 1126+ echo( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
11131127 dbsource( "../maintenance/users.sql", $wgDatabase );
11141128 echo( "success.</li>\n" );
11151129 }
@@ -1213,7 +1227,9 @@
12141228 $list = getLanguageList();
12151229 foreach( $list as $code => $name ) {
12161230 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
1217 - echo "\n\t\t<option value=\"$code\" $sel>$name</option>";
 1231+ $encCode = htmlspecialchars( $code );
 1232+ $encName = htmlspecialchars( $name );
 1233+ echo "\n\t\t<option value=\"$encCode\" $sel>$encName</option>";
12181234 }
12191235 echo "\n";
12201236 ?>
@@ -1380,7 +1396,11 @@
13811397 <div class="config-section">
13821398 <div class="config-input">
13831399 <label class='column'>Database type:</label>
1384 -<?php if (isset($errs['DBpicktype'])) print "\t<span class='error'>$errs[DBpicktype]</span>\n"; ?>
 1400+<?php
 1401+ if (isset($errs['DBpicktype'])) {
 1402+ print "\t<span class='error'>" . htmlspecialchars( $errs[DBpicktype] ) . "</span>\n";
 1403+ }
 1404+?>
13851405 <ul class='plain'><?php
13861406 database_picker($conf);
13871407 ?></ul>
@@ -1524,7 +1544,7 @@
15251545 </div>
15261546 </form>
15271547 <script type="text/javascript">
1528 -window.onload = toggleDBarea('<?php echo $conf->DBtype; ?>',
 1548+window.onload = toggleDBarea('<?php echo htmlspecialchars( Xml::encodeJsVar( $conf->DBtype ) ); ?>',
15291549 <?php
15301550 ## If they passed in a root user name, don't populate it on page load
15311551 echo strlen(importPost('RootUser', '')) ? 0 : 1;
@@ -1656,7 +1676,7 @@
16571677 }
16581678
16591679 # Add slashes to strings for double quoting
1660 - $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
 1680+ $slconf = wfArrayMap( "escapePhpString", get_object_vars( $conf ) );
16611681 if( $conf->License == 'gfdl1_2' || $conf->License == 'pd' || $conf->License == 'gfdl1_3' ) {
16621682 # Needs literal string interpolation for the current style path
16631683 $slconf['RightsIcon'] = $conf->RightsIcon;
@@ -1841,6 +1861,7 @@
18421862 } else {
18431863 $retval = $default;
18441864 }
 1865+ taint( $retval );
18451866 return $retval;
18461867 }
18471868
@@ -1856,10 +1877,8 @@
18571878 return importVar( $_REQUEST, $name, $default );
18581879 }
18591880
1860 -$radioCount = 0;
1861 -
18621881 function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) {
1863 - global $radioCount;
 1882+ static $radioCount = 0;
18641883 if( $type != "" ) {
18651884 $xtype = "type=\"$type\"";
18661885 } else {
@@ -1899,7 +1918,9 @@
19001919 }
19011920
19021921 global $errs;
1903 - if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
 1922+ if(isset($errs[$field])) {
 1923+ echo "<span class='error'>" . htmlspecialchars( $errs[$field] ) . "</span>\n";
 1924+ }
19041925 }
19051926
19061927 function getLanguageList() {
@@ -2042,7 +2063,7 @@
20432064 return false;
20442065 }
20452066
2046 - $lines = array_map( 'trim', $lines );
 2067+ $lines = wfArrayMap( 'trim', $lines );
20472068 $candidatesByLocale = array();
20482069 $candidatesByLang = array();
20492070 foreach ( $lines as $line ) {
@@ -2086,6 +2107,17 @@
20872108 return false;
20882109 }
20892110
 2111+function wfArrayMap( $function, $input ) {
 2112+ $ret = array_map( $function, $input );
 2113+ foreach ( $ret as $key => $value ) {
 2114+ $taint = istainted( $input[$key] );
 2115+ if ( $taint ) {
 2116+ taint( $ret[$key], $taint );
 2117+ }
 2118+ }
 2119+ return $ret;
 2120+}
 2121+
20902122 ?>
20912123
20922124 <div class="license">

Follow-up revisions

RevisionCommit summaryAuthorDate
r46843(bug 17366) fix for r46840: Xml::encodeJsVar() already escapes and quotes $co...ialex11:59, 5 February 2009
r46891Backported r46840, r46843, r46889tstarling04:54, 6 February 2009
r46892Backported r46840, r46843, r46889 (installer XSS fixes)tstarling05:05, 6 February 2009
r46896Fixed missing quotes in r46840tstarling05:43, 6 February 2009
r46897Fixed missing quotes in r46840tstarling05:44, 6 February 2009
r46898Backported r46840, r46843, r46889 (installer XSS fixes)tstarling05:47, 6 February 2009
r46899Backported r46840, r46843, r46889 (installer XSS fixes)tstarling06:29, 6 February 2009

Status & tagging log