MediaWiki  1.34.0
UserGroupMembership Class Reference

Represents a "user group membership" – a specific instance of a user belonging to a group. More...

Public Member Functions

 __construct ( $userId=0, $group=null, $expiry=null)
 
 delete (IDatabase $dbw=null)
 Delete the row from the user_groups table. More...
 
 getExpiry ()
 
 getGroup ()
 
 getUserId ()
 
 insert ( $allowUpdate=false, IDatabase $dbw=null)
 Insert a user right membership into the database. More...
 
 isExpired ()
 Has the membership expired? More...
 

Static Public Member Functions

static getGroupMemberName ( $group, $username)
 Gets the localized name for a member of a group, if it exists. More...
 
static getGroupName ( $group)
 Gets the localized friendly name for a group, if it exists. More...
 
static getGroupPage ( $group)
 Gets the title of a page describing a particular user group. More...
 
static getLink ( $ugm, IContextSource $context, $format, $userName=null)
 Gets a link for a user group, possibly including the expiry date if relevant. More...
 
static getMembership ( $userId, $group, IDatabase $db=null)
 Returns a UserGroupMembership object that pertains to the given user and group, or false if the user does not belong to that group (or the assignment has expired). More...
 
static getMembershipsForUser ( $userId, IDatabase $db=null)
 Returns UserGroupMembership objects for all the groups a user currently belongs to. More...
 
static newFromRow ( $row)
 Creates a new UserGroupMembership object from a database row. More...
 
static purgeExpired ()
 Purge expired memberships from the user_groups table. More...
 
static selectFields ()
 Returns the list of user_groups fields that should be selected to create a new user group membership. More...
 

Protected Member Functions

 getDatabaseArray (IDatabase $db)
 Get an array suitable for passing to $dbw->insert() or $dbw->update() More...
 
 initFromRow ( $row)
 

Private Attributes

string null $expiry
 Timestamp of expiry in TS_MW format, or null if no expiry. More...
 
string $group
 
int $userId
 The ID of the user who belongs to the group. More...
 

Detailed Description

Represents a "user group membership" – a specific instance of a user belonging to a group.

For example, the fact that user Mary belongs to the sysop group is a user group membership.

The class encapsulates rows in the user_groups table. The logic is low-level and doesn't run any hooks. Often, you will want to call User::addGroup() or User::removeGroup() instead.

Since
1.29

Definition at line 37 of file UserGroupMembership.php.

Constructor & Destructor Documentation

◆ __construct()

UserGroupMembership::__construct (   $userId = 0,
  $group = null,
  $expiry = null 
)
Parameters
int$userIdThe ID of the user who belongs to the group
string | null$groupThe internal group name
string | null$expiryTimestamp of expiry in TS_MW format, or null if no expiry

Definition at line 52 of file UserGroupMembership.php.

References $expiry, $group, and $userId.

Member Function Documentation

◆ delete()

UserGroupMembership::delete ( IDatabase  $dbw = null)

Delete the row from the user_groups table.

Exceptions
MWException
Parameters
IDatabase | null$dbwOptional master database connection to use
Returns
bool Whether or not anything was deleted

Definition at line 119 of file UserGroupMembership.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), DB_MASTER, Wikimedia\Rdbms\IDatabase\delete(), Wikimedia\Rdbms\IDatabase\insert(), wfGetDB(), and wfReadOnly().

◆ getDatabaseArray()

UserGroupMembership::getDatabaseArray ( IDatabase  $db)
protected

Get an array suitable for passing to $dbw->insert() or $dbw->update()

Parameters
IDatabase$db
Returns
array

Definition at line 220 of file UserGroupMembership.php.

References $group, $userId, and Wikimedia\Rdbms\IDatabase\timestamp().

Referenced by insert().

◆ getExpiry()

UserGroupMembership::getExpiry ( )
Returns
string|null Timestamp of expiry in TS_MW format, or null if no expiry

Definition at line 75 of file UserGroupMembership.php.

References $expiry.

Referenced by MediaWiki\Preferences\DefaultPreferencesFactory\profilePreferences().

◆ getGroup()

UserGroupMembership::getGroup ( )
Returns
string

Definition at line 68 of file UserGroupMembership.php.

References $group.

◆ getGroupMemberName()

static UserGroupMembership::getGroupMemberName (   $group,
  $username 
)
static

Gets the localized name for a member of a group, if it exists.

For example, "administrator" or "bureaucrat"

Parameters
string$groupInternal group name
string$usernameUsername for gender
Returns
string Localized name for group member

Definition at line 448 of file UserGroupMembership.php.

References $group, and wfMessage().

Referenced by getLink(), RightsLogFormatter\getMessageParameters(), and UserrightsPage\groupCheckboxes().

◆ getGroupName()

static UserGroupMembership::getGroupName (   $group)
static

Gets the localized friendly name for a group, if it exists.

For example, "Administrators" or "Bureaucrats"

Parameters
string$groupInternal group name
Returns
string Localized friendly group name

Definition at line 435 of file UserGroupMembership.php.

References $group, and wfMessage().

Referenced by SpecialActiveUsers\buildForm(), SpecialPasswordPolicies\execute(), SpecialListGroupRights\execute(), UsersPager\getAllGroups(), and getLink().

◆ getGroupPage()

static UserGroupMembership::getGroupPage (   $group)
static

Gets the title of a page describing a particular user group.

When the name of the group appears in the UI, it can link to this page.

Parameters
string$groupInternal group name
Returns
Title|bool Title of the page if it exists, false otherwise

Definition at line 460 of file UserGroupMembership.php.

References $title, Title\newFromText(), and wfMessage().

Referenced by UsersPager\doBatchLookups(), SpecialListGroupRights\execute(), SpecialPasswordPolicies\execute(), and getLink().

◆ getLink()

static UserGroupMembership::getLink (   $ugm,
IContextSource  $context,
  $format,
  $userName = null 
)
static

Gets a link for a user group, possibly including the expiry date if relevant.

Parameters
string | UserGroupMembership$ugmEither a group name as a string, or a UserGroupMembership object
IContextSource$context
string$formatEither 'wiki' or 'html'
string | null$userNameIf you want to use the group member message ("administrator"), pass the name of the user who belongs to the group; it is used for GENDER of the group member message. If you instead want the group name message ("Administrators"), omit this parameter.
Returns
string

Definition at line 376 of file UserGroupMembership.php.

References $context, $expiry, $group, getGroupMemberName(), getGroupName(), and getGroupPage().

Referenced by PermissionsError\__construct(), UsersPager\buildGroupLink(), SpecialListGroupRights\formatPermissions(), User\newFatalPermissionDeniedStatus(), MediaWiki\Preferences\DefaultPreferencesFactory\profilePreferences(), and UserrightsPage\showEditUserGroupsForm().

◆ getMembership()

static UserGroupMembership::getMembership (   $userId,
  $group,
IDatabase  $db = null 
)
static

Returns a UserGroupMembership object that pertains to the given user and group, or false if the user does not belong to that group (or the assignment has expired).

Parameters
int$userIdID of the user to search for
string$groupUser group name
IDatabase | null$dbOptional database connection
Returns
UserGroupMembership|false

Definition at line 343 of file UserGroupMembership.php.

References $group, $userId, DB_REPLICA, newFromRow(), and wfGetDB().

Referenced by UserRightsProxy\removeGroup(), and User\removeGroup().

◆ getMembershipsForUser()

static UserGroupMembership::getMembershipsForUser (   $userId,
IDatabase  $db = null 
)
static

Returns UserGroupMembership objects for all the groups a user currently belongs to.

Parameters
int$userIdID of the user to search for
IDatabase | null$dbOptional database connection
Returns
UserGroupMembership[] Associative array of (group name => UserGroupMembership object)

Definition at line 311 of file UserGroupMembership.php.

References $res, $userId, DB_REPLICA, newFromRow(), and wfGetDB().

Referenced by UserRightsProxy\getGroupMemberships(), and User\loadGroups().

◆ getUserId()

UserGroupMembership::getUserId ( )
Returns
int

Definition at line 61 of file UserGroupMembership.php.

References $userId.

◆ initFromRow()

UserGroupMembership::initFromRow (   $row)
protected

Definition at line 79 of file UserGroupMembership.php.

References wfTimestamp().

◆ insert()

UserGroupMembership::insert (   $allowUpdate = false,
IDatabase  $dbw = null 
)

Insert a user right membership into the database.

When $allowUpdate is false, the function fails if there is a conflicting membership entry (same user and group) already in the table.

Exceptions
UnexpectedValueException
Parameters
bool$allowUpdateWhether to perform "upsert" instead of INSERT
IDatabase | null$dbwIf you have one available
Returns
bool Whether or not anything was inserted

Definition at line 156 of file UserGroupMembership.php.

References DeferredUpdates\addCallableUpdate(), Wikimedia\Rdbms\IDatabase\addQuotes(), Wikimedia\Rdbms\IDatabase\affectedRows(), DB_MASTER, Wikimedia\Rdbms\IDatabase\endAtomic(), getDatabaseArray(), Wikimedia\Rdbms\IDatabase\insert(), Wikimedia\Rdbms\IDatabase\selectField(), JobQueueGroup\singleton(), Wikimedia\Rdbms\IDatabase\startAtomic(), Wikimedia\Rdbms\IDatabase\timestamp(), Wikimedia\Rdbms\IDatabase\update(), and wfGetDB().

◆ isExpired()

UserGroupMembership::isExpired ( )

Has the membership expired?

Returns
bool

Definition at line 232 of file UserGroupMembership.php.

References $expiry, and wfTimestampNow().

◆ newFromRow()

static UserGroupMembership::newFromRow (   $row)
static

Creates a new UserGroupMembership object from a database row.

Parameters
stdClass$rowThe row from the user_groups table
Returns
UserGroupMembership

Definition at line 93 of file UserGroupMembership.php.

Referenced by UsersPager\doBatchLookups(), getMembership(), getMembershipsForUser(), and User\loadFromRow().

◆ purgeExpired()

static UserGroupMembership::purgeExpired ( )
static

◆ selectFields()

static UserGroupMembership::selectFields ( )
static

Returns the list of user_groups fields that should be selected to create a new user group membership.

Returns
array

Definition at line 104 of file UserGroupMembership.php.

Referenced by UsersPager\doBatchLookups(), and ApiQueryUsers\execute().

Member Data Documentation

◆ $expiry

string null UserGroupMembership::$expiry
private

Timestamp of expiry in TS_MW format, or null if no expiry.

Definition at line 45 of file UserGroupMembership.php.

Referenced by __construct(), getExpiry(), getLink(), and isExpired().

◆ $group

string UserGroupMembership::$group
private

◆ $userId

int UserGroupMembership::$userId
private

The ID of the user who belongs to the group.

Definition at line 39 of file UserGroupMembership.php.

Referenced by __construct(), getDatabaseArray(), getMembership(), getMembershipsForUser(), and getUserId().


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