MediaWiki  1.34.0
emptyUserGroup.php
Go to the documentation of this file.
1 <?php
2 
25 require_once __DIR__ . '/Maintenance.php';
26 
28 
29 class EmptyUserGroup extends Maintenance {
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;
61 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
EmptyUserGroup\__construct
__construct()
Default constructor.
Definition: emptyUserGroup.php:30
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
EmptyUserGroup\execute
execute()
Do the actual work.
Definition: emptyUserGroup.php:36
$maintClass
$maintClass
Definition: emptyUserGroup.php:60
User\findUsersByGroup
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
Definition: User.php:1001
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:319
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:371
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
EmptyUserGroup
Definition: emptyUserGroup.php:29