MediaWiki master
MediaWiki\User\UserGroupAssignmentService Class Reference

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

Public Member Functions

 __construct (private readonly UserGroupManagerFactory $userGroupManagerFactory, private readonly UserNameUtils $userNameUtils, private readonly UserFactory $userFactory, private readonly RestrictedUserGroupChecker $restrictedGroupChecker, private readonly HookRunner $hookRunner, private readonly ServiceOptions $options, private readonly TempUserConfig $tempUserConfig,)
 
 getChangeableGroups (Authority $performer, UserIdentity $target)
 Returns the groups that the performer can add or remove from the target user.
 
 getPageTitleForTargetUser (UserIdentity $target)
 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=[])
 Changes the user groups, ensuring that the performer has the necessary permissions and that the changes are logged.
 
 targetCanHaveUserGroups (UserIdentity $target)
 Checks whether the target user can have groups assigned at all.
 
 userCanChangeRights (Authority $performer, UserIdentity $target)
 Check whether the given user can change the target user's rights.
 

Static Public Member Functions

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.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

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 29 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 RestrictedUserGroupChecker $restrictedGroupChecker,
private readonly HookRunner $hookRunner,
private readonly ServiceOptions $options,
private readonly TempUserConfig $tempUserConfig )

Definition at line 38 of file UserGroupAssignmentService.php.

Member Function Documentation

◆ enforceChangeGroupPermissions()

static MediaWiki\User\UserGroupAssignmentService::enforceChangeGroupPermissions ( array & $addGroups,
array & $removeGroups,
array & $newExpiries,
array $existingUGMs,
array $permittedChanges )
static

Ensures that the content of $addGroups, $removeGroups and $newExpiries is compliant with the possible changes defined in $permittedChanges.

If there's a change that is not permitted, it is removed from the respective array.

Parameters
list<string>&$addGroups
list<string>&$removeGroups
array<string,?string>&$newExpiries
array<string,UserGroupMembership>$existingUGMs
array{add:list<string>,remove:list<string>}$permittedChanges
Returns
void

Definition at line 315 of file UserGroupAssignmentService.php.

◆ expiryToTimestamp()

static MediaWiki\User\UserGroupAssignmentService::expiryToTimestamp ( $expiry)
static

Converts a user group membership expiry string into a timestamp.

Words like 'existing' or 'other' should have been filtered out before calling this function.

Parameters
string$expiry
Returns
string|null|false A string containing a valid timestamp, or null if the expiry is infinite, or false if the timestamp is not valid

Definition at line 396 of file UserGroupAssignmentService.php.

References wfIsInfinity(), and wfTimestamp().

◆ getChangeableGroups()

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

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.

Returns
array [ 'add' => [ addablegroups ], 'remove' => [ removablegroups ], 'restricted' => [ groupname => [ 'condition-met' => bool, 'ignore-condition' => bool, 'message' => string ] ] ]

Definition at line 108 of file UserGroupAssignmentService.php.

◆ getPageTitleForTargetUser()

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

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

The returned value doesn't include the namespace.

Definition at line 287 of file UserGroupAssignmentService.php.

References MediaWiki\DAO\WikiAwareEntity\getWikiId().

◆ saveChangesToUserGroups()

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

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
Returns
array{0:string[],1:string[]} The groups actually added and removed

Definition at line 186 of file UserGroupAssignmentService.php.

◆ targetCanHaveUserGroups()

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

Checks whether the target user can have groups assigned at all.

Definition at line 53 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 81 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 32 of file UserGroupAssignmentService.php.


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