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