MediaWiki REL1_34
emptyUserGroup.php
Go to the documentation of this file.
1<?php
2
25require_once __DIR__ . '/Maintenance.php';
26
28
30 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Remove all users from a given user group' );
33 $this->addArg( 'group', 'Group to be removed', true );
34 }
35
36 public function execute() {
37 $group = $this->getArg( 0 );
38
39 $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
40
41 $users = User::findUsersByGroup( $group );
42
43 $count = iterator_count( $users );
44
45 $this->output( "Removing $count users from $group..." );
46
50 foreach ( $users as $user ) {
51 $user->removeGroup( $group );
52
53 $lb->waitForReplication();
54 }
55
56 $this->output( " Done!\n" );
57 }
58}
59
60$maintClass = EmptyUserGroup::class;
61require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
execute()
Do the actual work.
__construct()
Default constructor.
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.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
MediaWikiServices is the service locator for the application scope of MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
Definition User.php:1042
$maintClass