23require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
33 "Blocks a list of usernames. Can use STDIN or the file argument.\n\n" .
34 'Note, this is probably most useful when dealing with spammers, with a ' .
35 "list you've generated with an SQL query or similar.\n\n" .
36 'By default, all users are hard blocked, auto blocked from any current and subsequent ' .
37 'IP addresses, email disabled, unable to write to their user page and unable to ' .
38 'create further accounts with no expiry to this block. You can change the expiry ' .
39 'with --expiry parameter.'
44 'File with list of users to block',
50 'User to make the blocks',
57 'Reason for the blocks',
64 'Reblock users who are already blocked',
71 'Expiry of your block',
78 'Should this unblock?',
84 'allow-createaccount',
85 'Allow account creation for blocked IPs',
91 'Allow blocked accounts to send emails',
97 'Allow blocked accounts to edit their own talk page',
103 'Don\'t block logged in accounts from a blocked IP address',
109 'Don\'t autoblock IP addresses used by the accounts',
115 $performerName = $this->
getOption(
'performer',
false );
116 $reason = $this->
getOption(
'reason',
'' );
117 $unblocking = $this->
getOption(
'unblock',
false );
118 $reblock = $this->
hasOption(
'reblock' );
119 $expiry = $this->
getOption(
'expiry',
'indefinite' );
122 if ( $performerName ) {
128 if ( $performer ===
null ) {
129 $this->
fatalError(
"Unable to parse performer's username" );
132 if ( $this->
hasArg( 0 ) ) {
140 $this->
fatalError(
"Unable to read file, exiting" );
144 $blockUserFactory = MediaWikiServices::getInstance()->getBlockUserFactory();
145 $unblockUserFactory = MediaWikiServices::getInstance()->getUnblockUserFactory();
146 $action = $unblocking ?
"Unblocking" :
"Blocking";
147 for ( $linenum = 1; !feof(
$file ); $linenum++ ) {
154 $res = $unblockUserFactory->newUnblockUser(
160 $res = $blockUserFactory->newBlockUser(
166 'isCreateAccountBlocked' => !$this->
hasOption(
'allow-createaccount' ),
167 'isEmailBlocked' => !$this->
hasOption(
'allow-email' ),
168 'isUserTalkEditBlocked' => !$this->
hasOption(
'allow-talkedit' ),
169 'isHardBlock' => !$this->
hasOption(
'disable-hardblock' ),
170 'isAutoblocking' => !$this->
hasOption(
'disable-autoblock' ),
172 )->placeBlockUnsafe( $reblock );
175 if (
$res->isOK() ) {
176 $this->
output(
"{$action} '{$line}' succeeded.\n" );
178 $errorsText =
$res->getMessage()->text();
179 $this->
output(
"{$action} '{$line}' failed ({$errorsText}).\n" );
186require_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)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
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')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.