MediaWiki REL1_30
invalidateUserSessions.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription(
40 'Invalidate the sessions of certain users on the wiki.'
41 );
42 $this->addOption( 'user', 'Username', false, true, 'u' );
43 $this->addOption( 'file', 'File with one username per line', false, true, 'f' );
44 $this->setBatchSize( 1000 );
45 }
46
47 public function execute() {
48 $username = $this->getOption( 'user' );
49 $file = $this->getOption( 'file' );
50
51 if ( $username === null && $file === null ) {
52 $this->error( 'Either --user or --file is required', 1 );
53 } elseif ( $username !== null && $file !== null ) {
54 $this->error( 'Cannot use both --user and --file', 1 );
55 }
56
57 if ( $username !== null ) {
58 $usernames = [ $username ];
59 } else {
60 $usernames = is_readable( $file ) ?
61 file( $file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) : false;
62 if ( $usernames === false ) {
63 $this->error( "Could not open $file", 2 );
64 }
65 }
66
67 $i = 0;
68 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
69 $sessionManager = SessionManager::singleton();
70 foreach ( $usernames as $username ) {
71 $i++;
72 $user = User::newFromName( $username );
73 try {
74 $sessionManager->invalidateSessionsForUser( $user );
75 if ( $user->getId() ) {
76 $this->output( "Invalidated sessions for user $username\n" );
77 } else {
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" );
80 }
81 } catch ( Exception $e ) {
82 $this->output( "Failed to invalidate sessions for user $username | "
83 . str_replace( [ "\r", "\n" ], ' ', $e->getMessage() ) . "\n" );
84 }
85
86 if ( $i % $this->mBatchSize ) {
87 $lbFactory->waitForReplication();
88 }
89 }
90 }
91}
92
93$maintClass = "InvalidateUserSesssions";
94require_once RUN_MAINTENANCE_IF_MAIN;
Invalidate the sessions of certain users on the wiki.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
setBatchSize( $s=0)
Set the batch size.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This serves as the entry point to the MediaWiki session handling system.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:783
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:106
returning false will NOT prevent logging $e
Definition hooks.txt:2146
require_once RUN_MAINTENANCE_IF_MAIN