MediaWiki REL1_30
|
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. | |
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 (IDatabase $dbw=null) |
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 | |
getDatabaseArray (IDatabase $db) | |
Get an array suitable for passing to $dbw->insert() or $dbw->update() | |
initFromRow ( $row) | |
Private Attributes | |
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. | |
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.
Definition at line 36 of file UserGroupMembership.php.
UserGroupMembership::__construct | ( | $userId = 0, | |
$group = null, | |||
$expiry = null ) |
UserGroupMembership::delete | ( | IDatabase | $dbw = null | ) |
Delete the row from the user_groups table.
MWException |
IDatabase | null | $dbw | Optional master database connection to use |
Definition at line 118 of file UserGroupMembership.php.
References Wikimedia\Rdbms\IDatabase\affectedRows(), DB_MASTER, Wikimedia\Rdbms\IDatabase\delete(), group, Wikimedia\Rdbms\IDatabase\insert(), wfGetDB(), and wfReadOnly().
|
protected |
Get an array suitable for passing to $dbw->insert() or $dbw->update()
IDatabase | $db |
Definition at line 217 of file UserGroupMembership.php.
References $group, $userId, and Wikimedia\Rdbms\IDatabase\timestamp().
Referenced by insert().
UserGroupMembership::getExpiry | ( | ) |
Definition at line 74 of file UserGroupMembership.php.
References $expiry.
Referenced by Preferences\profilePreferences().
UserGroupMembership::getGroup | ( | ) |
|
static |
Gets the localized name for a member of a group, if it exists.
For example, "administrator" or "bureaucrat"
string | $group | Internal group name |
string | $username | Username for gender |
Definition at line 418 of file UserGroupMembership.php.
References $group, $username, and wfMessage().
Referenced by User\getGroupMember(), getLink(), RightsLogFormatter\getMessageParameters(), and UserrightsPage\groupCheckboxes().
|
static |
Gets the localized friendly name for a group, if it exists.
For example, "Administrators" or "Bureaucrats"
string | $group | Internal group name |
Definition at line 405 of file UserGroupMembership.php.
References $group, and wfMessage().
Referenced by SpecialActiveUsers\buildForm(), UsersPager\getAllGroups(), User\getGroupName(), getLink(), User\makeGroupLinkHTML(), and User\makeGroupLinkWiki().
|
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.
string | $group | Internal group name |
Definition at line 430 of file UserGroupMembership.php.
References $title, and wfMessage().
Referenced by UsersPager\doBatchLookups(), User\getGroupPage(), getLink(), User\makeGroupLinkHTML(), and User\makeGroupLinkWiki().
|
static |
Gets a link for a user group, possibly including the expiry date if relevant.
string | UserGroupMembership | $ugm | Either a group name as a string, or a UserGroupMembership object |
IContextSource | $context | |
string | $format | Either 'wiki' or 'html' |
string | null | $userName | If 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. |
Definition at line 346 of file UserGroupMembership.php.
References $context, $expiry, $group, getGroupMemberName(), getGroupName(), getGroupPage(), and Linker\link().
Referenced by PermissionsError\__construct(), UsersPager\buildGroupLink(), SpecialListGroupRights\formatPermissions(), User\newFatalPermissionDeniedStatus(), Preferences\profilePreferences(), and UserrightsPage\showEditUserGroupsForm().
|
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).
int | $userId | ID of the user to search for |
string | $group | User group name |
IDatabase | null | $db | Optional database connection |
Definition at line 312 of file UserGroupMembership.php.
References $group, $userId, DB_REPLICA, newFromRow(), and wfGetDB().
Referenced by User\removeGroup(), UserRightsProxy\removeGroup(), and UserGroupMembershipTest\testGetMembership().
|
static |
Returns UserGroupMembership objects for all the groups a user currently belongs to.
int | $userId | ID of the user to search for |
IDatabase | null | $db | Optional database connection |
Definition at line 281 of file UserGroupMembership.php.
References $res, $userId, DB_REPLICA, newFromRow(), and wfGetDB().
Referenced by UserRightsProxy\getGroupMemberships(), User\loadGroups(), and UserGroupMembershipTest\testGetMembershipsForUser().
UserGroupMembership::getUserId | ( | ) |
|
protected |
Definition at line 78 of file UserGroupMembership.php.
References group, and wfTimestamp().
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.
MWException |
bool | $allowUpdate | Whether to perform "upsert" instead of INSERT |
IDatabase | null | $dbw | If you have one available |
Definition at line 155 of file UserGroupMembership.php.
References Wikimedia\Rdbms\IDatabase\addQuotes(), Wikimedia\Rdbms\IDatabase\affectedRows(), DB_MASTER, getDatabaseArray(), group, Wikimedia\Rdbms\IDatabase\insert(), purgeExpired(), Wikimedia\Rdbms\IDatabase\selectRow(), Wikimedia\Rdbms\IDatabase\timestamp(), Wikimedia\Rdbms\IDatabase\update(), and wfGetDB().
UserGroupMembership::isExpired | ( | ) |
Has the membership expired?
Definition at line 229 of file UserGroupMembership.php.
References $expiry, and wfTimestampNow().
|
static |
Creates a new UserGroupMembership object from a database row.
stdClass | $row | The row from the user_groups table |
Definition at line 92 of file UserGroupMembership.php.
Referenced by UsersPager\doBatchLookups(), getMembership(), getMembershipsForUser(), and User\loadFromRow().
|
static |
Purge expired memberships from the user_groups table.
IDatabase | null | $dbw |
Definition at line 242 of file UserGroupMembership.php.
References $fname, $res, Wikimedia\Rdbms\IDatabase\addQuotes(), DB_MASTER, Wikimedia\Rdbms\IDatabase\delete(), Wikimedia\Rdbms\IDatabase\insert(), Wikimedia\Rdbms\IDatabase\select(), Wikimedia\Rdbms\IDatabase\timestamp(), wfGetDB(), and wfReadOnly().
Referenced by insert().
|
static |
Returns the list of user_groups fields that should be selected to create a new user group membership.
Definition at line 103 of file UserGroupMembership.php.
Referenced by UsersPager\doBatchLookups(), and ApiQueryUsers\execute().
|
private |
Timestamp of expiry in TS_MW format, or null if no expiry.
Definition at line 44 of file UserGroupMembership.php.
Referenced by __construct(), getExpiry(), getLink(), and isExpired().
|
private |
Definition at line 41 of file UserGroupMembership.php.
Referenced by __construct(), getDatabaseArray(), getGroup(), getGroupMemberName(), getGroupName(), getLink(), and getMembership().
|
private |
The ID of the user who belongs to the group.
Definition at line 38 of file UserGroupMembership.php.
Referenced by __construct(), getDatabaseArray(), getMembership(), getMembershipsForUser(), and getUserId().