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