MediaWiki  master
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. More...
 
 addUserToGroup (UserIdentity $user, string $group, string $expiry=null, bool $allowUpdate=false)
 Add the user to the given group. More...
 
 addUserToMultipleGroups (UserIdentity $user, array $groups, string $expiry=null, bool $allowUpdate=false)
 Add the user to the given list of groups. More...
 
 clearCache (UserIdentity $user)
 Cleans cached group memberships for a given user. More...
 
 getGroupsChangeableBy (Authority $authority)
 Returns an array of groups that this $actor can add and remove. More...
 
 getGroupsChangeableByGroup (string $group)
 Returns an array of the groups that a particular group can add/remove. More...
 
 getQueryInfo ()
 Return the tables and fields to be selected to construct new UserGroupMembership object using newGroupMembershipFromRow method. More...
 
 getUserAutopromoteGroups (UserIdentity $user)
 Get the groups for the given user based on $wgAutopromote. More...
 
 getUserAutopromoteOnceGroups (UserIdentity $user, string $event)
 Get the groups for the given user based on the given criteria. More...
 
 getUserEffectiveGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL, bool $recache=false)
 Get the list of implicit group memberships the user has. More...
 
 getUserFormerGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Returns the groups the user has belonged to. More...
 
 getUserGroupMemberships (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Loads and returns UserGroupMembership objects for all the groups a user currently belongs to. More...
 
 getUserGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL)
 Get the list of explicit group memberships this user has. More...
 
 getUserImplicitGroups (UserIdentity $user, int $queryFlags=self::READ_NORMAL, bool $recache=false)
 Get the list of implicit group memberships this user has. More...
 
 listAllGroups ()
 Return the set of defined explicit groups. More...
 
 listAllImplicitGroups ()
 Get a list of all configured implicit groups. More...
 
 loadGroupMembershipsFromArray (UserIdentity $user, array $userGroups, int $queryFlags=self::READ_NORMAL)
 Load the user groups cache from the provided user groups data. More...
 
 newGroupMembershipFromRow (\stdClass $row)
 Creates a new UserGroupMembership instance from $row. More...
 
 purgeExpired ()
 Purge expired memberships from the user_groups table. More...
 
 removeUserFromGroup (UserIdentity $user, string $group)
 Remove the user from the given group. More...
 

Public Attributes

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

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 166 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 618 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 754 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 872 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 1136 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 1095 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 1066 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:
Access: internal

Definition at line 956 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 408 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 434 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 324 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 367 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 696 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 681 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 280 of file UserGroupManager.php.

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

◆ 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 202 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 219 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 250 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 232 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 975 of file UserGroupManager.php.

References $res, DB_PRIMARY, LIST_AND, and LIST_OR.

◆ 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 891 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 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: