23require_once __DIR__ .
'/Maintenance.php';
31 parent::__construct();
34 "Blocks a list of usernames. Can use STDIN or the file argument.\n\n" .
35 'Note, this is probably most useful when dealing with spammers, with a ' .
36 "list you've generated with an SQL query or similar.\n\n" .
37 'All users are hard blocked, auto blocked from any current and subsequent IP ' .
38 'addresses, email disabled, unable to write to their user page and unable to ' .
39 'create further accounts with no expiry to this block.'
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 $performerName = $this->
getOption(
'performer' );
75 $this->
fatalError(
"Username '{$performerName}' isn't valid.\n" );
78 if ( !$performer->getId() ) {
79 $this->
fatalError(
"User '{$performerName}' doesn't exist.\n" );
82 $permManager = MediaWikiServices::getInstance()->getPermissionManager();
83 if ( !$permManager->userHasRight( $performer,
'block' ) ) {
84 $this->
fatalError(
"User '{$performerName}' doesn't have blocking rights.\n" );
90 if ( $this->
hasArg( 0 ) ) {
93 trim( file_get_contents( $this->
getArg( 0 ) ) )
98 while ( !feof( $stdin ) ) {
99 $name = trim( fgets( $stdin ) );
121 private function blockUsers( $users, $performer, $reason, $reblock ) {
122 foreach ( $users as $name ) {
126 if ( !$user || !$user->getId() ) {
127 $this->
output(
"Blocking '{$name}' skipped (user doesn't exist or is invalid).\n" );
131 $priorBlock = DatabaseBlock::newFromTarget( $user );
132 if ( $priorBlock ===
null ) {
134 } elseif ( $reblock ) {
135 $block = clone $priorBlock;
137 $this->
output(
"Blocking '{$name}' skipped (user already blocked).\n" );
141 $block->setTarget( $name );
142 $block->setBlocker( $performer );
143 $block->setReason( $reason );
144 $block->isHardblock(
true );
145 $block->isAutoblocking(
true );
146 $block->isCreateAccountBlocked(
true );
147 $block->isEmailBlocked(
true );
148 $block->isUsertalkEditAllowed(
false );
149 $block->setExpiry( SpecialBlock::parseExpiryInput(
'infinity' ) );
151 if ( $priorBlock ===
null ) {
159 $this->
getHookRunner()->onBlockIpComplete( $block, $performer, $priorBlock );
167 '5::duration' =>
'indefinite',
168 '6::flags' => implode(
',', $flags ),
172 $logEntry->setTarget( Title::makeTitle(
NS_USER, $name ) );
173 $logEntry->setComment( $reason );
174 $logEntry->setPerformer( $performer );
175 $logEntry->setParameters( $logParams );
177 $logEntry->setRelations( [
'ipb_id' => $blockIds ] );
178 $logEntry->publish( $logEntry->insert() );
180 $this->
output(
"Blocking '{$name}' succeeded.\n" );
182 $this->
output(
"Blocking '{$name}' failed.\n" );
const RUN_MAINTENANCE_IF_MAIN
__construct()
Default constructor.
blockUsers( $users, $performer, $reason, $reblock)
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.
getHookRunner()
Get a HookRunner for running core hooks.
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.
Class for creating new log entries and inserting them into the database.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.