r51650 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51649‎ | r51650 | r51651 >
Date:17:04, 9 June 2009
Author:tstarling
Status:deferred
Tags:
Comment:
Changes related to update.php:
* Removed counter.php. Whoever heard of adding a file for a single line of code? Refactored the callers to GlobalFunctions.php wfCountDown().
* Removed the requirement for $wgDBadminuser to be set in update.php. There really is no security benefit, it's just there to annoy users and cause bugs like #19127. Just use $wgDBuser, commandLine.inc will automatically set it to $wgDBadminuser if it's available.
* Since we're using $wgDBuser now, we may as well just use wfGetDB(DB_MASTER) instead of the rubbish special-case code that was already there. There's no need for special-case error handling, there's already special-case code for command line connection errors, if you don't think that message is informative enough then you can change it there.
* Don't set $options before including commandLine.inc, it doesn't do anything.
* Use require not require_once
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/maintenance/counter.php (deleted) (history)
  • /trunk/phase3/maintenance/update.php (modified) (history)
  • /trunk/phase3/maintenance/userOptions.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/counter.php
@@ -1,12 +0,0 @@
2 -<?php
3 -/**
4 - * Helper file for update.php
5 - *
6 - * @file
7 - * @ingroup Maintenance
8 - */
9 -
10 -function print_c($last, $current) {
11 - echo str_repeat( chr(8), strlen( $last ) ) . $current;
12 -}
13 -
Index: trunk/phase3/maintenance/update.php
@@ -1,5 +1,4 @@
22 <?php
3 -require_once 'counter.php';
43 /**
54 * Run all updaters.
65 *
@@ -12,48 +11,24 @@
1312
1413 /** */
1514 $wgUseMasterForMaintenance = true;
16 -$options = array( 'quick', 'nopurge' );
17 -require_once( "commandLine.inc" );
18 -require_once( "updaters.inc" );
 15+require( "commandLine.inc" );
 16+require( "updaters.inc" );
1917 $wgTitle = Title::newFromText( "MediaWiki database updater" );
20 -$dbclass = 'Database' . ucfirst( $wgDBtype ) ;
2118
2219 echo( "MediaWiki {$wgVersion} Updater\n\n" );
2320
2421 install_version_checks();
2522
26 -# Do a pre-emptive check to ensure we've got credentials supplied
27 -# We can't, at this stage, check them, but we can detect their absence,
28 -# which seems to cause most of the problems people whinge about
29 -if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) {
30 - echo( "No superuser credentials could be found. Please provide the details\n" );
31 - echo( "of a user with appropriate permissions to update the database. See\n" );
32 - echo( "AdminSettings.sample for more details.\n\n" );
33 - exit(1);
34 -}
35 -
3623 # Attempt to connect to the database as a privileged user
3724 # This will vomit up an error if there are permissions problems
38 -$wgDatabase = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
 25+$wgDatabase = wfGetDB( DB_MASTER );
3926
40 -if( !$wgDatabase->isOpen() ) {
41 - # Appears to have failed
42 - echo( "A connection to the database could not be established. Check the\n" );
43 - echo( "values of \$wgDBadminuser and \$wgDBadminpassword.\n" );
44 - exit(1);
45 -}
46 -
4727 print "Going to run database updates for ".wfWikiID()."\n";
4828 print "Depending on the size of your database this may take a while!\n";
4929
5030 if( !isset( $options['quick'] ) ) {
5131 print "Abort with control-c in the next five seconds... ";
52 -
53 - for ($i = 6; $i >= 1;) {
54 - print_c($i, --$i);
55 - sleep(1);
56 - }
57 - echo "\n";
 32+ wfCountDown( 5 );
5833 }
5934
6035 $shared = isset( $options['doshared'] );
Index: trunk/phase3/maintenance/userOptions.inc
@@ -246,13 +246,7 @@
247247
248248 Abort with control-c in the next five seconds....
249249 WARN;
250 - require('counter.php');
251 - for ($i=6;$i>=1;) {
252 - print_c($i, --$i);
253 - sleep(1);
254 - }
255 - print "\n";
256 -
 250+ wfCountDown( 5 );
257251 return true;
258252 }
259253
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3084,6 +3084,24 @@
30853085 flush();
30863086 }
30873087
 3088+/**
 3089+ * Count down from $n to zero on the terminal, with a one-second pause
 3090+ * between showing each number. For use in command-line scripts.
 3091+ */
 3092+function wfCountDown( $n ) {
 3093+ for ( $i = $n; $i >= 0; $i-- ) {
 3094+ if ( $i != $n ) {
 3095+ echo str_repeat( "\x08", strlen( $i + 1 ) );
 3096+ }
 3097+ echo $i;
 3098+ flush();
 3099+ if ( $i ) {
 3100+ sleep( 1 );
 3101+ }
 3102+ }
 3103+ echo "\n";
 3104+}
 3105+
30883106 /** Generate a random 32-character hexadecimal token.
30893107 * @param mixed $salt Some sort of salt, if necessary, to add to random characters before hashing.
30903108 */

Status & tagging log