phpcs: More require/include is not a function
[lhc/web/wiklou.git] / maintenance / resetUserTokens.php
1 <?php
2 /**
3 * Reset the user_token for all users on the wiki. Useful if you believe
4 * 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 __DIR__ . '/Maintenance.php';
27
28 /**
29 * Maintenance script to reset the user_token for all users on the wiki.
30 *
31 * @ingroup Maintenance
32 */
33 class ResetUserTokens extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->mDescription = "Reset the user_token of all users on the wiki. Note that this may log some of them out.";
37 $this->addOption( 'nowarn', "Hides the 5 seconds warning", false, false );
38 }
39
40 public function execute() {
41
42 if ( !$this->getOption( 'nowarn' ) ) {
43 $this->output( "The script is about to reset the user_token for ALL USERS in the database.\n" );
44 $this->output( "This may log some of them out and is not necessary unless you believe your\n" );
45 $this->output( "user table has been compromised.\n" );
46 $this->output( "\n" );
47 $this->output( "Abort with control-c in the next five seconds (skip this countdown with --nowarn) ... " );
48 wfCountDown( 5 );
49 }
50
51 // We list user by user_id from one of the slave database
52 $dbr = wfGetDB( DB_SLAVE );
53 $result = $dbr->select( 'user',
54 array( 'user_id' ),
55 array(),
56 __METHOD__
57 );
58
59 foreach ( $result as $id ) {
60 $user = User::newFromId( $id->user_id );
61
62 $username = $user->getName();
63
64 $this->output( "Resetting user_token for $username: " );
65
66 // Change value
67 $user->setToken();
68 $user->saveSettings();
69
70 $this->output( " OK\n" );
71
72 }
73
74 }
75 }
76
77 $maintClass = "ResetUserTokens";
78 require_once RUN_MAINTENANCE_IF_MAIN;