2declare( strict_types=1 );
18use Wikimedia\Timestamp\ConvertibleTimestamp;
45 $this->tempUserConfig = $tempUserConfig;
46 $this->specialPageFactory = $specialPageFactory;
47 $this->linkRenderer = $linkRenderer;
48 $this->tempUserDetailsLookup = $tempUserDetailsLookup;
69 ?
string $altUserName =
null,
70 array $attributes = []
72 $outputPage = $context->getOutput();
73 $outputPage->addModuleStyles( [
'mediawiki.interface.helpers.styles' ] );
74 $outputPage->addModules( [
'mediawiki.interface.helpers' ] );
78 if ( $this->tempUserDetailsLookup->isExpired( $targetUser ) ) {
79 return $this->renderUserLink( $targetUser, $context, $altUserName, $attributes );
82 return $this->userLinkCache->getWithSetCallback(
83 $this->userLinkCache->makeKey(
86 implode(
' ', $attributes )
88 fn () => $this->renderUserLink( $targetUser, $context, $altUserName, $attributes )
103 private function renderUserLink(
106 ?
string $altUserName =
null,
107 array $attributes = []
109 $userName = $targetUser->getName();
111 $classes = [
'mw-userlink' ];
115 if ( $this->tempUserConfig->isTempName( $userName ) ) {
116 $classes[] =
'mw-tempuserlink';
119 if ( $this->tempUserDetailsLookup->isExpired( $targetUser ) ) {
120 $classes[] =
'mw-tempuserlink-expired';
121 $tooltipId = sprintf(
122 'mw-tempuserlink-expired-tooltip-%08x',
123 ConvertibleTimestamp::hrtime()
131 'class' =>
'cdx-tooltip mw-tempuserlink-expired--tooltip',
133 $messageLocalizer->
msg(
'tempuser-expired-link-tooltip' )->text()
136 $attributes[
'aria-describedby'] = $tooltipId;
140 $attributes[
'title'] =
'';
143 $pageName = $this->specialPageFactory->getLocalNameFor(
'Contributions', $userName );
144 $page =
new TitleValue(
NS_SPECIAL, $pageName );
146 $page = ExternalUserNames::getUserLinkTitle( $userName );
148 if ( ExternalUserNames::isExternal( $userName ) ) {
149 $classes[] =
'mw-extuserlink';
150 } elseif ( $altUserName ===
null ) {
151 $altUserName = IPUtils::prettifyIP( $userName );
153 $classes[] =
'mw-anonuserlink';
155 $page = TitleValue::tryNew(
NS_USER, strtr( $userName,
' ',
'_' ) );
160 '<bdi>' . htmlspecialchars( $altUserName ?? $userName ) .
'</bdi>';
162 if ( isset( $attributes[
'class'] ) ) {
163 $classes[] = $attributes[
'class'];
166 $attributes[
'class'] = implode(
' ', $classes );
168 if ( $page !==
null ) {
169 return $this->linkRenderer->makeLink( $page,
new HtmlArmor( $linkText ), $attributes ) . $postfix;
172 return Html::rawElement(
'span', $attributes, $linkText ) . $postfix;
Marks HTML that shouldn't be escaped.
Store key-value entries in a size-limited in-memory LRU cache.
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.