a1c4eaeb5999ab05a9dcbce6a868880071682fbc
[lhc/web/wiklou.git] / maintenance / resetUserTokens.php
1 <?php
2 /**
3 * Script to reset the user_token for all users on the wiki. Useful if you
4 * believe that your user table was acidentally leaked to an external source.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup Maintenance
23 * @author Daniel Friesen <mediawiki@danielfriesen.name>
24 */
25
26 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
27
28 class ResetUserTokens extends Maintenance {
29 public function __construct() {
30 parent::__construct();
31 $this->mDescription = "Reset the user_token of all users on the wiki. Note that this may log some of them out.";
32 $this->addOption( 'nowarn', "Hides the 5 seconds warning", false, false );
33 }
34
35 public function execute() {
36
37 if ( !$this->getOption( 'nowarn' ) ) {
38 $this->output( "The script is about to reset the user_token for ALL USERS in the database.\n" );
39 $this->output( "This may log some of them out and is not necessary unless you believe your\n" );
40 $this->output( "user table has been compromised.\n" );
41 $this->output( "\n" );
42 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --nowarn) ... " );
43 wfCountDown( 5 );
44 }
45
46 // We list user by user_id from one of the slave database
47 $dbr = wfGetDB( DB_SLAVE );
48 $result = $dbr->select( 'user',
49 array( 'user_id' ),
50 array(),
51 __METHOD__
52 );
53
54 foreach ( $result as $id ) {
55 $user = User::newFromId( $id->user_id );
56
57 $username = $user->getName();
58
59 $this->output( "Resetting user_token for $username: " );
60
61 // Change value
62 $user->setToken();
63 $user->saveSettings();
64
65 $this->output( " OK\n" );
66
67 }
68
69 }
70 }
71
72 $maintClass = "ResetUserTokens";
73 require_once( RUN_MAINTENANCE_IF_MAIN );