Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SkinComponentTempUserBanner | |
0.00% |
0 / 47 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
createLoginLink | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
createAccountLink | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
renderBannerHTML | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
getTemplateData | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Skin; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MediaWiki\User\User; |
7 | use MessageLocalizer; |
8 | |
9 | /** |
10 | * @internal for use inside Skin and SkinTemplate classes only |
11 | * |
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 |
18 | */ |
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; |
32 | |
33 | /** |
34 | * @param string|array $returnto |
35 | * @param MessageLocalizer $localizer |
36 | * @param User $user |
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(); // getUser |
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 | * @inheritDoc |
97 | */ |
98 | public function getTemplateData(): array { |
99 | return [ |
100 | 'html' => ( $this->isTempUser ) ? $this->renderBannerHTML() : '' |
101 | ]; |
102 | } |
103 | } |