25use InvalidArgumentException;
60 public function __construct(
int $userId = 0, ?
string $group =
null, ?
string $expiry =
null ) {
61 $this->userId = $userId;
62 $this->group = $group;
63 $this->expiry = $expiry ?:
null;
94 return $this->expired;
119 throw new InvalidArgumentException(
'UserGroupMembership::getLink() $format parameter should be ' .
120 "'wiki' or 'html'" );
140 'linkTitle' => $linkTitle,
141 'groupName' => $groupName
142 ] = self::getLinkInfo( $ugm, $context, $userName );
147 $groupLink = $linkRenderer->makeLink( $linkTitle, $groupName );
149 $groupLink = htmlspecialchars( $groupName );
154 'expiryDT' => $expiryDT,
155 'expiryD' => $expiryD,
156 'expiryT' => $expiryT
157 ] = self::getLinkExpiryParams( $context, $expiry );
159 return $context->
msg(
'group-membership-link-with-expiry' )
160 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->escaped();
181 'linkTitle' => $linkTitle,
182 'groupName' => $groupName
183 ] = self::getLinkInfo( $ugm, $context, $userName );
187 $linkPage = $linkTitle->getFullText();
188 $groupLink =
"[[$linkPage|$groupName]]";
190 $groupLink = $groupName;
195 'expiryDT' => $expiryDT,
196 'expiryD' => $expiryD,
197 'expiryT' => $expiryT
198 ] = self::getLinkExpiryParams( $context, $expiry );
199 return $context->
msg(
'group-membership-link-with-expiry' )
200 ->params( $groupLink, $expiryDT, $expiryD, $expiryT )->text();
211 private static function getLinkInfo( $ugm, $context, $userName =
null ): array {
212 if ( $ugm instanceof UserGroupMembership ) {
213 $expiry = $ugm->getExpiry();
214 $group = $ugm->getGroup();
221 if ( $userName !==
null ) {
222 $groupName = $uiLanguage->getGroupMemberName( $group, $userName );
224 $groupName = $uiLanguage->getGroupName( $group );
226 $linkTitle = self::getGroupPage( $group );
227 return [
'expiry' => $expiry,
'linkTitle' => $linkTitle,
'groupName' => $groupName ];
235 private static function getLinkExpiryParams( IContextSource $context,
string $expiry ): array {
237 $uiLanguage = $context->getLanguage();
238 $uiUser = $context->getUser();
239 $expiryDT = $uiLanguage->userTimeAndDate( $expiry, $uiUser );
240 $expiryD = $uiLanguage->userDate( $expiry, $uiUser );
241 $expiryT = $uiLanguage->userTime( $expiry, $uiUser );
242 return [
'expiryDT' => $expiryDT,
'expiryD' => $expiryD,
'expiryT' => $expiryT ];
255 return RequestContext::getMain()->getLanguage()->getGroupName( $group );
270 return RequestContext::getMain()->getLanguage()->getGroupMemberName( $group, $member );
281 $msg =
wfMessage(
"grouppage-$group" )->inContentLanguage();
282 if ( $msg->exists() ) {
283 $title = Title::newFromText( $msg->text() );
284 if ( is_object( $title ) ) {
302 && $ugm->
getGroup() === $this->group
309class_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.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
Group all the pieces relevant to the context of a request into one instance.
Interface for objects which can provide a MediaWiki context on request.
msg( $key,... $params)
This is the method for getting translated interface messages.