3 namespace MediaWiki\Skin
;
5 use MediaWiki\Html\Html
;
6 use MediaWiki\User\User
;
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.
19 class SkinComponentTempUserBanner
implements SkinComponent
{
23 private $createAccountUrl;
24 /** @var MessageLocalizer */
34 * @param string|array $returnto
35 * @param MessageLocalizer $localizer
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
,
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
)
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 ' ] )
88 HTML
::rawElement( 'div', [ 'class' => 'mw-temp-user-banner-buttons' ],
89 $this->createLoginLink() .
90 $this->createAccountLink()
98 public function getTemplateData(): array {
100 'html' => ( $this->isTempUser
) ?
$this->renderBannerHTML() : ''