Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
Resources | |
0.00% |
0 / 44 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderIconName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shouldHeaderIncludeIcon | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBody | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
6 | |||
formatLink | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
getMobileSummaryBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\MentorDashboard\Modules; |
4 | |
5 | use GrowthExperiments\Mentorship\Provider\MentorProvider; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Html\Html; |
8 | use MediaWiki\Linker\LinkRenderer; |
9 | use MediaWiki\SpecialPage\SpecialPage; |
10 | use MediaWiki\Title\MalformedTitleException; |
11 | use MediaWiki\Title\TitleParser; |
12 | |
13 | class Resources extends BaseModule { |
14 | /** @var TitleParser */ |
15 | private $titleParser; |
16 | |
17 | /** @var LinkRenderer */ |
18 | private $linkRenderer; |
19 | |
20 | /** @var MentorProvider */ |
21 | private $mentorProvider; |
22 | |
23 | /** |
24 | * @param string $name |
25 | * @param IContextSource $ctx |
26 | * @param TitleParser $titleParser |
27 | * @param LinkRenderer $linkRenderer |
28 | * @param MentorProvider $mentorProvider |
29 | */ |
30 | public function __construct( |
31 | $name, |
32 | IContextSource $ctx, |
33 | TitleParser $titleParser, |
34 | LinkRenderer $linkRenderer, |
35 | MentorProvider $mentorProvider |
36 | ) { |
37 | parent::__construct( $name, $ctx ); |
38 | |
39 | $this->titleParser = $titleParser; |
40 | $this->linkRenderer = $linkRenderer; |
41 | $this->mentorProvider = $mentorProvider; |
42 | } |
43 | |
44 | /** |
45 | * @inheritDoc |
46 | */ |
47 | protected function getHeaderText() { |
48 | return $this->msg( 'growthexperiments-mentor-dashboard-resources-headline' )->text(); |
49 | } |
50 | |
51 | /** |
52 | * @inheritDoc |
53 | */ |
54 | protected function getHeaderIconName() { |
55 | return 'references'; |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | protected function shouldHeaderIncludeIcon(): bool { |
62 | return true; |
63 | } |
64 | |
65 | /** |
66 | * @inheritDoc |
67 | */ |
68 | protected function getBody() { |
69 | $links = [ |
70 | // TODO: For now, links are hardcoded here. In the full version of the |
71 | // resources module, they should be customizable by the wiki (via interface |
72 | // messages). |
73 | $this->formatLink( |
74 | SpecialPage::getTitleFor( 'ManageMentors' )->getPrefixedText(), |
75 | $this->getUser()->isAllowed( 'managementors' ) ? |
76 | $this->msg( 'growthexperiments-mentor-dashboard-resources-link-manage-mentors' )->text() |
77 | : $this->msg( 'growthexperiments-mentor-dashboard-resources-link-view-mentor-list' )->text() |
78 | ), |
79 | $this->formatLink( |
80 | 'mw:Special:MyLanguage/Growth/Communities/How to configure the mentors\' list', |
81 | $this->msg( 'growthexperiments-mentor-dashboard-resources-link-how-to-introduce' )->text() |
82 | ), |
83 | $this->formatLink( |
84 | 'mw:Special:MyLanguage/Help:Growth/Tools/How to claim a mentee', |
85 | $this->msg( 'growthexperiments-mentor-dashboard-resources-link-claim-mentee' )->text() |
86 | ), |
87 | $this->formatLink( |
88 | 'mw:Special:MyLanguage/Growth', |
89 | $this->msg( 'growthexperiments-mentor-dashboard-resources-link-tools' )->text() |
90 | ) |
91 | ]; |
92 | |
93 | return Html::rawElement( |
94 | 'ul', |
95 | [], |
96 | implode( "\n", array_filter( $links ) ) |
97 | ); |
98 | } |
99 | |
100 | /** |
101 | * @param string $targetText Text target for the link (parsed by TitleParser) |
102 | * @param string $text Description for the link |
103 | * @return ?string Null on error |
104 | */ |
105 | private function formatLink( string $targetText, string $text ): ?string { |
106 | try { |
107 | $target = $this->titleParser->parseTitle( $targetText ); |
108 | } catch ( MalformedTitleException $e ) { |
109 | return null; |
110 | } |
111 | |
112 | return Html::rawElement( |
113 | 'li', |
114 | [], |
115 | $this->linkRenderer->makeLink( |
116 | $target, |
117 | $text |
118 | ) |
119 | ); |
120 | } |
121 | |
122 | /** |
123 | * @inheritDoc |
124 | */ |
125 | protected function getMobileSummaryBody() { |
126 | return ''; |
127 | } |
128 | } |