Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
56.00% |
14 / 25 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
ContributeFactory | |
56.00% |
14 / 25 |
|
50.00% |
2 / 4 |
11.17 | |
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 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getAssociatedNavigationLinks | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Specials\Contribute; |
4 | |
5 | use MediaWiki\HookContainer\HookRunner; |
6 | use MediaWiki\SpecialPage\SpecialPage; |
7 | use MediaWiki\Specials\Contribute\Card\ContributeCard; |
8 | use MediaWiki\Specials\Contribute\Card\ContributeCardActionLink; |
9 | use MediaWiki\User\UserIdentity; |
10 | use MessageLocalizer; |
11 | use Skin; |
12 | |
13 | class ContributeFactory { |
14 | |
15 | private MessageLocalizer $localizer; |
16 | private HookRunner $hookRunner; |
17 | |
18 | /** |
19 | * @param MessageLocalizer $localizer |
20 | * @param HookRunner $hookRunner |
21 | */ |
22 | public function __construct( MessageLocalizer $localizer, HookRunner $hookRunner ) { |
23 | $this->localizer = $localizer; |
24 | $this->hookRunner = $hookRunner; |
25 | } |
26 | |
27 | /** |
28 | * @return array |
29 | */ |
30 | public function getCards(): array { |
31 | $cards = []; |
32 | |
33 | $this->hookRunner->onContributeCards( $cards ); |
34 | |
35 | $cards[] = ( new ContributeCard( |
36 | $this->localizer->msg( 'newpage' )->text(), |
37 | $this->localizer->msg( 'newpage-desc' )->text(), |
38 | 'article', |
39 | new ContributeCardActionLink( |
40 | SpecialPage::getTitleFor( 'Wantedpages' )->getLocalURL(), |
41 | $this->localizer->msg( 'view-missing-pages' )->text() |
42 | ) |
43 | ) )->toArray(); |
44 | |
45 | return $cards; |
46 | } |
47 | |
48 | /** |
49 | * Check if the Special:Contribute page is enabled for the current skin |
50 | * @param Skin $skin |
51 | * @param array $specialContributeSkinsEnabled |
52 | * |
53 | * @return bool |
54 | */ |
55 | public static function isEnabledOnCurrentSkin( |
56 | Skin $skin, |
57 | array $specialContributeSkinsEnabled = [] |
58 | ): bool { |
59 | return $skin->supportsMenu( 'special-contribute' ) |
60 | || in_array( |
61 | $skin->getSkinName(), |
62 | $specialContributeSkinsEnabled |
63 | ); |
64 | } |
65 | |
66 | /** |
67 | * @param UserIdentity $viewingUser |
68 | * @param ?UserIdentity $targetUser |
69 | * |
70 | * @return array |
71 | */ |
72 | public static function getAssociatedNavigationLinks( |
73 | UserIdentity $viewingUser, |
74 | ?UserIdentity $targetUser |
75 | ): array { |
76 | if ( $targetUser === null || !$viewingUser->equals( $targetUser ) ) { |
77 | return []; |
78 | } |
79 | |
80 | return [ |
81 | SpecialPage::getTitleFor( 'Contribute' )->getFullText(), |
82 | SpecialPage::getTitleFor( 'Contributions', $targetUser->getName() )->getFullText(), |
83 | ]; |
84 | } |
85 | } |