| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Skin; |
| 4 |
|
| 5 |
use MediaWiki\Html\Html; |
| 6 |
use MediaWiki\User\User; |
| 7 |
use MessageLocalizer; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class SkinComponentTempUserBanner implements SkinComponent { |
| 20 |
|
| 21 |
private $loginUrl; |
| 22 |
|
| 23 |
private $createAccountUrl; |
| 24 |
|
| 25 |
private $localizer; |
| 26 |
|
| 27 |
private $isTempUser; |
| 28 |
|
| 29 |
private $username; |
| 30 |
|
| 31 |
private $userpageUrl; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 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(); |
| 44 |
$this->userpageUrl = $user->getUserPage()->getFullURL(); |
| 45 |
} |
| 46 |
|
| 47 |
private function createLoginLink() { |
| 48 |
return Html::element( 'a', |
| 49 |
[ |
| 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' |
| 54 |
], |
| 55 |
$this->localizer->msg( 'pt-login' )->text() ); |
| 56 |
} |
| 57 |
|
| 58 |
private function createAccountLink() { |
| 59 |
return Html::element( 'a', |
| 60 |
[ |
| 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' |
| 65 |
], |
| 66 |
$this->localizer->msg( 'pt-createaccount' )->text() |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 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' ) |
| 83 |
], |
| 84 |
HTML::element( 'span', [ 'class' => 'mw-temp-user-banner-tooltip-icon ' ] ) |
| 85 |
) |
| 86 |
|
| 87 |
) . |
| 88 |
HTML::rawElement( 'div', [ 'class' => 'mw-temp-user-banner-buttons' ], |
| 89 |
$this->createLoginLink() . |
| 90 |
$this->createAccountLink() |
| 91 |
) |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function getTemplateData(): array { |
| 99 |
return [ |
| 100 |
'html' => ( $this->isTempUser ) ? $this->renderBannerHTML() : '' |
| 101 |
]; |
| 102 |
} |
| 103 |
} |