2declare( strict_types=1 );
44 $this->tempUserConfig = $tempUserConfig;
45 $this->specialPageFactory = $specialPageFactory;
46 $this->linkRenderer = $linkRenderer;
47 $this->tempUserDetailsLookup = $tempUserDetailsLookup;
68 ?
string $altUserName =
null,
69 array $attributes = []
71 $outputPage = $context->getOutput();
72 $outputPage->addModuleStyles( [
73 'mediawiki.interface.helpers.styles',
74 'mediawiki.interface.helpers.linker.styles'
77 return $this->userLinkCache->getWithSetCallback(
78 $this->userLinkCache->makeKey(
81 implode(
' ', $attributes )
83 fn () => $this->renderUserLink( $targetUser, $context, $altUserName, $attributes )
98 private function renderUserLink(
101 ?
string $altUserName =
null,
102 array $attributes = []
104 $userName = $targetUser->getName();
106 $classes = [
'mw-userlink' ];
110 if ( $this->tempUserConfig->isTempName( $userName ) ) {
111 $classes[] =
'mw-tempuserlink';
112 $attributes[
'data-mw-target'] = $userName;
115 if ( $this->tempUserDetailsLookup->isExpired( $targetUser ) ) {
116 $classes[] =
'mw-tempuserlink-expired';
118 $description = $messageLocalizer->
msg(
'tempuser-expired-link-tooltip' )->text();
123 'role' =>
'presentation',
124 'class' =>
'cdx-tooltip mw-tempuserlink-expired--tooltip',
129 $attributes[
'aria-description'] = $description;
133 $attributes[
'title'] =
null;
136 $pageName = $this->specialPageFactory->getLocalNameFor(
'Contributions', $userName );
137 $page =
new TitleValue(
NS_SPECIAL, $pageName );
139 $page = ExternalUserNames::getUserLinkTitle( $userName );
141 if ( ExternalUserNames::isExternal( $userName ) ) {
142 $classes[] =
'mw-extuserlink';
143 } elseif ( $altUserName ===
null ) {
144 $altUserName = IPUtils::prettifyIP( $userName );
146 $classes[] =
'mw-anonuserlink';
148 $page = TitleValue::tryNew(
NS_USER, strtr( $userName,
' ',
'_' ) );
153 '<bdi>' . htmlspecialchars( $altUserName ?? $userName ) .
'</bdi>'
156 if ( isset( $attributes[
'class'] ) ) {
157 $classes[] = $attributes[
'class'];
160 $attributes[
'class'] = $classes;
162 if ( $page !==
null ) {
163 return $this->linkRenderer->makeLink( $page,
new HtmlArmor( $linkText ), $attributes );
166 return Html::rawElement(
'span', $attributes, $linkText );
Factory for handling the special page list and generating SpecialPage objects.
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.
msg( $key,... $params)
This is the method for getting translated interface messages.