28 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 'Invalidate the sessions of certain users on the wiki.'
42 $this->
addOption(
'user',
'Username',
false,
true,
'u' );
43 $this->
addOption(
'file',
'File with one username per line',
false,
true,
'f' );
51 if ( $username ===
null &&
$file ===
null ) {
52 $this->
fatalError(
'Either --user or --file is required' );
53 } elseif ( $username !==
null &&
$file !==
null ) {
54 $this->
fatalError(
'Cannot use both --user and --file' );
57 if ( $username !==
null ) {
58 $usernames = [ $username ];
60 $usernames = is_readable(
$file ) ?
61 file(
$file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) :
false;
62 if ( $usernames ===
false ) {
63 $this->
fatalError(
"Could not open $file", 2 );
68 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
69 $sessionManager = SessionManager::singleton();
70 foreach ( $usernames as $username ) {
74 $sessionManager->invalidateSessionsForUser( $user );
75 if ( $user->isRegistered() ) {
76 $this->
output(
"Invalidated sessions for user $username\n" );
78 # session invalidation might still work if there is a central identity provider
79 $this->
output(
"Could not find user $username, tried to invalidate anyway\n" );
81 }
catch ( Exception $e ) {
82 $this->
output(
"Failed to invalidate sessions for user $username | "
83 . str_replace( [
"\r",
"\n" ],
' ', $e->getMessage() ) .
"\n" );
87 $lbFactory->waitForReplication();
94 require_once RUN_MAINTENANCE_IF_MAIN;
Invalidate the sessions of certain users on the wiki.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static newFromName( $name, $validate='valid')
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.