Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index e1a4dc6..552bec0 100644 (file)
@@ -104,7 +104,7 @@ abstract class Maintenance {
 
        /**
         * Used by getDB() / setDB()
-        * @var IDatabase
+        * @var Database
         */
        private $mDb = null;
 
@@ -459,7 +459,6 @@ abstract class Maintenance {
         * Add the default parameters to the scripts
         */
        protected function addDefaultParams() {
-
                # Generic (non script dependant) options:
 
                $this->addOption( 'help', 'Display this help message', false, false, 'h' );
@@ -546,7 +545,6 @@ abstract class Maintenance {
                                . "for this script to run: $joined. Please enable them and then try again.";
                        $this->error( $msg, 1 );
                }
-
        }
 
        /**
@@ -726,6 +724,7 @@ abstract class Maintenance {
 
                if ( is_array( $wgProfiler ) && isset( $wgProfiler['class'] ) ) {
                        $class = $wgProfiler['class'];
+                       /** @var Profiler $profiler */
                        $profiler = new $class(
                                [ 'sampling' => 1, 'output' => [ $output ] ]
                                        + $wgProfiler
@@ -1182,6 +1181,7 @@ abstract class Maintenance {
                $this->beginTransaction( $dbw, __METHOD__ );
 
                # Get "active" text records from the revisions table
+               $cur = [];
                $this->output( 'Searching for active text records in revisions table...' );
                $res = $dbw->select( 'revision', 'rev_text_id', [], __METHOD__, [ 'DISTINCT' ] );
                foreach ( $res as $row ) {
@@ -1316,7 +1316,7 @@ abstract class Maintenance {
 
        /**
         * Lock the search index
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function lockSearchindex( $db ) {
                $write = [ 'searchindex' ];
@@ -1334,7 +1334,7 @@ abstract class Maintenance {
 
        /**
         * Unlock the tables
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function unlockSearchindex( $db ) {
                $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
@@ -1343,7 +1343,7 @@ abstract class Maintenance {
        /**
         * Unlock and lock again
         * Since the lock is low-priority, queued reads will be able to complete
-        * @param DatabaseBase &$db
+        * @param Database &$db
         */
        private function relockSearchindex( $db ) {
                $this->unlockSearchindex( $db );
@@ -1354,7 +1354,7 @@ abstract class Maintenance {
         * Perform a search index update with locking
         * @param int $maxLockTime The maximum time to keep the search index locked.
         * @param string $callback The function that will update the function.
-        * @param DatabaseBase $dbw
+        * @param Database $dbw
         * @param array $results
         */
        public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) {
@@ -1390,7 +1390,7 @@ abstract class Maintenance {
 
        /**
         * Update the searchindex table for a given pageid
-        * @param DatabaseBase $dbw A database write handle
+        * @param Database $dbw A database write handle
         * @param int $pageId The page ID to update.
         * @return null|string
         */
@@ -1500,6 +1500,36 @@ abstract class Maintenance {
                return fgets( STDIN, 1024 );
        }
 
+       /**
+        * Get the terminal size as a two-element array where the first element
+        * is the width (number of columns) and the second element is the height
+        * (number of rows).
+        *
+        * @return array
+        */
+       public static function getTermSize() {
+               $default = [ 80, 50 ];
+               if ( wfIsWindows() ) {
+                       return $default;
+               }
+               // It's possible to get the screen size with VT-100 terminal escapes,
+               // but reading the responses is not possible without setting raw mode
+               // (unless you want to require the user to press enter), and that
+               // requires an ioctl(), which we can't do. So we have to shell out to
+               // something that can do the relevant syscalls. There are a few
+               // options. Linux and Mac OS X both have "stty size" which does the
+               // job directly.
+               $retval = false;
+               $size = wfShellExec( 'stty size', $retval );
+               if ( $retval !== 0 ) {
+                       return $default;
+               }
+               if ( !preg_match( '/^(\d+) (\d+)$/', $size, $m ) ) {
+                       return $default;
+               }
+               return [ intval( $m[2] ), intval( $m[1] ) ];
+       }
+
        /**
         * Call this to set up the autoloader to allow classes to be used from the
         * tests directory.