Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
AdvancedUserMenuBuilder | |
0.00% |
0 / 33 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getGroup | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | namespace MediaWiki\Minerva\Menu\User; |
21 | |
22 | use MediaWiki\Minerva\Menu\Definitions; |
23 | use MediaWiki\Minerva\Menu\Entries\ProfileMenuEntry; |
24 | use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry; |
25 | use MediaWiki\Minerva\Menu\Group; |
26 | use MediaWiki\User\User; |
27 | use MessageLocalizer; |
28 | |
29 | /** |
30 | * Logged-in, advanced Mobile Contributions user menu config generator. |
31 | */ |
32 | final class AdvancedUserMenuBuilder implements IUserMenuBuilder { |
33 | private MessageLocalizer $messageLocalizer; |
34 | private User $user; |
35 | private Definitions $definitions; |
36 | |
37 | /** |
38 | * @param MessageLocalizer $messageLocalizer |
39 | * @param User $user |
40 | * @param Definitions $definitions A menu items definitions set |
41 | */ |
42 | public function __construct( |
43 | MessageLocalizer $messageLocalizer, User $user, Definitions $definitions |
44 | ) { |
45 | $this->messageLocalizer = $messageLocalizer; |
46 | $this->user = $user; |
47 | $this->definitions = $definitions; |
48 | } |
49 | |
50 | /** |
51 | * @inheritDoc |
52 | * @param array $personalTools list of personal tools generated by |
53 | * SkinTemplate::getPersonalTools |
54 | * @return Group |
55 | */ |
56 | public function getGroup( array $personalTools ): Group { |
57 | $group = new Group( 'p-personal' ); |
58 | $trackingKeyOverrides = [ |
59 | 'mytalk' => 'userTalk', |
60 | 'watchlist' => 'unStar', |
61 | 'mycontris' => 'contributions', |
62 | ]; |
63 | |
64 | foreach ( $personalTools as $key => $item ) { |
65 | if ( in_array( $key, [ 'preferences', 'betafeatures', 'uploads' ] ) ) { |
66 | continue; |
67 | } |
68 | // Special casing for userpage to support Extension:GrowthExperiments. |
69 | // This can be removed when T291568 is resolved. |
70 | if ( $key === 'userpage' ) { |
71 | $entry = new ProfileMenuEntry( $this->user ); |
72 | $entry->overrideProfileURL( |
73 | $item['href'], |
74 | $item['text'] |
75 | ); |
76 | $group->insertEntry( $entry ); |
77 | continue; |
78 | } |
79 | $icon = $item['icon'] ?? null; |
80 | if ( $icon ) { |
81 | $entry = SingleMenuEntry::create( |
82 | $key, |
83 | $item['text'], |
84 | $item['href'], |
85 | $item['class'] ?? '', |
86 | $icon |
87 | ); |
88 | // override tracking key where key mismatch |
89 | if ( array_key_exists( $key, $trackingKeyOverrides ) ) { |
90 | $entry->trackClicks( $trackingKeyOverrides[ $key ] ); |
91 | } |
92 | $group->insertEntry( $entry ); |
93 | } |
94 | } |
95 | return $group; |
96 | } |
97 | } |