24require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
36 "Blocks a list of usernames. Can use STDIN or the file argument.\n\n" .
37 'Note, this is probably most useful when dealing with spammers, with a ' .
38 "list you've generated with an SQL query or similar.\n\n" .
39 'By default, all users are hard blocked, auto blocked from any current and subsequent ' .
40 'IP addresses, email disabled, unable to write to their user page and unable to ' .
41 'create further accounts with no expiry to this block. You can change the expiry ' .
42 'with --expiry parameter.'
47 'File with list of users to block',
53 'User to make the blocks',
60 'Reason for the blocks',
67 'Reblock users who are already blocked',
74 'Expiry of your block',
81 'Should this unblock?',
87 'allow-createaccount',
88 'Allow account creation for blocked IPs',
94 'Allow blocked accounts to send emails',
100 'Allow blocked accounts to edit their own talk page',
106 'Don\'t block logged in accounts from a blocked IP address (will still block temporary accounts)',
112 'Don\'t autoblock IP addresses used by the accounts',
118 $performerName = $this->
getOption(
'performer',
false );
119 $reason = $this->
getOption(
'reason',
'' );
120 $unblocking = $this->
getOption(
'unblock',
false );
121 $reblock = $this->
hasOption(
'reblock' );
122 $expiry = $this->
getOption(
'expiry',
'indefinite' );
124 if ( $performerName ) {
125 $performer = $this->
getServiceContainer()->getUserFactory()->newFromName( $performerName );
127 $performer = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
130 if ( $performer ===
null ) {
131 $this->
fatalError(
"Unable to parse performer's username" );
134 if ( $this->
hasArg( 0 ) ) {
135 $file = fopen( $this->
getArg( 0 ),
'r' );
142 $this->
fatalError(
"Unable to read file, exiting" );
148 $action = $unblocking ?
"Unblocking" :
"Blocking";
149 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
150 $line = trim( fgets( $file ) );
156 $res = $unblockUserFactory->newUnblockUser(
162 $res = $blockUserFactory->newBlockUser(
168 'isCreateAccountBlocked' => !$this->
hasOption(
'allow-createaccount' ),
169 'isEmailBlocked' => !$this->
hasOption(
'allow-email' ),
170 'isUserTalkEditBlocked' => !$this->
hasOption(
'allow-talkedit' ),
171 'isHardBlock' => !$this->
hasOption(
'disable-hardblock' ),
172 'isAutoblocking' => !$this->
hasOption(
'disable-autoblock' ),
174 )->placeBlockUnsafe( $reblock );
177 if ( $res->isOK() ) {
178 $this->
output(
"{$action} '{$line}' succeeded.\n" );
180 $errorsText = $res->getMessage()->text();
181 $this->
output(
"{$action} '{$line}' failed ({$errorsText}).\n" );
189require_once RUN_MAINTENANCE_IF_MAIN;
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
hasArg( $argId=0)
Does a given argument exist?
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.