MediaWiki REL1_39
MediaWiki\User\UserGroupManager Class Reference

Managers user groups. More...

Inheritance diagram for MediaWiki\User\UserGroupManager:
Collaboration diagram for MediaWiki\User\UserGroupManager:

Public Member Functions

 __construct (ServiceOptions $options, ConfiguredReadOnlyMode $configuredReadOnlyMode, ILBFactory $loadBalancerFactory, HookContainer $hookContainer, UserEditTracker $userEditTracker, GroupPermissionsLookup $groupPermissionsLookup, JobQueueGroup $jobQueueGroup, LoggerInterface $logger, TempUserConfig $tempUserConfig, array $clearCacheCallbacks=[], $dbDomain=false)
 
 addUserToAutopromoteOnceGroups (UserIdentity $user, string $event)
 Add the user to the group if he/she meets given criteria.
 
 addUserToGroup (UserIdentity $user, string $group, string $expiry=null, bool $allowUpdate=false)
 Add the user to the given group.
 
 addUserToMultipleGroups (UserIdentity $user, array $groups, string $expiry=null, bool $allowUpdate=false)
 Add the user to the given list of groups.
 
 clearCache (UserIdentity $user)
 Cleans cached group memberships for a given user.
 
 getGroupsChangeableBy (Authority $authority)
 Returns an array of groups that this $actor can add and remove.
 
 getGroupsChangeableByGroup (string $group)
 Returns an array of the groups that a particular group can add/remove.
 
 getQueryInfo ()
 Return the tables and fields to be selected to construct new UserGroupMembership object using newGroupMembershipFromRow method.
 
 getUserAutopromoteGroups (UserIdentity $user)
 Get the groups for the given user based on $wgAutopromote.
 
 getUserAutopromoteOnceGroups (UserIdentity $user, string $event)
 Get the groups for the given user based on the given criteria.
 
 getUserEffectiveGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL, bool $recache=false)
 Get the list of implicit group memberships the user has.
 
 getUserFormerGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Returns the groups the user has belonged to.
 
 getUserGroupMemberships (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Loads and returns UserGroupMembership objects for all the groups a user currently belongs to.
 
 getUserGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Get the list of explicit group memberships this user has.
 
 getUserImplicitGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL, bool $recache=false)
 Get the list of implicit group memberships this user has.
 
 getUserPrivilegedGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL, bool $recache=false)
 Returns the list of privileged groups that $user belongs to.
 
 listAllGroups ()
 Return the set of defined explicit groups.
 
 listAllImplicitGroups ()
 Get a list of all configured implicit groups.
 
 loadGroupMembershipsFromArray (UserIdentity $user, array $userGroups, int $queryFlags=self::READ_NORMAL)
 Load the user groups cache from the provided user groups data.
 
 newGroupMembershipFromRow (\stdClass $row)
 Creates a new UserGroupMembership instance from $row.
 
 purgeExpired ()
 Purge expired memberships from the user_groups table.
 
 removeUserFromGroup (UserIdentity $user, string $group)
 Remove the user from the given group.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
- Public Attributes inherited from IDBAccessObject
const READ_NONE = -1
 Constants for object loading bitfield flags (higher => higher QoS)
 

Detailed Description

Managers user groups.

Since
1.35

Definition at line 54 of file UserGroupManager.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserGroupManager::__construct ( ServiceOptions $options,
ConfiguredReadOnlyMode $configuredReadOnlyMode,
ILBFactory $loadBalancerFactory,
HookContainer $hookContainer,
UserEditTracker $userEditTracker,
GroupPermissionsLookup $groupPermissionsLookup,
JobQueueGroup $jobQueueGroup,
LoggerInterface $logger,
TempUserConfig $tempUserConfig,
array $clearCacheCallbacks = [],
$dbDomain = false )
Parameters
ServiceOptions$options
ConfiguredReadOnlyMode$configuredReadOnlyMode
ILBFactory$loadBalancerFactory
HookContainer$hookContainer
UserEditTracker$userEditTracker
GroupPermissionsLookup$groupPermissionsLookup
JobQueueGroup$jobQueueGroupfor this $dbDomain
LoggerInterface$logger
TempUserConfig$tempUserConfig
callable[]$clearCacheCallbacks
string | bool$dbDomain

Definition at line 172 of file UserGroupManager.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and Wikimedia\Rdbms\ILBFactory\getMainLB().

Member Function Documentation

◆ addUserToAutopromoteOnceGroups()

MediaWiki\User\UserGroupManager::addUserToAutopromoteOnceGroups ( UserIdentity $user,
string $event )

Add the user to the group if he/she meets given criteria.

Contrary to autopromotion by $wgAutopromote, the group will be possible to remove manually via Special:UserRights. In such case it will not be re-added automatically. The user will also not lose the group if they no longer meet the criteria.

Parameters
UserIdentity$userUser to add to the groups
string$eventKey in $wgAutopromoteOnce (each event has groups/criteria)
Returns
string[] Array of groups the user has been promoted to.
See also
$wgAutopromoteOnce

Definition at line 675 of file UserGroupManager.php.

◆ addUserToGroup()

MediaWiki\User\UserGroupManager::addUserToGroup ( UserIdentity $user,
string $group,
string $expiry = null,
bool $allowUpdate = false )

Add the user to the given group.

This takes immediate effect. If the user is already in the group, the expiry time will be updated to the new expiry time. (If $expiry is omitted or null, the membership will be altered to never expire.)

Parameters
UserIdentity$user
string$groupName of the group to add
string | null$expiryOptional expiry timestamp in any format acceptable to wfTimestamp(), or null if the group assignment should not expire
bool$allowUpdateWhether to perform "upsert" instead of INSERT
Exceptions
InvalidArgumentException
Returns
bool

Definition at line 811 of file UserGroupManager.php.

◆ addUserToMultipleGroups()

MediaWiki\User\UserGroupManager::addUserToMultipleGroups ( UserIdentity $user,
array $groups,
string $expiry = null,
bool $allowUpdate = false )

Add the user to the given list of groups.

Since
1.37
Parameters
UserIdentity$user
string[]$groupsNames of the groups to add
string | null$expiryOptional expiry timestamp in any format acceptable to wfTimestamp(), or null if the group assignment should not expire
bool$allowUpdateWhether to perform "upsert" instead of INSERT
Exceptions
InvalidArgumentException

Definition at line 929 of file UserGroupManager.php.

◆ clearCache()

MediaWiki\User\UserGroupManager::clearCache ( UserIdentity $user)

Cleans cached group memberships for a given user.

Parameters
UserIdentity$user

Definition at line 1193 of file UserGroupManager.php.

◆ getGroupsChangeableBy()

MediaWiki\User\UserGroupManager::getGroupsChangeableBy ( Authority $authority)

Returns an array of groups that this $actor can add and remove.

Since
1.37
Parameters
Authority$authority
Returns
array [ 'add' => [ addablegroups ], 'remove' => [ removablegroups ], 'add-self' => [ addablegroups to self ], 'remove-self' => [ removable groups from self ] ]

Definition at line 1152 of file UserGroupManager.php.

◆ getGroupsChangeableByGroup()

MediaWiki\User\UserGroupManager::getGroupsChangeableByGroup ( string $group)

Returns an array of the groups that a particular group can add/remove.

Since
1.37
Parameters
string$groupThe group to check for whether it can add/remove
Returns
array [ 'add' => [ addablegroups ], 'remove' => [ removablegroups ], 'add-self' => [ addablegroups to self ], 'remove-self' => [ removable groups from self ] ]

Definition at line 1123 of file UserGroupManager.php.

◆ getQueryInfo()

MediaWiki\User\UserGroupManager::getQueryInfo ( )

Return the tables and fields to be selected to construct new UserGroupMembership object using newGroupMembershipFromRow method.

Returns
array[] With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select() or SelectQueryBuilder::tables
  • fields: (string[]) to include in the $vars to IDatabase->select() or SelectQueryBuilder::fields
  • joins: (array) to include in the $join_conds to IDatabase->select() or SelectQueryBuilder::joinConds
Access: internal

Definition at line 1013 of file UserGroupManager.php.

◆ getUserAutopromoteGroups()

MediaWiki\User\UserGroupManager::getUserAutopromoteGroups ( UserIdentity $user)

Get the groups for the given user based on $wgAutopromote.

Parameters
UserIdentity$userThe user to get the groups for
Returns
string[] Array of groups to promote to.
See also
$wgAutopromote

Definition at line 414 of file UserGroupManager.php.

◆ getUserAutopromoteOnceGroups()

MediaWiki\User\UserGroupManager::getUserAutopromoteOnceGroups ( UserIdentity $user,
string $event )

Get the groups for the given user based on the given criteria.

Does not return groups the user already belongs to or has once belonged.

Parameters
UserIdentity$userThe user to get the groups for
string$eventKey in $wgAutopromoteOnce (each event has groups/criteria)
Returns
string[] Groups the user should be promoted to.
See also
$wgAutopromoteOnce

Definition at line 440 of file UserGroupManager.php.

References User\newFromIdentity().

◆ getUserEffectiveGroups()

MediaWiki\User\UserGroupManager::getUserEffectiveGroups ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL,
bool $recache = false )

Get the list of implicit group memberships the user has.

This includes all explicit groups, plus 'user' if logged in, '*' for all accounts, and autopromoted groups

Parameters
UserIdentity$user
int$queryFlags
bool$recacheWhether to avoid the cache
Returns
string[] internal group names

Definition at line 330 of file UserGroupManager.php.

References User\newFromIdentity().

◆ getUserFormerGroups()

MediaWiki\User\UserGroupManager::getUserFormerGroups ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL )

Returns the groups the user has belonged to.

The user may still belong to the returned groups. Compare with getUserGroups().

The function will not return groups the user had belonged to before MW 1.17

Parameters
UserIdentity$user
int$queryFlags
Returns
string[] Names of the groups the user has belonged to.

Definition at line 373 of file UserGroupManager.php.

◆ getUserGroupMemberships()

MediaWiki\User\UserGroupManager::getUserGroupMemberships ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL )

Loads and returns UserGroupMembership objects for all the groups a user currently belongs to.

Parameters
UserIdentity$userthe user to search for
int$queryFlags
Returns
UserGroupMembership[] Associative array of (group name => UserGroupMembership object)

Definition at line 753 of file UserGroupManager.php.

◆ getUserGroups()

MediaWiki\User\UserGroupManager::getUserGroups ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL )

Get the list of explicit group memberships this user has.

The implicit * and user groups are not included.

Parameters
UserIdentity$user
int$queryFlags
Returns
string[]

Definition at line 738 of file UserGroupManager.php.

◆ getUserImplicitGroups()

MediaWiki\User\UserGroupManager::getUserImplicitGroups ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL,
bool $recache = false )

Get the list of implicit group memberships this user has.

This includes 'user' if logged in, '*' for all accounts, and autopromoted groups

Parameters
UserIdentity$user
int$queryFlags
bool$recacheWhether to avoid the cache
Returns
string[] internal group names

Definition at line 286 of file UserGroupManager.php.

References MediaWiki\User\UserIdentity\getName(), and MediaWiki\User\UserIdentity\isRegistered().

◆ getUserPrivilegedGroups()

MediaWiki\User\UserGroupManager::getUserPrivilegedGroups ( UserIdentity $user,
int $queryFlags = self::READ_NORMAL,
bool $recache = false )

Returns the list of privileged groups that $user belongs to.

Privileged groups are ones that can be abused in a dangerous way.

Depending on how extensions extend this method, it might return values that are not strictly user groups (ACL list names, etc.). It is meant for logging/auditing, not for passing to methods that expect group names.

Parameters
UserIdentity$user
int$queryFlags
bool$recacheWhether to avoid the cache
Returns
string[]
Since
1.41 (also backported to 1.39.5 and 1.40.1)
See also
$wgPrivilegedGroups
https://www.mediawiki.org/wiki/Manual:Hooks/UserGetPrivilegedGroups

Definition at line 487 of file UserGroupManager.php.

◆ listAllGroups()

MediaWiki\User\UserGroupManager::listAllGroups ( )

Return the set of defined explicit groups.

The implicit groups (by default *, 'user' and 'autoconfirmed') are not included, as they are defined automatically, not in the database.

Returns
string[] internal group names

Definition at line 208 of file UserGroupManager.php.

Referenced by UsersPager\__construct().

◆ listAllImplicitGroups()

MediaWiki\User\UserGroupManager::listAllImplicitGroups ( )

Get a list of all configured implicit groups.

Returns
string[]

Definition at line 225 of file UserGroupManager.php.

◆ loadGroupMembershipsFromArray()

MediaWiki\User\UserGroupManager::loadGroupMembershipsFromArray ( UserIdentity $user,
array $userGroups,
int $queryFlags = self::READ_NORMAL )

Load the user groups cache from the provided user groups data.

Access: internal
for use by the User object only
Parameters
UserIdentity$user
array$userGroupsan array of database query results
int$queryFlags

Definition at line 256 of file UserGroupManager.php.

◆ newGroupMembershipFromRow()

MediaWiki\User\UserGroupManager::newGroupMembershipFromRow ( \stdClass $row)

Creates a new UserGroupMembership instance from $row.

The fields required to build an instance could be found using getQueryInfo() method.

Parameters
\\stdClass$rowA database result object
Returns
UserGroupMembership

Definition at line 238 of file UserGroupManager.php.

◆ purgeExpired()

MediaWiki\User\UserGroupManager::purgeExpired ( )

Purge expired memberships from the user_groups table.

Access: internal
Note
this could be slow and is intended for use in a background job
Returns
int|bool false if purging wasn't attempted (e.g. because of readonly), the number of rows purged (might be 0) otherwise

Definition at line 1032 of file UserGroupManager.php.

References $res, and DB_PRIMARY.

◆ removeUserFromGroup()

MediaWiki\User\UserGroupManager::removeUserFromGroup ( UserIdentity $user,
string $group )

Remove the user from the given group.

This takes immediate effect.

Parameters
UserIdentity$user
string$groupName of the group to remove
Exceptions
InvalidArgumentException
Returns
bool

Definition at line 948 of file UserGroupManager.php.

References User\newFromIdentity().

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserGroupManager::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const AutoConfirmCount
Name constant for the AutoConfirmCount setting, for use with Config::get()
const ImplicitGroups
Name constant for the ImplicitGroups setting, for use with Config::get()
const GroupInheritsPermissions
Name constant for the GroupInheritsPermissions setting, for use with Config::get()
const RevokePermissions
Name constant for the RevokePermissions setting, for use with Config::get()
const GroupsRemoveFromSelf
Name constant for the GroupsRemoveFromSelf setting, for use with Config::get()
const AutopromoteOnce
Name constant for the AutopromoteOnce setting, for use with Config::get()
const Autopromote
Name constant for the Autopromote setting, for use with Config::get()
const GroupPermissions
Name constant for the GroupPermissions setting, for use with Config::get()
const AddGroups
Name constant for the AddGroups setting, for use with Config::get()
const AutoConfirmAge
Name constant for the AutoConfirmAge setting, for use with Config::get()
const PrivilegedGroups
Name constant for the PrivilegedGroups setting, for use with Config::get()
const GroupsAddToSelf
Name constant for the GroupsAddToSelf setting, for use with Config::get()
const AutopromoteOnceLogInRC
Name constant for the AutopromoteOnceLogInRC setting, for use with Config::get()
const RemoveGroups
Name constant for the RemoveGroups setting, for use with Config::get()
const EmailAuthentication
Name constant for the EmailAuthentication setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 59 of file UserGroupManager.php.


The documentation for this class was generated from the following file: