Revision: 51650
Author:   tstarling
Date:     2009-06-09 17:04:16 +0000 (Tue, 09 Jun 2009)

Log Message:
-----------
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
    trunk/phase3/maintenance/update.php
    trunk/phase3/maintenance/userOptions.inc

Removed Paths:
-------------
    trunk/phase3/maintenance/counter.php

Modified: trunk/phase3/includes/GlobalFunctions.php
===================================================================
--- trunk/phase3/includes/GlobalFunctions.php   2009-06-09 16:37:58 UTC (rev 
51649)
+++ trunk/phase3/includes/GlobalFunctions.php   2009-06-09 17:04:16 UTC (rev 
51650)
@@ -3084,6 +3084,24 @@
        flush();
 }
 
+/**
+ * Count down from $n to zero on the terminal, with a one-second pause 
+ * between showing each number. For use in command-line scripts.
+ */
+function wfCountDown( $n ) {
+       for ( $i = $n; $i >= 0; $i-- ) {
+               if ( $i != $n ) {
+                       echo str_repeat( "\x08", strlen( $i + 1 ) );
+               } 
+               echo $i;
+               flush();
+               if ( $i ) {
+                       sleep( 1 );
+               }
+       }
+       echo "\n";
+}
+
 /** Generate a random 32-character hexadecimal token.
  * @param mixed $salt Some sort of salt, if necessary, to add to random 
characters before hashing.
  */

Deleted: trunk/phase3/maintenance/counter.php
===================================================================
--- trunk/phase3/maintenance/counter.php        2009-06-09 16:37:58 UTC (rev 
51649)
+++ trunk/phase3/maintenance/counter.php        2009-06-09 17:04:16 UTC (rev 
51650)
@@ -1,12 +0,0 @@
-<?php
-/**
- * Helper file for update.php
- *
- * @file
- * @ingroup Maintenance
- */
-
-function print_c($last, $current) {
-       echo str_repeat( chr(8), strlen( $last ) ) . $current;
-}
-

Modified: trunk/phase3/maintenance/update.php
===================================================================
--- trunk/phase3/maintenance/update.php 2009-06-09 16:37:58 UTC (rev 51649)
+++ trunk/phase3/maintenance/update.php 2009-06-09 17:04:16 UTC (rev 51650)
@@ -1,5 +1,4 @@
 <?php
-require_once 'counter.php';
 /**
  * Run all updaters.
  *
@@ -12,48 +11,24 @@
 
 /** */
 $wgUseMasterForMaintenance = true;
-$options = array( 'quick', 'nopurge' );
-require_once( "commandLine.inc" );
-require_once( "updaters.inc" );
+require( "commandLine.inc" );
+require( "updaters.inc" );
 $wgTitle = Title::newFromText( "MediaWiki database updater" );
-$dbclass = 'Database' . ucfirst( $wgDBtype ) ;
 
 echo( "MediaWiki {$wgVersion} Updater\n\n" );
 
 install_version_checks();
 
-# Do a pre-emptive check to ensure we've got credentials supplied
-# We can't, at this stage, check them, but we can detect their absence,
-# which seems to cause most of the problems people whinge about
-if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) {
-       echo( "No superuser credentials could be found. Please provide the 
details\n" );
-       echo( "of a user with appropriate permissions to update the database. 
See\n" );
-       echo( "AdminSettings.sample for more details.\n\n" );
-       exit(1);
-}
-
 # Attempt to connect to the database as a privileged user
 # This will vomit up an error if there are permissions problems
-$wgDatabase = new $dbclass( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, 
$wgDBname, 1 );
+$wgDatabase = wfGetDB( DB_MASTER );
 
-if( !$wgDatabase->isOpen() ) {
-       # Appears to have failed
-       echo( "A connection to the database could not be established. Check 
the\n" );
-       echo( "values of \$wgDBadminuser and \$wgDBadminpassword.\n" );
-       exit(1);
-}
-
 print "Going to run database updates for ".wfWikiID()."\n";
 print "Depending on the size of your database this may take a while!\n";
 
 if( !isset( $options['quick'] ) ) {
        print "Abort with control-c in the next five seconds... ";
-
-       for ($i = 6; $i >= 1;) {
-               print_c($i, --$i);
-               sleep(1);
-       }
-       echo "\n";
+       wfCountDown( 5 );
 }
 
 $shared = isset( $options['doshared'] );

Modified: trunk/phase3/maintenance/userOptions.inc
===================================================================
--- trunk/phase3/maintenance/userOptions.inc    2009-06-09 16:37:58 UTC (rev 
51649)
+++ trunk/phase3/maintenance/userOptions.inc    2009-06-09 17:04:16 UTC (rev 
51650)
@@ -246,13 +246,7 @@
 
 Abort with control-c in the next five seconds....
 WARN;
-               require('counter.php');
-               for ($i=6;$i>=1;) {
-                       print_c($i, --$i);
-                       sleep(1);
-               }
-               print "\n";
-
+               wfCountDown( 5 );
                return true;
        }
 



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to