Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
35 / 42
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialContribute
85.37% covered (warning)
85.37%
35 / 41
66.67% covered (warning)
66.67%
4 / 6
7.15
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getContributePage
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
1
 getShortDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAssociatedNavigationLinks
28.57% covered (danger)
28.57%
2 / 7
0.00% covered (danger)
0.00%
0 / 1
3.46
 isShowable
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Specials;
4
5use MediaWiki\Config\ServiceOptions;
6use MediaWiki\Html\TemplateParser;
7use MediaWiki\MainConfigNames;
8use MediaWiki\SpecialPage\IncludableSpecialPage;
9use MediaWiki\Specials\Contribute\ContributeFactory;
10
11/**
12 * Promote ways for editors to contribute.
13 *
14 * The cards are produced by MediaWiki\Specials\Contribute\ContributeFactory,
15 * which defaults to a single card promoting Special:Wantedpages, and is
16 * extended by extensions to add additional cards.
17 *
18 * To enable a link to this special page in the skin, which will replace the
19 * link to "Contributions" in the p-personal portlet menu, add the skin name
20 * to $wgSpecialContributeSkinsEnabled.
21 *
22 * @ingroup SpecialPage
23 */
24class SpecialContribute extends IncludableSpecialPage {
25
26    public function __construct() {
27        parent::__construct( 'Contribute' );
28    }
29
30    /**
31     * @inheritDoc
32     */
33    public function execute( $par ) {
34        $this->setHeaders();
35        $this->outputHeader();
36
37        $out = $this->getOutput();
38        $out->setPageTitleMsg( $this->msg( 'contribute-title', $this->getUser()->getName() ) );
39        $out->addModuleStyles( [
40            'mediawiki.special'
41        ] );
42        $out->addHTML( $this->getContributePage() );
43    }
44
45    /**
46     * Get the contribute page HTML, check ContributeFactory it is used to
47     * get the contribute cards and render them using the mustache template.
48     *
49     * @return string
50     */
51    private function getContributePage() {
52        $contributeFactory = new ContributeFactory(
53            $this->getContext(),
54            $this->getHookRunner(),
55            new ServiceOptions(
56                ContributeFactory::CONSTRUCTOR_OPTIONS,
57                $this->getConfig()
58            )
59        );
60        $cards = $contributeFactory->getCards();
61
62        $templateParser = new TemplateParser(
63            dirname( __DIR__, 2 ) . '/resources/templates/SpecialContribute'
64        );
65        $templateData = [
66            'cards' => $cards,
67        ];
68        $outputHTML = $templateParser->processTemplate(
69            'SpecialContribute',
70            $templateData
71        );
72
73        return $outputHTML;
74    }
75
76    /**
77     * @inheritDoc
78     */
79    public function getShortDescription( string $path = '' ): string {
80        return $this->msg( 'special-tab-contribute-short' )->text();
81    }
82
83    /**
84     * @inheritDoc
85     */
86    public function getAssociatedNavigationLinks(): array {
87        if ( $this->isShowable() ) {
88            $user = $this->getUser();
89            return ContributeFactory::getAssociatedNavigationLinks(
90                $user,
91                $user
92            );
93        }
94        return [];
95    }
96
97    /**
98     * Check if skin is allowed to access the Special:Contribute page
99     * and the page have enough cards to be enabled
100     */
101    public function isShowable(): bool {
102        return ContributeFactory::isEnabledOnCurrentSkin(
103            $this->getSkin(),
104            $this->getConfig()->get( MainConfigNames::SpecialContributeSkinsEnabled )
105        );
106    }
107}
108
109/** @deprecated class alias since 1.41 */
110class_alias( SpecialContribute::class, 'SpecialContribute' );