Merge "Special:BlockList: Update remove/change block links"
[mediawiki.git] / includes / skins / components / SkinComponentTempUserBanner.php
blobd8404801a7b85c376fcbaf56d23bd093137a77fd
1 <?php
3 namespace MediaWiki\Skin;
5 use MediaWiki\Html\Html;
6 use MediaWiki\User\User;
7 use MessageLocalizer;
9 /**
10 * @internal for use inside Skin and SkinTemplate classes only
12 * NOTE: This class is currently *not registered* via the SkinComponentRegistry
13 * and cannot be called via Skin::getComponent.
14 * Because of it's unsuitability for rendering via mustache templates
15 * (it renders its own HTML and returns no data),
16 * it is appended directly to skin data in Skin::getTemplateData.
17 * @unstable
19 class SkinComponentTempUserBanner implements SkinComponent {
20 /** @var string */
21 private $loginUrl;
22 /** @var string */
23 private $createAccountUrl;
24 /** @var MessageLocalizer */
25 private $localizer;
26 /** @var bool */
27 private $isTempUser;
28 /** @var string */
29 private $username;
30 /** @var string */
31 private $userpageUrl;
33 /**
34 * @param string|array $returnto
35 * @param MessageLocalizer $localizer
36 * @param User $user
38 public function __construct( $returnto, $localizer, $user ) {
39 $this->loginUrl = SkinComponentUtils::makeSpecialUrl( 'Userlogin', $returnto );
40 $this->createAccountUrl = SkinComponentUtils::makeSpecialUrl( 'CreateAccount', $returnto );
41 $this->localizer = $localizer;
42 $this->isTempUser = $user->isTemp();
43 $this->username = $user->getName(); // getUser
44 $this->userpageUrl = $user->getUserPage()->getFullURL();
47 private function createLoginLink() {
48 return Html::element( 'a',
50 'href' => $this->loginUrl,
51 'id' => 'pt-login',
52 'title' => $this->localizer->msg( 'tooltip-pt-login' )->text(),
53 'class' => 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled'
55 $this->localizer->msg( 'pt-login' )->text() );
58 private function createAccountLink() {
59 return Html::element( 'a',
61 'href' => $this->createAccountUrl,
62 'id' => 'pt-createaccount',
63 'title' => $this->localizer->msg( 'tooltip-pt-createaccount' )->text(),
64 'class' => 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled'
66 $this->localizer->msg( 'pt-createaccount' )->text()
70 private function renderBannerHTML() {
71 return Html::rawElement( 'div', [ 'class' => 'mw-temp-user-banner' ],
72 Html::rawElement( 'p', [],
73 $this->localizer->msg( 'temp-user-banner-description' )->escaped() .
74 $this->localizer->msg( 'colon-separator' )->escaped() .
75 Html::element( 'span', [ 'class' => 'mw-temp-user-banner-username' ], $this->username )
76 ) .
77 HTML::rawElement( 'div', [ 'class' => 'mw-temp-user-banner-tooltip' ],
78 HTML::rawElement( 'button', [
79 'id' => 'mw-temp-user-banner-tooltip-button',
80 'class' => 'mw-temp-user-banner-tooltip-summary cdx-button '
81 . 'cdx-button--icon-only cdx-button--weight-quiet',
82 'aria-label' => $this->localizer->msg( 'temp-user-banner-tooltip-label' )
84 HTML::element( 'span', [ 'class' => 'mw-temp-user-banner-tooltip-icon ' ] )
87 ) .
88 HTML::rawElement( 'div', [ 'class' => 'mw-temp-user-banner-buttons' ],
89 $this->createLoginLink() .
90 $this->createAccountLink()
95 /**
96 * @inheritDoc
98 public function getTemplateData(): array {
99 return [
100 'html' => ( $this->isTempUser ) ? $this->renderBannerHTML() : ''