Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
58.33% covered (warning)
58.33%
14 / 24
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ContributeFactory
58.33% covered (warning)
58.33%
14 / 24
50.00% covered (danger)
50.00%
2 / 4
8.60
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCards
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 isEnabledOnCurrentSkin
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getAssociatedNavigationLinks
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Specials\Contribute;
4
5use MediaWiki\HookContainer\HookRunner;
6use MediaWiki\SpecialPage\SpecialPage;
7use MediaWiki\Specials\Contribute\Card\ContributeCard;
8use MediaWiki\Specials\Contribute\Card\ContributeCardActionLink;
9use MediaWiki\User\UserIdentity;
10use MessageLocalizer;
11use Skin;
12
13class 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     * This can be removed when T323083 is resolved ie. the Special:Contribute feature
51     * has been shipped by the WMF Language Team.
52     *
53     * @param Skin $skin
54     * @param array $specialContributeSkinsEnabled
55     *
56     * @return bool
57     */
58    public static function isEnabledOnCurrentSkin(
59        Skin $skin,
60        array $specialContributeSkinsEnabled = []
61    ): bool {
62        return in_array(
63                $skin->getSkinName(),
64                $specialContributeSkinsEnabled
65            );
66    }
67
68    /**
69     * @param UserIdentity $viewingUser
70     * @param ?UserIdentity $targetUser
71     *
72     * @return array
73     */
74    public static function getAssociatedNavigationLinks(
75        UserIdentity $viewingUser,
76        ?UserIdentity $targetUser
77    ): array {
78        if ( $targetUser === null || !$viewingUser->equals( $targetUser ) ) {
79            return [];
80        }
81
82        return [
83            SpecialPage::getTitleFor( 'Contribute' )->getFullText(),
84            SpecialPage::getTitleFor( 'Contributions', $targetUser->getName() )->getFullText(),
85        ];
86    }
87}