From: Gergő Tisza Date: Wed, 15 Jun 2016 18:01:31 +0000 (+0000) Subject: Add invalidateUserSessions.php maintenance script X-Git-Tag: 1.31.0-rc.0~6591^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=c2fb1b900b5b7619dadbf92b9fb592c717c7b4a7;p=lhc%2Fweb%2Fwiklou.git Add invalidateUserSessions.php maintenance script Similar to resetUserTokens.php but uses AuthManager and takes a list of users (a script for invalidating all users would be mostly pointless with $wgAuthenticationTokenVersion). resetUserTokens.php is deprecated, but kept around - mainly in case we want to transform it into a fast token reset algorithm much like I6b6e75db2a. Change-Id: I81450c44a7af26393db7fc61fd5c05f13a13ac3f --- diff --git a/maintenance/invalidateUserSessions.php b/maintenance/invalidateUserSessions.php new file mode 100644 index 0000000000..4b567aec00 --- /dev/null +++ b/maintenance/invalidateUserSessions.php @@ -0,0 +1,88 @@ +addDescription( + 'Invalidate the sessions of certain users on the wiki.' + ); + $this->addOption( 'user', 'Username', false, true, 'u' ); + $this->addOption( 'file', 'File with one username per line', false, true, 'f' ); + $this->setBatchSize( 1000 ); + } + + public function execute() { + $username = $this->getOption( 'user' ); + $file = $this->getOption( 'file' ); + + if ( $username === null && $file === null ) { + $this->error( 'Either --user or --file is required', 1 ); + } elseif ( $username !== null && $file !== null ) { + $this->error( 'Cannot use both --user and --file', 1 ); + } + + if ( $username !== null ) { + $usernames = [ $username ]; + } else { + $usernames = is_readable( $file ) ? + file( $file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) : false; + if ( $usernames === false ) { + $this->error( "Could not open $file", 2 ); + } + } + + $i = 0; + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $sessionManager = SessionManager::singleton(); + foreach ( $usernames as $username ) { + $i++; + $user = User::newFromName( $username ); + if ( $user->getId() ) { + $sessionManager->invalidateSessionsForUser( $user ); + $this->output( "Invalidated sessions for user $username\n" ); + } else { + $this->output( "Could not find user $username\n" ); + } + + if ( $i % $this->mBatchSize ) { + $lbFactory->waitForReplication(); + } + } + } +} + +$maintClass = "InvalidateUserSesssions"; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/resetUserTokens.php b/maintenance/resetUserTokens.php index 837f304ddc..131a569d6c 100644 --- a/maintenance/resetUserTokens.php +++ b/maintenance/resetUserTokens.php @@ -30,12 +30,14 @@ require_once __DIR__ . '/Maintenance.php'; * Maintenance script to reset the user_token for all users on the wiki. * * @ingroup Maintenance + * @deprecated since 1.27, use $wgAuthenticationTokenVersion instead. */ class ResetUserTokens extends Maintenance { public function __construct() { parent::__construct(); $this->addDescription( - 'Reset the user_token of all users on the wiki. Note that this may log some of them out.' + "Reset the user_token of all users on the wiki. Note that this may log some of them out.\n" + . "Deprecated, use \$wgAuthenticationTokenVersion instead." ); $this->addOption( 'nowarn', "Hides the 5 seconds warning", false, false ); $this->addOption(