MediaWiki REL1_35
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.
 
 equals (UserGroupMembership $ugm)
 Compares two pure value objects.
 
 getExpiry ()
 
 getGroup ()
 
 getUserId ()
 
 insert ( $allowUpdate=false, IDatabase $dbw=null)
 Insert a user right membership into the database.
 
 isExpired ()
 Has the membership expired?
 

Static Public Member Functions

static getGroupMemberName ( $group, $username)
 Gets the localized name for a member of a group, if it exists.
 
static getGroupName ( $group)
 Gets the localized friendly name for a group, if it exists.
 
static getGroupPage ( $group)
 Gets the title of a page describing a particular user group.
 
static getLink ( $ugm, IContextSource $context, $format, $userName=null)
 Gets a link for a user group, possibly including the expiry date if relevant.
 
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).
 
static getMembershipsForUser ( $userId, IDatabase $db=null)
 Returns UserGroupMembership objects for all the groups a user currently belongs to.
 
static newFromRow ( $row)
 Creates a new UserGroupMembership object from a database row.
 
static purgeExpired ()
 Purge expired memberships from the user_groups table.
 
static selectFields ()
 Returns the list of user_groups fields that should be selected to create a new user group membership.
 

Protected Member Functions

 initFromRow ( $row)
 

Static Private Member Functions

static assertValidSpec ( $userId, $group, $expiry)
 Asserts that the given parameters could be used to construct a UserGroupMembership object.
 

Private Attributes

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

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 is a pure value object. Use UserGroupManager to modify user group memberships.

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 56 of file UserGroupMembership.php.

References $expiry, and wfTimestampNow().

Member Function Documentation

◆ assertValidSpec()

static UserGroupMembership::assertValidSpec (   $userId,
  $group,
  $expiry 
)
staticprivate

Asserts that the given parameters could be used to construct a UserGroupMembership object.

Parameters
int$userId
string | null$group
string | null$expiry
Exceptions
ParameterTypeException

Definition at line 73 of file UserGroupMembership.php.

References $expiry.

◆ 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
Deprecated:
since 1.35, use UserGroupManager::removeUserFromGroup instead

Definition at line 151 of file UserGroupMembership.php.

References getUserId(), User\newFromId(), and wfDeprecated().

◆ equals()

UserGroupMembership::equals ( UserGroupMembership  $ugm)

Compares two pure value objects.

Parameters
UserGroupMembership$ugm
Returns
bool
Since
1.35

Definition at line 388 of file UserGroupMembership.php.

References getGroup(), and getUserId().

◆ getExpiry()

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

Definition at line 96 of file UserGroupMembership.php.

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

◆ getGroup()

UserGroupMembership::getGroup ( )
Returns
string

Definition at line 89 of file UserGroupMembership.php.

Referenced by equals().

◆ 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 357 of file UserGroupMembership.php.

References wfMessage().

◆ 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 344 of file UserGroupMembership.php.

References wfMessage().

◆ 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 369 of file UserGroupMembership.php.

References $title, and wfMessage().

◆ 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 279 of file UserGroupMembership.php.

References $expiry, IContextSource\getLanguage(), IContextSource\getUser(), MessageLocalizer\msg(), and Message\rawParam().

◆ 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$dbunused since 1.35
Returns
UserGroupMembership|false
Deprecated:
since 1.35, use UserGroupManager::getUserGroupMemberships instead

Definition at line 252 of file UserGroupMembership.php.

References User\newFromId(), and wfDeprecated().

◆ 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$dbunused since 1.35
Returns
UserGroupMembership[] Associative array of (group name => UserGroupMembership object)
Deprecated:
since 1.35, use UserGroupManager::getUserGroupMemberships instead

Definition at line 227 of file UserGroupMembership.php.

References User\newFromId(), and wfDeprecated().

◆ getUserId()

UserGroupMembership::getUserId ( )
Returns
int

Definition at line 82 of file UserGroupMembership.php.

Referenced by delete(), equals(), and insert().

◆ initFromRow()

UserGroupMembership::initFromRow (   $row)
protected
Deprecated:
since 1.35
Parameters
$row

Definition at line 104 of file UserGroupMembership.php.

References wfDeprecated(), and 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
Deprecated:
since 1.35, use UserGroupManager::addUserToGroup instead

Definition at line 177 of file UserGroupMembership.php.

References getUserId(), User\newFromId(), and wfDeprecated().

◆ isExpired()

UserGroupMembership::isExpired ( )

Has the membership expired?

Returns
bool

Definition at line 198 of file UserGroupMembership.php.

◆ 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
Deprecated:
since 1.35, use UserGroupMembership constructor instead

Definition at line 121 of file UserGroupMembership.php.

References wfDeprecated(), and wfTimestamp().

◆ purgeExpired()

static UserGroupMembership::purgeExpired ( )
static

Purge expired memberships from the user_groups table.

Returns
int|bool false if purging wasn't attempted (e.g. because of readonly), the number of rows purged (might be 0) otherwise
Deprecated:
since 1.35, use UserGroupManager::purgeExpired instead

Definition at line 210 of file UserGroupMembership.php.

References wfDeprecated().

◆ 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
Deprecated:
since 1.35, use UserGroupManager::getQueryInfo instead

Definition at line 137 of file UserGroupMembership.php.

References wfDeprecated().

Member Data Documentation

◆ $expired

bool UserGroupMembership::$expired
private

Expiration flag.

Definition at line 49 of file UserGroupMembership.php.

◆ $expiry

string null UserGroupMembership::$expiry
private

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

Definition at line 46 of file UserGroupMembership.php.

Referenced by __construct(), assertValidSpec(), and getLink().

◆ $group

string UserGroupMembership::$group
private

Definition at line 43 of file UserGroupMembership.php.

◆ $userId

int UserGroupMembership::$userId
private

The ID of the user who belongs to the group.

Definition at line 40 of file UserGroupMembership.php.


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