Move wfCountDown() into Maintenance class
authorMax Semenik <maxsem.wiki@gmail.com>
Fri, 13 Oct 2017 00:24:46 +0000 (17:24 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Fri, 13 Oct 2017 00:24:46 +0000 (17:24 -0700)
Doing this allows to restrict it to maintenance scripts and support
quiet mode.

Change-Id: Iad0858ce1fdd64f746d5f9d4a7d6ed96f21e94df

RELEASE-NOTES-1.31
includes/GlobalFunctions.php
maintenance/Maintenance.php
maintenance/resetUserTokens.php
maintenance/update.php

index 57cbec4..efadf9a 100644 (file)
@@ -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
index d53e98d..537a97f 100644 (file)
@@ -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
  */
index ecbbb85..9a29055 100644 (file)
@@ -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)
index 481da98..1c8b4b9 100644 (file)
@@ -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
index 5f705ba..5e2947b 100755 (executable)
@@ -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 );