MediaWiki master
MediaWiki\User\UserGroupAssignmentService Class Reference

This class represents a service that provides high-level operations on user groups. More...

Inherits MediaWiki\User\UserGroupAssignmentServiceBase.

Collaboration diagram for MediaWiki\User\UserGroupAssignmentService:

Public Member Functions

 __construct (private readonly UserGroupManagerFactory $userGroupManagerFactory, private readonly UserNameUtils $userNameUtils, private readonly UserFactory $userFactory, private readonly RestrictedUserGroupCheckerFactory $restrictedGroupCheckerFactory, private readonly HookRunner $hookRunner, private readonly ServiceOptions $options, private readonly TempUserConfig $tempUserConfig, private readonly IConnectionProvider $connectionProvider, private readonly PageStoreFactory $pageStoreFactory,)
 
 getChangeableGroups (Authority $performer, UserIdentity $target, bool $evaluatePrivateConditionsForRestrictedGroups=true)
 Returns the groups that the performer can add or remove from the target user.The result of this function is cached for the duration of the request.

Parameters
Authority$performer
UserIdentity$target
bool$evaluatePrivateConditionsForRestrictedGroupsIf true, all conditions for restricted groups will be evaluated (including private). If false, private conditions will be left unevaluated and 'condition-met' can be potentially null, if the result depends on private conditions.
Returns
array [ 'add' => [ addablegroups ], 'remove' => [ removablegroups ], 'restricted' => [ groupname => [ 'condition-met' => ?bool, 'ignore-condition' => bool, 'message' => string ] ] ]

 
 getPageTitleForTargetUser (UserIdentity $target, string|false $referenceWiki=UserIdentity::LOCAL)
 Returns the title of page representing the target user, suitable for use in log entries.
 
 saveChangesToUserGroups (Authority $performer, UserIdentity $target, array $addGroups, array $removeGroups, array $newExpiries, string $reason='', array $tags=[], array $logAtAdditionalWikis=[])
 Changes the user groups, ensuring that the performer has the necessary permissions and that the changes are logged.
 
 targetCanHaveUserGroups (UserIdentity $target)
 
 userCanChangeRights (Authority $performer, UserIdentity $target)
 Check whether the given user can change the target user's rights.
 
- Public Member Functions inherited from MediaWiki\User\UserGroupAssignmentServiceBase
 __construct (private readonly HookRunner $hookRunner,)
 
 logAccessToPrivateConditions (Authority $performer, UserIdentity $target, array $addGroups, array $newExpiries, array $existingUGMs,)
 Triggers a hook that allows extensions to log when user read some private conditions.
 
 validateUserGroups (Authority $performer, UserIdentity $target, array $addGroups, array $removeGroups, array $newExpiries, array $groupMemberships,)
 Validates the requested changes to user groups and returns an array, specifying if some groups are unchangeable and for what reasons.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Protected Member Functions

 getKnownGroups (UserIdentity $target)
 Returns a list of possible known groups for a given identity.The result of this function is used to skip undefined pre-existing groups when validating group changes.

Parameters
UserIdentity$targetThe target user
Returns
string[]

 
 getRestrictedGroupChecker (UserIdentity $target)
 Returns an instance of {.
See also
RestrictedUserGroupChecker} suitable for use with the target user.

 

Additional Inherited Members

- Static Public Member Functions inherited from MediaWiki\User\UserGroupAssignmentServiceBase
static enforceChangeGroupPermissions (array &$addGroups, array &$removeGroups, array &$newExpiries, array $existingUGMs, array $permittedChanges)
 Ensures that the content of $addGroups, $removeGroups and $newExpiries is compliant with the possible changes defined in $permittedChanges.
 
static expiryToTimestamp ( $expiry)
 Converts a user group membership expiry string into a timestamp.
 

Detailed Description

This class represents a service that provides high-level operations on user groups.

Contrary to UserGroupManager, this class is not interested in details of how user groups are stored or defined, but rather in the business logic of assigning and removing groups.

Therefore, it combines group management with logging and provides permission checks. Additionally, the method interfaces are designed to be suitable for calls from user-facing code.

Since
1.45

Definition at line 33 of file UserGroupAssignmentService.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserGroupAssignmentService::__construct ( private readonly UserGroupManagerFactory $userGroupManagerFactory,
private readonly UserNameUtils $userNameUtils,
private readonly UserFactory $userFactory,
private readonly RestrictedUserGroupCheckerFactory $restrictedGroupCheckerFactory,
private readonly HookRunner $hookRunner,
private readonly ServiceOptions $options,
private readonly TempUserConfig $tempUserConfig,
private readonly IConnectionProvider $connectionProvider,
private readonly PageStoreFactory $pageStoreFactory )

Definition at line 42 of file UserGroupAssignmentService.php.

Member Function Documentation

◆ getChangeableGroups()

MediaWiki\User\UserGroupAssignmentService::getChangeableGroups ( Authority $performer,
UserIdentity $target,
bool $evaluatePrivateConditionsForRestrictedGroups = true )

Returns the groups that the performer can add or remove from the target user.The result of this function is cached for the duration of the request.

Parameters
Authority$performer
UserIdentity$target
bool$evaluatePrivateConditionsForRestrictedGroupsIf true, all conditions for restricted groups will be evaluated (including private). If false, private conditions will be left unevaluated and 'condition-met' can be potentially null, if the result depends on private conditions.
Returns
array [ 'add' => [ addablegroups ], 'remove' => [ removablegroups ], 'restricted' => [ groupname => [ 'condition-met' => ?bool, 'ignore-condition' => bool, 'message' => string ] ] ]

Reimplemented from MediaWiki\User\UserGroupAssignmentServiceBase.

Definition at line 103 of file UserGroupAssignmentService.php.

◆ getKnownGroups()

MediaWiki\User\UserGroupAssignmentService::getKnownGroups ( UserIdentity $target)
protected

Returns a list of possible known groups for a given identity.The result of this function is used to skip undefined pre-existing groups when validating group changes.

Parameters
UserIdentity$targetThe target user
Returns
string[]

Reimplemented from MediaWiki\User\UserGroupAssignmentServiceBase.

Definition at line 263 of file UserGroupAssignmentService.php.

◆ getPageTitleForTargetUser()

MediaWiki\User\UserGroupAssignmentService::getPageTitleForTargetUser ( UserIdentity $target,
string|false $referenceWiki = UserIdentity::LOCAL )

Returns the title of page representing the target user, suitable for use in log entries.

The returned value doesn't include the namespace.

Interwiki suffix will be added to the title only if the target user's wiki is different from the reference wiki.

Parameters
UserIdentity$targetThe target user (only name and wiki ID are relevant for this method)
string | false$referenceWikiThe wiki to use as a reference for formatting the title. If the wiki is different from the target user's wiki, the returned title will include the interwiki suffix.

Definition at line 374 of file UserGroupAssignmentService.php.

◆ getRestrictedGroupChecker()

MediaWiki\User\UserGroupAssignmentService::getRestrictedGroupChecker ( UserIdentity $target)
protected

Returns an instance of {.

See also
RestrictedUserGroupChecker} suitable for use with the target user.

Reimplemented from MediaWiki\User\UserGroupAssignmentServiceBase.

Definition at line 269 of file UserGroupAssignmentService.php.

◆ saveChangesToUserGroups()

MediaWiki\User\UserGroupAssignmentService::saveChangesToUserGroups ( Authority $performer,
UserIdentity $target,
array $addGroups,
array $removeGroups,
array $newExpiries,
string $reason = '',
array $tags = [],
array $logAtAdditionalWikis = [] )

Changes the user groups, ensuring that the performer has the necessary permissions and that the changes are logged.

Parameters
Authority$performer
UserIdentity$target
list<string>$addGroups The groups to add (or change expiry of)
list<string>$removeGroups The groups to remove
array<string,?string>$newExpiries Map of group name to new expiry (string timestamp or null for infinite). If a group is in $addGroups but not in this array, it won't expire.
string$reason
array$tags
list<string>$logAtAdditionalWikis List of wiki IDs where the log entry should be added, in addition to the current wiki and the target user's wiki. Wikis to which the log entry will be added are deduplicated, so no double logging will happen.
Returns
array{0:string[],1:string[]} The groups actually added and removed

Definition at line 198 of file UserGroupAssignmentService.php.

◆ targetCanHaveUserGroups()

MediaWiki\User\UserGroupAssignmentService::targetCanHaveUserGroups ( UserIdentity $target)

Definition at line 58 of file UserGroupAssignmentService.php.

◆ userCanChangeRights()

MediaWiki\User\UserGroupAssignmentService::userCanChangeRights ( Authority $performer,
UserIdentity $target )

Check whether the given user can change the target user's rights.

Parameters
Authority$performerUser who is attempting to change the target's rights
UserIdentity$targetUser whose rights are being changed

Definition at line 86 of file UserGroupAssignmentService.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserGroupAssignmentService::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const UserrightsInterwikiDelimiter
Name constant for the UserrightsInterwikiDelimiter setting, for use with Config::get()
Access: internal

Definition at line 36 of file UserGroupAssignmentService.php.


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