Debian Codegraph @

includes/specials/SpecialContribute.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Specials;
4
5 use MediaWiki\Html\TemplateParser;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\SpecialPage\IncludableSpecialPage;
8 use 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 */
23 class 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 */
106 class_alias( SpecialContribute::class, 'SpecialContribute' );