*/
// 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';
*/
function __construct( $opts, $args ) {
if ( !$this->checkOpts( $opts, $args ) ) {
- UserOptions::showUsageAndExit();
+ self::showUsageAndExit();
} else {
$this->mReady = $this->initializeOpts( $opts, $args );
}
* @return bool
*/
private function initializeOpts( $opts, $args ) {
-
$this->mQuick = isset( $opts['nowarn'] );
$this->mQuiet = isset( $opts['quiet'] );
$this->mDry = isset( $opts['dry'] );
return true;
}
- // Dumb stuff to run a mode.
+ /**
+ * Dumb stuff to run a mode.
+ */
public function run() {
if ( !$this->mReady ) {
return false;
return true;
}
- #
- # Modes.
- #
-
- /** List default options and their value */
+ /**
+ * List default options and their value
+ */
private function LISTER() {
$def = User::getDefaultOptions();
ksort( $def );
}
}
- /** 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 );
+ // We list user by user_id from one of the replica DBs
+ $dbr = wfGetDB( DB_REPLICA );
$result = $dbr->select( 'user',
- array( 'user_id' ),
- array(),
+ [ 'user_id' ],
+ [],
__METHOD__
);
foreach ( $result as $id ) {
-
$user = User::newFromId( $id->user_id );
// Get the options and update stats
if ( $this->mAnOption ) {
-
if ( !array_key_exists( $this->mAnOption, $defaultOptions ) ) {
print "Invalid user option. Use --list to see valid choices\n";
exit;
}
}
- /** 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 );
+ // We list user by user_id from one of the replica DBs
+ $dbr = wfGetDB( DB_REPLICA );
$result = $dbr->select( 'user',
- array( 'user_id' ),
- array(),
+ [ 'user_id' ],
+ [],
__METHOD__
);
foreach ( $result as $id ) {
-
$user = User::newFromId( $id->user_id );
$curValue = $user->getOption( $this->mAnOption );
$username = $user->getName();
if ( $curValue == $this->mOldValue ) {
-
if ( !$this->mQuiet ) {
print "Setting {$this->mAnOption} for $username from '{$this->mOldValue}' " .
"to '{$this->mNewValue}'): ";
*/
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 <<<USAGE
* @return bool
*/
public function warn() {
-
if ( $this->mQuick ) {
return true;
}