MediaWiki
REL1_20
|
00001 <?php 00026 require_once( __DIR__ . '/Maintenance.php' ); 00027 00033 class ResetUserTokens extends Maintenance { 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Reset the user_token of all users on the wiki. Note that this may log some of them out."; 00037 $this->addOption( 'nowarn', "Hides the 5 seconds warning", false, false ); 00038 } 00039 00040 public function execute() { 00041 00042 if ( !$this->getOption( 'nowarn' ) ) { 00043 $this->output( "The script is about to reset the user_token for ALL USERS in the database.\n" ); 00044 $this->output( "This may log some of them out and is not necessary unless you believe your\n" ); 00045 $this->output( "user table has been compromised.\n" ); 00046 $this->output( "\n" ); 00047 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --nowarn) ... " ); 00048 wfCountDown( 5 ); 00049 } 00050 00051 // We list user by user_id from one of the slave database 00052 $dbr = wfGetDB( DB_SLAVE ); 00053 $result = $dbr->select( 'user', 00054 array( 'user_id' ), 00055 array(), 00056 __METHOD__ 00057 ); 00058 00059 foreach ( $result as $id ) { 00060 $user = User::newFromId( $id->user_id ); 00061 00062 $username = $user->getName(); 00063 00064 $this->output( "Resetting user_token for $username: " ); 00065 00066 // Change value 00067 $user->setToken(); 00068 $user->saveSettings(); 00069 00070 $this->output( " OK\n" ); 00071 00072 } 00073 00074 } 00075 } 00076 00077 $maintClass = "ResetUserTokens"; 00078 require_once( RUN_MAINTENANCE_IF_MAIN );