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