Merge "(bug 42915) make MovePage aware of whether redirects are supported."
[lhc/web/wiklou.git] / maintenance / userOptions.inc
index bfc8e8e..2a06657 100644 (file)
@@ -1,5 +1,22 @@
 <?php
 /**
+ * Helper class for userOptions.php script.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Maintenance
  */
@@ -8,7 +25,7 @@
 $options = array( 'list', 'nowarn', 'quiet', 'usage', 'dry' );
 $optionsWithArgs = array( 'old', 'new' );
 
-require_once( dirname( __FILE__ ) . '/commandLine.inc' );
+require_once( __DIR__ . '/commandLine.inc' );
 
 /**
  * @ingroup Maintenance
@@ -33,7 +50,14 @@ class userOptions {
        }
 
 
-       /** This is used to check options. Only needed on construction */
+       /**
+        * This is used to check options. Only needed on construction
+        *
+        * @param $opts array
+        * @param $args array
+        *
+        * @return bool
+        */
        private function checkOpts( $opts, $args ) {
                // The three possible ways to run the script:
                $list   = isset( $opts['list'] );
@@ -46,7 +70,14 @@ class userOptions {
                return $isValid;
        }
 
-       /** load script options in the object */
+       /**
+        * load script options in the object
+        *
+        * @param $opts array
+        * @param $args array
+        *
+        * @return bool
+        */
        private function initializeOpts( $opts, $args ) {
 
                $this->mQuick = isset( $opts['nowarn'] );
@@ -77,13 +108,13 @@ class userOptions {
                        return false;
                }
 
-               $this-> { $this->mMode } ( );
-
+               $this->{ $this->mMode } ( );
+               return true;
        }
 
        #
        # Modes.
-       # 
+       #
 
        /** List default options and their value */
        private function LISTER( ) {
@@ -111,7 +142,7 @@ class userOptions {
                        __METHOD__
                        );
 
-               while ( $id = $dbr->fetchObject( $result ) ) {
+               foreach ( $result as $id ) {
 
                        $user = User::newFromId( $id->user_id );
 
@@ -161,7 +192,7 @@ class userOptions {
                        __METHOD__
                        );
 
-               while ( $id = $dbr->fetchObject( $result ) ) {
+               foreach ( $result as $id ) {
 
                        $user = User::newFromId( $id->user_id );
 
@@ -174,7 +205,7 @@ class userOptions {
                                        print "Setting {$this->mAnOption} for $username from '{$this->mOldValue}' to '{$this->mNewValue}'): ";
                                }
 
-                               // Change value 
+                               // Change value
                                $user->setOption( $this->mAnOption, $this->mNewValue );
 
                                // Will not save the settings if run with --dry
@@ -189,8 +220,10 @@ class userOptions {
                }
        }
 
-
-       /** Return an array of option names */
+       /**
+        * Return an array of option names
+        * @return array
+        */
        public static function getDefaultOptionsNames() {
                $def = User::getDefaultOptions();
                $ret = array();
@@ -200,7 +233,6 @@ class userOptions {
                return $ret;
        }
 
-
        #
        # Helper methods
        #
@@ -212,28 +244,31 @@ This script pass through all users and change one of their options.
 The new option is NOT validated.
 
 Usage:
-    php userOptions.php --list
-    php userOptions.php [user option] --usage
-    php userOptions.php [options] <user option> --old <old value> --new <new value>
+       php userOptions.php --list
+       php userOptions.php [user option] --usage
+       php userOptions.php [options] <user option> --old <old value> --new <new value>
 
 Switchs:
-    --list : list available user options and their default value
+       --list : list available user options and their default value
 
-    --usage : report all options statistics or just one if you specify it.
+       --usage : report all options statistics or just one if you specify it.
 
-    --old <old value> : the value to look for
-    --new <new value> : new value to update users with
+       --old <old value> : the value to look for
+       --new <new value> : new value to update users with
 
 Options:
-    --nowarn: hides the 5 seconds warning
-    --quiet : do not print what is happening
-    --dry   : do not save user settings back to database
+       --nowarn: hides the 5 seconds warning
+       --quiet : do not print what is happening
+       --dry   : do not save user settings back to database
 
 USAGE;
-    exit( 0 );
+       exit( 0 );
        }
 
-       /** The warning message and countdown */
+       /**
+        * The warning message and countdown
+        * @return bool
+        */
        public function warn() {
 
                if ( $this->mQuick ) {