Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
58.33% |
14 / 24 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
ContributeFactory | |
58.33% |
14 / 24 |
|
50.00% |
2 / 4 |
8.60 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getCards | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
isEnabledOnCurrentSkin | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getAssociatedNavigationLinks | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
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 | |
21 | namespace MediaWiki\Specials\Contribute; |
22 | |
23 | use MediaWiki\HookContainer\HookRunner; |
24 | use MediaWiki\SpecialPage\SpecialPage; |
25 | use MediaWiki\Specials\Contribute\Card\ContributeCard; |
26 | use MediaWiki\Specials\Contribute\Card\ContributeCardActionLink; |
27 | use MediaWiki\User\UserIdentity; |
28 | use MessageLocalizer; |
29 | use Skin; |
30 | |
31 | class ContributeFactory { |
32 | |
33 | private MessageLocalizer $localizer; |
34 | private HookRunner $hookRunner; |
35 | |
36 | public function __construct( MessageLocalizer $localizer, HookRunner $hookRunner ) { |
37 | $this->localizer = $localizer; |
38 | $this->hookRunner = $hookRunner; |
39 | } |
40 | |
41 | public function getCards(): array { |
42 | $cards = []; |
43 | |
44 | $this->hookRunner->onContributeCards( $cards ); |
45 | |
46 | $cards[] = ( new ContributeCard( |
47 | $this->localizer->msg( 'newpage' )->text(), |
48 | $this->localizer->msg( 'newpage-desc' )->text(), |
49 | 'article', |
50 | new ContributeCardActionLink( |
51 | SpecialPage::getTitleFor( 'Wantedpages' )->getLocalURL(), |
52 | $this->localizer->msg( 'view-missing-pages' )->text() |
53 | ) |
54 | ) )->toArray(); |
55 | |
56 | return $cards; |
57 | } |
58 | |
59 | /** |
60 | * Check if the Special:Contribute page is enabled for the current skin |
61 | * This can be removed when T323083 is resolved ie. the Special:Contribute feature |
62 | * has been shipped by the WMF Language Team. |
63 | * |
64 | * @param Skin $skin |
65 | * @param array $specialContributeSkinsEnabled |
66 | * |
67 | * @return bool |
68 | */ |
69 | public static function isEnabledOnCurrentSkin( |
70 | Skin $skin, |
71 | array $specialContributeSkinsEnabled = [] |
72 | ): bool { |
73 | return in_array( |
74 | $skin->getSkinName(), |
75 | $specialContributeSkinsEnabled |
76 | ); |
77 | } |
78 | |
79 | /** |
80 | * @param UserIdentity $viewingUser |
81 | * @param ?UserIdentity $targetUser |
82 | * |
83 | * @return array |
84 | */ |
85 | public static function getAssociatedNavigationLinks( |
86 | UserIdentity $viewingUser, |
87 | ?UserIdentity $targetUser |
88 | ): array { |
89 | if ( $targetUser === null || !$viewingUser->equals( $targetUser ) ) { |
90 | return []; |
91 | } |
92 | |
93 | return [ |
94 | SpecialPage::getTitleFor( 'Contribute' )->getFullText(), |
95 | SpecialPage::getTitleFor( 'Contributions', $targetUser->getName() )->getFullText(), |
96 | ]; |
97 | } |
98 | } |