X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FuserOptions.inc;h=4b0a817b5b164b6c289368a5352b5d6e3643bf8c;hb=8dc51b09120a83e8aa6f255781609a12f46412ec;hp=5d113526f2c2148cc53207d4434c83f067123141;hpb=d89467e2af726ac08e32d0201e75712151e2273f;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/userOptions.inc b/maintenance/userOptions.inc index 5d113526f2..4b0a817b5b 100644 --- a/maintenance/userOptions.inc +++ b/maintenance/userOptions.inc @@ -22,8 +22,8 @@ */ // Options we will use -$options = array( 'list', 'nowarn', 'quiet', 'usage', 'dry' ); -$optionsWithArgs = array( 'old', 'new' ); +$options = [ 'list', 'nowarn', 'quiet', 'usage', 'dry' ]; +$optionsWithArgs = [ 'old', 'new' ]; require_once __DIR__ . '/commandLine.inc'; @@ -40,7 +40,11 @@ class UserOptions { private $mMode, $mReady; - /** Constructor. Will show usage and exit if script options are not correct */ + /** + * Constructor. Will show usage and exit if script options are not correct + * @param array $opts + * @param array $args + */ function __construct( $opts, $args ) { if ( !$this->checkOpts( $opts, $args ) ) { UserOptions::showUsageAndExit(); @@ -101,21 +105,22 @@ class UserOptions { return true; } - // Dumb stuff to run a mode. + /** + * Dumb stuff to run a mode. + */ public function run() { if ( !$this->mReady ) { return false; } - $this->{ $this->mMode } (); + $this->{$this->mMode}(); + return true; } - # - # Modes. - # - - /** List default options and their value */ + /** + * List default options and their value + */ private function LISTER() { $def = User::getDefaultOptions(); ksort( $def ); @@ -128,18 +133,20 @@ class UserOptions { } } - /** List options usage */ + /** + * List options usage + */ private function USAGER() { - $ret = array(); + $ret = []; $defaultOptions = User::getDefaultOptions(); // We list user by user_id from one of the slave database $dbr = wfGetDB( DB_SLAVE ); $result = $dbr->select( 'user', - array( 'user_id' ), - array(), + [ 'user_id' ], + [], __METHOD__ - ); + ); foreach ( $result as $id ) { @@ -155,15 +162,18 @@ class UserOptions { $userValue = $user->getOption( $this->mAnOption ); if ( $userValue <> $defaultOptions[$this->mAnOption] ) { + // @codingStandardsIgnoreStart Ignore silencing errors is discouraged warning @$ret[$this->mAnOption][$userValue]++; + // @codingStandardsIgnoreEnd } - } else { foreach ( $defaultOptions as $name => $defaultValue ) { $userValue = $user->getOption( $name ); if ( $userValue <> $defaultValue ) { + // @codingStandardsIgnoreStart Ignore silencing errors is discouraged warning @$ret[$name][$userValue]++; + // @codingStandardsIgnoreEnd } } } @@ -178,17 +188,19 @@ class UserOptions { } } - /** Change our users options */ + /** + * Change our users options + */ private function CHANGER() { $this->warn(); // We list user by user_id from one of the slave database $dbr = wfGetDB( DB_SLAVE ); $result = $dbr->select( 'user', - array( 'user_id' ), - array(), + [ 'user_id' ], + [], __METHOD__ - ); + ); foreach ( $result as $id ) { @@ -200,7 +212,8 @@ class UserOptions { if ( $curValue == $this->mOldValue ) { if ( !$this->mQuiet ) { - print "Setting {$this->mAnOption} for $username from '{$this->mOldValue}' to '{$this->mNewValue}'): "; + print "Setting {$this->mAnOption} for $username from '{$this->mOldValue}' " . + "to '{$this->mNewValue}'): "; } // Change value @@ -213,7 +226,6 @@ class UserOptions { if ( !$this->mQuiet ) { print " OK\n"; } - } elseif ( !$this->mQuiet ) { print "Not changing '$username' using <{$this->mAnOption}> = '$curValue'\n"; } @@ -226,19 +238,16 @@ class UserOptions { */ public static function getDefaultOptionsNames() { $def = User::getDefaultOptions(); - $ret = array(); + $ret = []; foreach ( $def as $optname => $defaultValue ) { array_push( $ret, $optname ); } + return $ret; } - # - # Helper methods - # - public static function showUsageAndExit() { -print <<mAnOption> = '$this->mOldValue' will be made to use '$this->mNewValue'. Abort with control-c in the next five seconds.... WARN; wfCountDown( 5 ); + return true; } - }