From 9177887791cb348a7458ddce21fbb6b124e0cdd8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 9 Jun 2009 17:04:16 +0000 Subject: [PATCH] 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 --- includes/GlobalFunctions.php | 18 ++++++++++++++++++ maintenance/counter.php | 12 ------------ maintenance/update.php | 33 ++++----------------------------- maintenance/userOptions.inc | 8 +------- 4 files changed, 23 insertions(+), 48 deletions(-) delete mode 100644 maintenance/counter.php diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3da139945b..0505f0ebf1 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3084,6 +3084,24 @@ function wfOut( $s ) { 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. */ diff --git a/maintenance/counter.php b/maintenance/counter.php deleted file mode 100644 index 67575ec1c5..0000000000 --- a/maintenance/counter.php +++ /dev/null @@ -1,12 +0,0 @@ -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); -} +$wgDatabase = wfGetDB( DB_MASTER ); 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'] ); diff --git a/maintenance/userOptions.inc b/maintenance/userOptions.inc index 00278f5188..da641b4b5b 100644 --- a/maintenance/userOptions.inc +++ b/maintenance/userOptions.inc @@ -246,13 +246,7 @@ Users with option <$this->mAnOption> = '$this->mOldValue' will be made to use '$ 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; } -- 2.20.1