From 51cdf2eb149631d8240a4be05fcfe7a24d39928f Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Fri, 11 Feb 2011 02:46:08 +0000 Subject: [PATCH] Add a new maintenance script to reset the user_token of all users if you think someone got ahold of your user table. --- maintenance/resetUserTokens.php | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 maintenance/resetUserTokens.php diff --git a/maintenance/resetUserTokens.php b/maintenance/resetUserTokens.php new file mode 100644 index 0000000000..52407f4d4d --- /dev/null +++ b/maintenance/resetUserTokens.php @@ -0,0 +1,82 @@ + + */ + +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); + +class ResetUserTokens extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = "Reset the user_token of all users on the wiki. Note that this may log some of them out."; + $this->addOption( 'nowarn', "Hides the 5 seconds warning", false, false ); + $this->addOption( 'quiet', "Do not print what is happening", false, false ); + } + + public function execute() { + $nowarn = $this->getOption( 'nowarn' ); + $quiet = $this->getOption( 'quiet' ); + + if ( !$nowarn ) { + echo <<select( 'user', + array( 'user_id' ), + array(), + __METHOD__ + ); + + foreach ( $result as $id ) { + $user = User::newFromId( $id->user_id ); + + $username = $user->getName(); + + if ( !$quiet ) { + echo "Resetting user_token for $username: "; + } + + // Change value + $user->setToken(); + $user->saveSettings(); + + if ( !$quiet ) { + echo " OK\n"; + } + + } + + } +} + +$maintClass = "ResetUserTokens"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- 2.20.1