25use InvalidArgumentException;
59 public function __construct(
int $userId = 0, ?
string $group =
null, ?
string $expiry =
null ) {
60 $this->userId = $userId;
61 $this->group = $group;
62 $this->expiry = $expiry ?:
null;
93 return $this->expired;
118 throw new InvalidArgumentException(
'UserGroupMembership::getLink() $format parameter should be ' .
119 "'wiki' or 'html'" );
139 'linkTitle' => $linkTitle,
140 'groupName' => $groupName
141 ] = self::getLinkInfo( $ugm, $context, $userName );
146 $groupLink = $linkRenderer->makeLink( $linkTitle, $groupName );
148 $groupLink = htmlspecialchars( $groupName );
153 'expiryDT' => $expiryDT,
154 'expiryD' => $expiryD,
155 'expiryT' => $expiryT
156 ] = self::getLinkExpiryParams( $context, $expiry );
158 return $context->
msg(
'group-membership-link-with-expiry' )
159 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->escaped();
180 'linkTitle' => $linkTitle,
181 'groupName' => $groupName
182 ] = self::getLinkInfo( $ugm, $context, $userName );
186 $linkPage = $linkTitle->getFullText();
187 $groupLink =
"[[$linkPage|$groupName]]";
189 $groupLink = $groupName;
194 'expiryDT' => $expiryDT,
195 'expiryD' => $expiryD,
196 'expiryT' => $expiryT
197 ] = self::getLinkExpiryParams( $context, $expiry );
198 return $context->
msg(
'group-membership-link-with-expiry' )
199 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->text();
210 private static function getLinkInfo( $ugm, $context, $userName =
null ): array {
211 if ( $ugm instanceof UserGroupMembership ) {
212 $expiry = $ugm->getExpiry();
213 $group = $ugm->getGroup();
220 if ( $userName !==
null ) {
221 $groupName = $uiLanguage->getGroupMemberName( $group, $userName );
223 $groupName = $uiLanguage->getGroupName( $group );
225 $linkTitle = self::getGroupPage( $group );
226 return [
'expiry' => $expiry,
'linkTitle' => $linkTitle,
'groupName' => $groupName ];
234 private static function getLinkExpiryParams( IContextSource $context,
string $expiry ): array {
236 $uiLanguage = $context->getLanguage();
237 $uiUser = $context->getUser();
238 $expiryDT = $uiLanguage->userTimeAndDate( $expiry, $uiUser );
239 $expiryD = $uiLanguage->userDate( $expiry, $uiUser );
240 $expiryT = $uiLanguage->userTime( $expiry, $uiUser );
241 return [
'expiryDT' => $expiryDT,
'expiryD' => $expiryD,
'expiryT' => $expiryT ];
252 $msg =
wfMessage(
"grouppage-$group" )->inContentLanguage();
253 if ( $msg->exists() ) {
254 $title = Title::newFromText( $msg->text() );
255 if ( is_object( $title ) ) {
273 && $ugm->
getGroup() === $this->group
280class_alias( UserGroupMembership::class,
'UserGroupMembership' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.