2007-01-24 22:13:12 +00:00
|
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
/**
|
2010-12-16 19:15:12 +00:00
|
|
|
|
* 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
|
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
* @file
|
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2007-01-24 22:13:12 +00:00
|
|
|
|
// Options we will use
|
|
|
|
|
|
$options = array( 'list', 'nowarn', 'quiet', 'usage', 'dry' );
|
|
|
|
|
|
$optionsWithArgs = array( 'old', 'new' );
|
|
|
|
|
|
|
2012-08-27 19:03:15 +00:00
|
|
|
|
require_once( __DIR__ . '/commandLine.inc' );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
|
*/
|
2007-01-24 22:13:12 +00:00
|
|
|
|
class userOptions {
|
|
|
|
|
|
public $mQuick;
|
|
|
|
|
|
public $mQuiet;
|
|
|
|
|
|
public $mDry;
|
|
|
|
|
|
public $mAnOption;
|
|
|
|
|
|
public $mOldValue;
|
|
|
|
|
|
public $mNewValue;
|
|
|
|
|
|
|
|
|
|
|
|
private $mMode, $mReady ;
|
|
|
|
|
|
|
|
|
|
|
|
/** Constructor. Will show usage and exit if script options are not correct */
|
|
|
|
|
|
function __construct( $opts, $args ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !$this->checkOpts( $opts, $args ) ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
userOptions::showUsageAndExit();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$this->mReady = $this->initializeOpts( $opts, $args );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* This is used to check options. Only needed on construction
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $opts array
|
|
|
|
|
|
* @param $args array
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
2007-01-24 22:13:12 +00:00
|
|
|
|
private function checkOpts( $opts, $args ) {
|
|
|
|
|
|
// The three possible ways to run the script:
|
|
|
|
|
|
$list = isset( $opts['list'] );
|
2010-05-22 16:50:39 +00:00
|
|
|
|
$usage = isset( $opts['usage'] ) && ( count( $args ) <= 1 );
|
|
|
|
|
|
$change = isset( $opts['old'] ) && isset( $opts['new'] ) && ( count( $args ) <= 1 ) ;
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
// We want only one of them
|
2010-05-22 16:50:39 +00:00
|
|
|
|
$isValid = ( ( $list + $usage + $change ) == 1 );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
return $isValid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* load script options in the object
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param $opts array
|
|
|
|
|
|
* @param $args array
|
|
|
|
|
|
*
|
2012-02-09 21:08:06 +00:00
|
|
|
|
* @return bool
|
2011-10-18 17:32:20 +00:00
|
|
|
|
*/
|
2007-01-24 22:13:12 +00:00
|
|
|
|
private function initializeOpts( $opts, $args ) {
|
|
|
|
|
|
|
|
|
|
|
|
$this->mQuick = isset( $opts['nowarn'] );
|
|
|
|
|
|
$this->mQuiet = isset( $opts['quiet'] );
|
|
|
|
|
|
$this->mDry = isset( $opts['dry'] );
|
|
|
|
|
|
|
|
|
|
|
|
// Set object properties, specially 'mMode' used by run()
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( isset( $opts['list'] ) ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$this->mMode = 'LISTER' ;
|
2010-05-22 16:50:39 +00:00
|
|
|
|
} elseif ( isset( $opts['usage'] ) ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$this->mMode = 'USAGER' ;
|
2010-05-22 16:50:39 +00:00
|
|
|
|
$this->mAnOption = isset( $args[0] ) ? $args[0] : false ;
|
|
|
|
|
|
} elseif ( isset( $opts['old'] ) && isset( $opts['new'] ) ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$this->mMode = 'CHANGER' ;
|
|
|
|
|
|
$this->mOldValue = $opts['old'] ;
|
|
|
|
|
|
$this->mNewValue = $opts['new'] ;
|
|
|
|
|
|
$this->mAnOption = $args[0];
|
|
|
|
|
|
} else {
|
2010-05-22 16:50:39 +00:00
|
|
|
|
die( "There is a bug in the software, this should never happen\n" );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dumb stuff to run a mode.
|
|
|
|
|
|
public function run() {
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !$this->mReady ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
|
$this->{ $this->mMode } ( );
|
|
|
|
|
|
return true;
|
2007-01-24 22:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
# Modes.
|
2010-12-04 03:20:14 +00:00
|
|
|
|
#
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
/** List default options and their value */
|
|
|
|
|
|
private function LISTER( ) {
|
|
|
|
|
|
$def = User::getDefaultOptions();
|
2010-05-22 16:50:39 +00:00
|
|
|
|
ksort( $def );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$maxOpt = 0;
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $def as $opt => $value ) {
|
|
|
|
|
|
$maxOpt = max( $maxOpt, strlen( $opt ) );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $def as $opt => $value ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
printf( "%-{$maxOpt}s: %s\n", $opt, $value );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** List options usage */
|
|
|
|
|
|
private function USAGER( ) {
|
|
|
|
|
|
$ret = array();
|
|
|
|
|
|
$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(),
|
|
|
|
|
|
__METHOD__
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2010-10-13 22:34:25 +00:00
|
|
|
|
foreach ( $result as $id ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
$user = User::newFromId( $id->user_id );
|
|
|
|
|
|
|
|
|
|
|
|
// Get the options and update stats
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( $this->mAnOption ) {
|
2007-05-05 20:30:12 +00:00
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !array_key_exists( $this->mAnOption, $defaultOptions ) ) {
|
2007-05-05 20:30:12 +00:00
|
|
|
|
print "Invalid user option. Use --list to see valid choices\n";
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$userValue = $user->getOption( $this->mAnOption );
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( $userValue <> $defaultOptions[$this->mAnOption] ) {
|
2007-05-05 20:30:12 +00:00
|
|
|
|
@$ret[$this->mAnOption][$userValue]++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $defaultOptions as $name => $defaultValue ) {
|
2007-05-05 20:30:12 +00:00
|
|
|
|
$userValue = $user->getOption( $name );
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( $userValue <> $defaultValue ) {
|
2007-05-05 20:30:12 +00:00
|
|
|
|
@$ret[$name][$userValue]++;
|
|
|
|
|
|
}
|
2007-01-24 22:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $ret as $optionName => $usageStats ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
print "Usage for <$optionName> (default: '{$defaultOptions[$optionName]}'):\n";
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $usageStats as $value => $count ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
print " $count user(s): '$value'\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
print "\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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(),
|
|
|
|
|
|
__METHOD__
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2010-10-13 22:34:25 +00:00
|
|
|
|
foreach ( $result as $id ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
$user = User::newFromId( $id->user_id );
|
|
|
|
|
|
|
|
|
|
|
|
$curValue = $user->getOption( $this->mAnOption );
|
|
|
|
|
|
$username = $user->getName();
|
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( $curValue == $this->mOldValue ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !$this->mQuiet ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
print "Setting {$this->mAnOption} for $username from '{$this->mOldValue}' to '{$this->mNewValue}'): ";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-12-04 03:20:14 +00:00
|
|
|
|
// Change value
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$user->setOption( $this->mAnOption, $this->mNewValue );
|
|
|
|
|
|
|
|
|
|
|
|
// Will not save the settings if run with --dry
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !$this->mDry ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
$user->saveSettings();
|
|
|
|
|
|
}
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( !$this->mQuiet ) { print " OK\n"; }
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
} elseif ( !$this->mQuiet ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
print "Not changing '$username' using <{$this->mAnOption}> = '$curValue'\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Return an array of option names
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
2007-01-24 22:13:12 +00:00
|
|
|
|
public static function getDefaultOptionsNames() {
|
|
|
|
|
|
$def = User::getDefaultOptions();
|
|
|
|
|
|
$ret = array();
|
2010-05-22 16:50:39 +00:00
|
|
|
|
foreach ( $def as $optname => $defaultValue ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
array_push( $ret, $optname );
|
|
|
|
|
|
}
|
|
|
|
|
|
return $ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
# Helper methods
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
public static function showUsageAndExit() {
|
|
|
|
|
|
print <<<USAGE
|
|
|
|
|
|
|
|
|
|
|
|
This script pass through all users and change one of their options.
|
|
|
|
|
|
The new option is NOT validated.
|
|
|
|
|
|
|
|
|
|
|
|
Usage:
|
2010-12-04 03:20:14 +00:00
|
|
|
|
php userOptions.php --list
|
|
|
|
|
|
php userOptions.php [user option] --usage
|
|
|
|
|
|
php userOptions.php [options] <user option> --old <old value> --new <new value>
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
Switchs:
|
2010-12-04 03:20:14 +00:00
|
|
|
|
--list : list available user options and their default value
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
2010-12-04 03:20:14 +00:00
|
|
|
|
--usage : report all options statistics or just one if you specify it.
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
2010-12-04 03:20:14 +00:00
|
|
|
|
--old <old value> : the value to look for
|
|
|
|
|
|
--new <new value> : new value to update users with
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
Options:
|
2010-12-04 03:20:14 +00:00
|
|
|
|
--nowarn: hides the 5 seconds warning
|
|
|
|
|
|
--quiet : do not print what is happening
|
|
|
|
|
|
--dry : do not save user settings back to database
|
2007-01-24 22:13:12 +00:00
|
|
|
|
|
|
|
|
|
|
USAGE;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
exit( 0 );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-10-18 17:32:20 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* The warning message and countdown
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
2007-01-24 22:13:12 +00:00
|
|
|
|
public function warn() {
|
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
|
if ( $this->mQuick ) {
|
2007-01-24 22:13:12 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print <<<WARN
|
|
|
|
|
|
The script is about to change the skin for ALL USERS in the database.
|
|
|
|
|
|
Users with option <$this->mAnOption> = '$this->mOldValue' will be made to use '$this->mNewValue'.
|
|
|
|
|
|
|
|
|
|
|
|
Abort with control-c in the next five seconds....
|
|
|
|
|
|
WARN;
|
2009-06-09 17:04:16 +00:00
|
|
|
|
wfCountDown( 5 );
|
2007-01-24 22:13:12 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|