From: Max Semenik Date: Fri, 13 Oct 2017 00:24:46 +0000 (-0700) Subject: Move wfCountDown() into Maintenance class X-Git-Tag: 1.31.0-rc.0~1788^2 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=0392d9bb57d5663bcbb58ee03fcb01de9df53180;p=lhc%2Fweb%2Fwiklou.git Move wfCountDown() into Maintenance class Doing this allows to restrict it to maintenance scripts and support quiet mode. Change-Id: Iad0858ce1fdd64f746d5f9d4a7d6ed96f21e94df --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index 57cbec456d..efadf9abb1 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -44,6 +44,8 @@ changes to languages because of Phabricator reports. * MessageBlobStore::insertMessageBlob() (deprecated in 1.27) was removed. * The global function wfBCP47 was renamed to LanguageCode::bcp47. * The global function wfBCP47 is now deprecated. +* The global function wfCountDown() is now deprecated in favor of + Maintenance::countDown(). == Compatibility == MediaWiki 1.31 requires PHP 5.5.9 or later. There is experimental support for diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index d53e98dbe1..537a97ff9e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3047,6 +3047,8 @@ function wfWaitForSlaves( * Count down from $seconds to zero on the terminal, with a one-second pause * between showing each number. For use in command-line scripts. * + * @deprecated since 1.31, use Maintenance::countDown() + * * @codeCoverageIgnore * @param int $seconds */ diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index ecbbb85117..9a29055feb 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1416,6 +1416,32 @@ abstract class Maintenance { return $title; } + /** + * Count down from $seconds to zero on the terminal, with a one-second pause + * between showing each number. If the maintenance script is in quiet mode, + * this function does nothing. + * + * @since 1.31 + * + * @codeCoverageIgnore + * @param int $seconds + */ + protected function countDown( $seconds ) { + if ( $this->isQuiet() ) { + return; + } + for ( $i = $seconds; $i >= 0; $i-- ) { + if ( $i != $seconds ) { + $this->output( str_repeat( "\x08", strlen( $i + 1 ) ) ); + } + $this->output( $i ); + if ( $i ) { + sleep( 1 ); + } + } + $this->output( "\n" ); + } + /** * Wrapper for posix_isatty() * We default as considering stdin a tty (for nice readline methods) diff --git a/maintenance/resetUserTokens.php b/maintenance/resetUserTokens.php index 481da980da..1c8b4b9d0b 100644 --- a/maintenance/resetUserTokens.php +++ b/maintenance/resetUserTokens.php @@ -64,7 +64,7 @@ class ResetUserTokens extends Maintenance { $this->output( "\n" ); $this->output( "Abort with control-c in the next five seconds " . "(skip this countdown with --nowarn) ... " ); - wfCountDown( 5 ); + $this->countDown( 5 ); } // We list user by user_id from one of the replica DBs diff --git a/maintenance/update.php b/maintenance/update.php index 5f705ba371..5e2947b2db 100755 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -128,7 +128,7 @@ class UpdateMediaWiki extends Maintenance { $this->compatChecks(); } else { $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" ); - wfCountDown( 5 ); + $this->countDown( 5 ); } // Check external dependencies are up to date @@ -155,7 +155,7 @@ class UpdateMediaWiki extends Maintenance { if ( !$this->hasOption( 'quick' ) ) { $this->output( "Abort with control-c in the next five seconds " . "(skip this countdown with --quick) ... " ); - wfCountDown( 5 ); + $this->countDown( 5 ); } $time1 = microtime( true );