Pass phpcs-strict on maintenance/ (5/8)
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index fb2cd8c..5c05b1e 100644 (file)
@@ -114,13 +114,6 @@ abstract class Maintenance {
         */
        public $fileHandle;
 
-       /**
-        * List of all the core maintenance scripts. This is added
-        * to scripts added by extensions in $wgMaintenanceScripts
-        * and returned by getMaintenanceScripts()
-        */
-       protected static $mCoreScripts = null;
-
        /**
         * Default constructor. Children should call this *first* if implementing
         * their own constructors
@@ -141,7 +134,7 @@ abstract class Maintenance {
         * as a standalone class? It checks that the call stack only includes this
         * function and "requires" (meaning was called from the file scope)
         *
-        * @return Boolean
+        * @return bool
         */
        public static function shouldExecute() {
                $bt = debug_backtrace();
@@ -170,11 +163,11 @@ abstract class Maintenance {
         * Add a parameter to the script. Will be displayed on --help
         * with the associated description
         *
-        * @param $name String: the name of the param (help, version, etc)
-        * @param $description String: the description of the param to show on --help
-        * @param $required Boolean: is the param required?
-        * @param $withArg Boolean: is an argument required with this option?
-        * @param $shortName String: character to use as short name
+        * @param string $name The name of the param (help, version, etc)
+        * @param string $description The description of the param to show on --help
+        * @param bool $required Is the param required?
+        * @param bool $withArg Is an argument required with this option?
+        * @param string $shortName Character to use as short name
         */
        protected function addOption( $name, $description, $required = false, $withArg = false, $shortName = false ) {
                $this->mParams[$name] = array( 'desc' => $description, 'require' => $required, 'withArg' => $withArg, 'shortName' => $shortName );
@@ -185,8 +178,8 @@ abstract class Maintenance {
 
        /**
         * Checks to see if a particular param exists.
-        * @param $name String: the name of the param
-        * @return Boolean
+        * @param string $name The name of the param
+        * @return bool
         */
        protected function hasOption( $name ) {
                return isset( $this->mOptions[$name] );
@@ -194,9 +187,9 @@ abstract class Maintenance {
 
        /**
         * Get an option, or return the default
-        * @param $name String: the name of the param
-        * @param $default Mixed: anything you want, default null
-        * @return Mixed
+        * @param string $name The name of the param
+        * @param mixed $default Anything you want, default null
+        * @return mixed
         */
        protected function getOption( $name, $default = null ) {
                if ( $this->hasOption( $name ) ) {
@@ -210,9 +203,9 @@ abstract class Maintenance {
 
        /**
         * Add some args that are needed
-        * @param $arg String: name of the arg, like 'start'
-        * @param $description String: short description of the arg
-        * @param $required Boolean: is this required?
+        * @param string $arg Name of the arg, like 'start'
+        * @param string $description Short description of the arg
+        * @param bool $required Is this required?
         */
        protected function addArg( $arg, $description, $required = true ) {
                $this->mArgList[] = array(
@@ -224,7 +217,7 @@ abstract class Maintenance {
 
        /**
         * Remove an option.  Useful for removing options that won't be used in your script.
-        * @param $name String: the option to remove.
+        * @param string $name The option to remove.
         */
        protected function deleteOption( $name ) {
                unset( $this->mParams[$name] );
@@ -232,7 +225,7 @@ abstract class Maintenance {
 
        /**
         * Set the description text.
-        * @param $text String: the text of the description
+        * @param string $text The text of the description
         */
        protected function addDescription( $text ) {
                $this->mDescription = $text;
@@ -240,8 +233,8 @@ abstract class Maintenance {
 
        /**
         * Does a given argument exist?
-        * @param $argId Integer: the integer value (from zero) for the arg
-        * @return Boolean
+        * @param int $argId The integer value (from zero) for the arg
+        * @return bool
         */
        protected function hasArg( $argId = 0 ) {
                return isset( $this->mArgs[$argId] );
@@ -249,8 +242,8 @@ abstract class Maintenance {
 
        /**
         * Get an argument.
-        * @param $argId Integer: the integer value (from zero) for the arg
-        * @param $default Mixed: the default if it doesn't exist
+        * @param int $argId The integer value (from zero) for the arg
+        * @param mixed $default The default if it doesn't exist
         * @return mixed
         */
        protected function getArg( $argId = 0, $default = null ) {
@@ -259,7 +252,7 @@ abstract class Maintenance {
 
        /**
         * Set the batch size.
-        * @param $s Integer: the number of operations to do in a batch
+        * @param int $s The number of operations to do in a batch
         */
        protected function setBatchSize( $s = 0 ) {
                $this->mBatchSize = $s;
@@ -281,7 +274,7 @@ abstract class Maintenance {
 
        /**
         * Get the script's name
-        * @return String
+        * @return string
         */
        public function getName() {
                return $this->mSelf;
@@ -289,10 +282,9 @@ abstract class Maintenance {
 
        /**
         * Return input from stdin.
-        * @param $len Integer: the number of bytes to read. If null,
-        *        just return the handle. Maintenance::STDIN_ALL returns
-        *        the full length
-        * @return Mixed
+        * @param int $len The number of bytes to read. If null, just return the handle.
+        *   Maintenance::STDIN_ALL returns the full length
+        * @return mixed
         */
        protected function getStdin( $len = null ) {
                if ( $len == Maintenance::STDIN_ALL ) {
@@ -317,9 +309,8 @@ abstract class Maintenance {
        /**
         * Throw some output to the user. Scripts can call this with no fears,
         * as we handle all --quiet stuff here
-        * @param $out String: the text to show to the user
-        * @param $channel Mixed: unique identifier for the channel. See
-        *     function outputChanneled.
+        * @param string $out The text to show to the user
+        * @param mixed $channel Unique identifier for the channel. See function outputChanneled.
         */
        protected function output( $out, $channel = null ) {
                if ( $this->mQuiet ) {
@@ -337,8 +328,8 @@ abstract class Maintenance {
        /**
         * Throw an error to the user. Doesn't respect --quiet, so don't use
         * this for non-error output
-        * @param $err String: the error to display
-        * @param $die Int: if > 0, go ahead and die out using this int as the code
+        * @param string $err The error to display
+        * @param int $die If > 0, go ahead and die out using this int as the code
         */
        protected function error( $err, $die = 0 ) {
                $this->outputChanneled( false );
@@ -370,8 +361,8 @@ abstract class Maintenance {
         * Message outputter with channeled message support. Messages on the
         * same channel are concatenated, but any intervening messages in another
         * channel start a new line.
-        * @param $msg String: the message without trailing newline
-        * @param $channel string Channel identifier or null for no
+        * @param string $msg The message without trailing newline
+        * @param string $channel Channel identifier or null for no
         *     channel. Channel comparison uses ===.
         */
        public function outputChanneled( $msg, $channel = null ) {
@@ -404,7 +395,7 @@ abstract class Maintenance {
         *    Maintenance::DB_NONE  -  For no DB access at all
         *    Maintenance::DB_STD   -  For normal DB access, default
         *    Maintenance::DB_ADMIN -  For admin DB access
-        * @return Integer
+        * @return int
         */
        public function getDbType() {
                return Maintenance::DB_STD;
@@ -447,9 +438,9 @@ abstract class Maintenance {
        /**
         * Run a child maintenance script. Pass all of the current arguments
         * to it.
-        * @param $maintClass String: a name of a child maintenance class
-        * @param $classFile String: full path of where the child is
-        * @return Maintenance child
+        * @param string $maintClass A name of a child maintenance class
+        * @param string $classFile Full path of where the child is
+        * @return Maintenance
         */
        public function runChild( $maintClass, $classFile = null ) {
                // Make sure the class is loaded first
@@ -570,9 +561,9 @@ abstract class Maintenance {
         * $mOptions becomes an array with keys set to the option names
         * $mArgs becomes a zero-based array containing the non-option arguments
         *
-        * @param $self String The name of the script, if any
-        * @param $opts Array An array of options, in form of key=>value
-        * @param $args Array An array of command line arguments
+        * @param string $self The name of the script, if any
+        * @param array $opts An array of options, in form of key=>value
+        * @param array $args An array of command line arguments
         */
        public function loadParamsAndArgs( $self = null, $opts = null, $args = null ) {
                # If we were given opts or args, set those and return early
@@ -715,7 +706,7 @@ abstract class Maintenance {
 
        /**
         * Maybe show the help.
-        * @param $force boolean Whether to force the help to show, default false
+        * @param bool $force Whether to force the help to show, default false
         */
        protected function maybeHelp( $force = false ) {
                if ( !$force && !$this->hasOption( 'help' ) ) {
@@ -915,7 +906,7 @@ abstract class Maintenance {
 
        /**
         * Generic setup for most installs. Returns the location of LocalSettings
-        * @return String
+        * @return string
         */
        public function loadSettings() {
                global $wgCommandLineMode, $IP;
@@ -947,7 +938,7 @@ abstract class Maintenance {
 
        /**
         * Support function for cleaning up redundant text records
-        * @param $delete Boolean: whether or not to actually delete the records
+        * @param bool $delete Whether or not to actually delete the records
         * @author Rob Church <robchur@gmail.com>
         */
        public function purgeRedundantText( $delete = true ) {
@@ -1007,52 +998,6 @@ abstract class Maintenance {
                return __DIR__;
        }
 
-       /**
-        * Get the list of available maintenance scripts. Note
-        * that if you call this _before_ calling doMaintenance
-        * you won't have any extensions in it yet
-        * @return Array
-        */
-       public static function getMaintenanceScripts() {
-               global $wgMaintenanceScripts;
-               return $wgMaintenanceScripts + self::getCoreScripts();
-       }
-
-       /**
-        * Return all of the core maintenance scripts
-        * @return array
-        */
-       protected static function getCoreScripts() {
-               if ( !self::$mCoreScripts ) {
-                       $paths = array(
-                               __DIR__,
-                               __DIR__ . '/language',
-                               __DIR__ . '/storage',
-                       );
-                       self::$mCoreScripts = array();
-                       foreach ( $paths as $p ) {
-                               $handle = opendir( $p );
-                               while ( ( $file = readdir( $handle ) ) !== false ) {
-                                       if ( $file == 'Maintenance.php' ) {
-                                               continue;
-                                       }
-                                       $file = $p . '/' . $file;
-                                       if ( is_dir( $file ) || !strpos( $file, '.php' ) ||
-                                               ( strpos( file_get_contents( $file ), '$maintClass' ) === false ) ) {
-                                               continue;
-                                       }
-                                       require $file;
-                                       $vars = get_defined_vars();
-                                       if ( array_key_exists( 'maintClass', $vars ) ) {
-                                               self::$mCoreScripts[$vars['maintClass']] = $file;
-                                       }
-                               }
-                               closedir( $handle );
-                       }
-               }
-               return self::$mCoreScripts;
-       }
-
        /**
         * Returns a database to be used by current maintenance script. It can be set by setDB().
         * If not set, wfGetDB() will be used.
@@ -1071,7 +1016,7 @@ abstract class Maintenance {
        /**
         * Sets database object to be returned by getDB().
         *
-        * @param $db DatabaseBase: Database object to be used
+        * @param DatabaseBase $db Database object to be used
         */
        public function setDB( &$db ) {
                $this->mDb = $db;
@@ -1079,7 +1024,7 @@ abstract class Maintenance {
 
        /**
         * Lock the search index
-        * @param &$db DatabaseBase object
+        * @param DatabaseBase &$db
         */
        private function lockSearchindex( &$db ) {
                $write = array( 'searchindex' );
@@ -1089,7 +1034,7 @@ abstract class Maintenance {
 
        /**
         * Unlock the tables
-        * @param &$db DatabaseBase object
+        * @param DatabaseBase &$db
         */
        private function unlockSearchindex( &$db ) {
                $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
@@ -1098,7 +1043,7 @@ abstract class Maintenance {
        /**
         * Unlock and lock again
         * Since the lock is low-priority, queued reads will be able to complete
-        * @param &$db DatabaseBase object
+        * @param DatabaseBase &$db
         */
        private function relockSearchindex( &$db ) {
                $this->unlockSearchindex( $db );
@@ -1107,10 +1052,10 @@ abstract class Maintenance {
 
        /**
         * Perform a search index update with locking
-        * @param $maxLockTime Integer: the maximum time to keep the search index locked.
-        * @param $callback callback String: the function that will update the function.
-        * @param $dbw DatabaseBase object
-        * @param $results
+        * @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 array $results
         */
        public function updateSearchIndex( $maxLockTime, $callback, $dbw, $results ) {
                $lockTime = time();
@@ -1146,8 +1091,8 @@ abstract class Maintenance {
 
        /**
         * Update the searchindex table for a given pageid
-        * @param $dbw DatabaseBase a database write handle
-        * @param $pageId Integer: the page ID to update.
+        * @param DatabaseBase $dbw A database write handle
+        * @param int $pageId The page ID to update.
         * @return null|string
         */
        public function updateSearchIndexForPage( $dbw, $pageId ) {
@@ -1171,7 +1116,7 @@ abstract class Maintenance {
         * We default as considering stdin a tty (for nice readline methods)
         * but treating stout as not a tty to avoid color codes
         *
-        * @param $fd int File descriptor
+        * @param int $fd File descriptor
         * @return bool
         */
        public static function posix_isatty( $fd ) {
@@ -1184,8 +1129,8 @@ abstract class Maintenance {
 
        /**
         * Prompt the console for input
-        * @param $prompt String what to begin the line with, like '> '
-        * @return String response
+        * @param string $prompt What to begin the line with, like '> '
+        * @return string Response
         */
        public static function readconsole( $prompt = '> ' ) {
                static $isatty = null;
@@ -1215,8 +1160,8 @@ abstract class Maintenance {
 
        /**
         * Emulate readline()
-        * @param $prompt String what to begin the line with, like '> '
-        * @return String
+        * @param string $prompt What to begin the line with, like '> '
+        * @return string
         */
        private static function readlineEmulation( $prompt ) {
                $bash = Installer::locateExecutableInDefaultPaths( array( 'bash' ) );
@@ -1294,7 +1239,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
 
        /**
         * Message to show that the update was done already and was just skipped
-        * @return String
+        * @return string
         */
        protected function updateSkippedMessage() {
                $key = $this->getUpdateKey();
@@ -1303,7 +1248,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
 
        /**
         * Message to show the the update log was unable to log the completion of this update
-        * @return String
+        * @return string
         */
        protected function updatelogFailedMessage() {
                $key = $this->getUpdateKey();
@@ -1313,13 +1258,13 @@ abstract class LoggedUpdateMaintenance extends Maintenance {
        /**
         * Do the actual work. All child classes will need to implement this.
         * Return true to log the update as done or false (usually on failure).
-        * @return Bool
+        * @return bool
         */
        abstract protected function doDBUpdates();
 
        /**
         * Get the update key name to go in the update log table
-        * @return String
+        * @return string
         */
        abstract protected function getUpdateKey();
 }