Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
MentorshipOptIn | |
0.00% |
0 / 37 |
|
0.00% |
0 / 10 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
canRender | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderText | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderIconName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getModules | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getBody | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getMobileSummaryBody | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getIntroductionElement | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
shouldWrapModuleWithLink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOptInButton | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\HomepageModules; |
4 | |
5 | use GrowthExperiments\ExperimentUserManager; |
6 | use GrowthExperiments\Mentorship\MentorManager; |
7 | use MediaWiki\Config\Config; |
8 | use MediaWiki\Context\IContextSource; |
9 | use MediaWiki\Html\Html; |
10 | use OOUI\ButtonWidget; |
11 | |
12 | class MentorshipOptIn extends BaseModule { |
13 | |
14 | /** @var MentorManager */ |
15 | private $mentorManager; |
16 | |
17 | /** |
18 | * @param IContextSource $context |
19 | * @param Config $wikiConfig |
20 | * @param ExperimentUserManager $experimentUserManager |
21 | * @param MentorManager $mentorManager |
22 | */ |
23 | public function __construct( |
24 | IContextSource $context, |
25 | Config $wikiConfig, |
26 | ExperimentUserManager $experimentUserManager, |
27 | MentorManager $mentorManager |
28 | ) { |
29 | parent::__construct( 'mentorship-optin', $context, $wikiConfig, $experimentUserManager ); |
30 | |
31 | $this->mentorManager = $mentorManager; |
32 | } |
33 | |
34 | /** |
35 | * @inheritDoc |
36 | */ |
37 | protected function canRender() { |
38 | return $this->mentorManager->getMentorshipStateForUser( |
39 | $this->getUser() |
40 | ) === MentorManager::MENTORSHIP_OPTED_OUT; |
41 | } |
42 | |
43 | /** |
44 | * @inheritDoc |
45 | */ |
46 | protected function getHeaderText() { |
47 | return $this->msg( 'growthexperiments-homepage-mentorship-optin-header' ) |
48 | ->text(); |
49 | } |
50 | |
51 | /** |
52 | * @inheritDoc |
53 | */ |
54 | protected function getHeaderIconName() { |
55 | return 'userTalk'; |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | protected function getModules() { |
62 | return $this->getMode() !== self::RENDER_MOBILE_SUMMARY ? |
63 | [ |
64 | 'ext.growthExperiments.Homepage.Mentorship', |
65 | ] : []; |
66 | } |
67 | |
68 | /** |
69 | * @inheritDoc |
70 | */ |
71 | protected function getBody() { |
72 | return implode( "\n", [ |
73 | $this->getIntroductionElement(), |
74 | $this->getOptInButton() |
75 | ] ); |
76 | } |
77 | |
78 | /** |
79 | * @inheritDoc |
80 | */ |
81 | protected function getMobileSummaryBody() { |
82 | return Html::element( |
83 | 'div', |
84 | [ 'class' => 'growthexperiments-homepage-module-text-light' ], |
85 | $this->msg( 'growthexperiments-homepage-mentorship-optin-text' )->text() |
86 | ) . $this->getOptInButton(); |
87 | } |
88 | |
89 | /** |
90 | * @return string |
91 | */ |
92 | private function getIntroductionElement(): string { |
93 | return Html::element( |
94 | 'p', |
95 | [], |
96 | $this->msg( 'growthexperiments-homepage-mentorship-optin-text' ) |
97 | ->text() |
98 | ); |
99 | } |
100 | |
101 | /** @inheritDoc */ |
102 | public function shouldWrapModuleWithLink(): bool { |
103 | return false; |
104 | } |
105 | |
106 | /** |
107 | * @return string |
108 | */ |
109 | private function getOptInButton(): string { |
110 | return new ButtonWidget( [ |
111 | 'id' => 'mw-ge-homepage-mentorship-optin', |
112 | 'framed' => false, |
113 | 'flags' => [ 'progressive' ], |
114 | 'icon' => 'mentor', |
115 | 'label' => $this->msg( 'growthexperiments-homepage-mentorship-optin-button' ) |
116 | ->text(), |
117 | 'infusable' => true, |
118 | ] ); |
119 | } |
120 | } |