53 public function __construct(
int $userId = 0, ?
string $group =
null, ?
string $expiry =
null ) {
56 $this->expiry =
$expiry ?:
null;
87 return $this->expired;
104 if ( $format !==
'wiki' && $format !==
'html' ) {
105 throw new MWException(
'UserGroupMembership::getLink() $format parameter should be ' .
106 "'wiki' or 'html'" );
111 $group = $ugm->getGroup();
117 if ( $userName !==
null ) {
118 $groupName = self::getGroupMemberName(
$group, $userName );
120 $groupName = self::getGroupName(
$group );
124 $linkTitle = self::getGroupPage(
$group );
125 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
126 if ( $format ===
'wiki' ) {
128 $linkPage = $linkTitle->getFullText();
129 $groupLink =
"[[$linkPage|$groupName]]";
131 $groupLink = $groupName;
135 $groupLink = $linkRenderer->makeLink( $linkTitle, $groupName );
137 $groupLink = htmlspecialchars( $groupName );
145 $expiryDT = $uiLanguage->userTimeAndDate(
$expiry, $uiUser );
146 $expiryD = $uiLanguage->userDate(
$expiry, $uiUser );
147 $expiryT = $uiLanguage->userTime(
$expiry, $uiUser );
149 if ( $format ===
'wiki' ) {
150 return $context->
msg(
'group-membership-link-with-expiry' )
151 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->text();
154 return $context->
msg(
'group-membership-link-with-expiry' )
155 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->escaped();
170 return $msg->isBlank() ?
$group : $msg->text();
182 $msg =
wfMessage(
"group-$group-member", $username );
183 return $msg->isBlank() ?
$group : $msg->text();
194 $msg =
wfMessage(
"grouppage-$group" )->inContentLanguage();
195 if ( $msg->exists() ) {
196 $title = Title::newFromText( $msg->text() );
197 if ( is_object(
$title ) ) {
215 && $ugm->
getGroup() === $this->group
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Represents a "user group membership" – a specific instance of a user belonging to a group.
static getGroupPage( $group)
Gets the title of a page describing a particular user group.
__construct(int $userId=0, ?string $group=null, ?string $expiry=null)
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
int $userId
The ID of the user who belongs to the group.
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
isExpired()
Has the membership expired?
static getGroupMemberName( $group, $username)
Gets the localized name for a member of a group, if it exists.
string null $expiry
Timestamp of expiry in TS_MW format, or null if no expiry.
equals(UserGroupMembership $ugm)
Compares two pure value objects.
bool $expired
Expiration flag.
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.