Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
Banner
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 10
132
0.00% covered (danger)
0.00%
0 / 1
 isEnabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 canRender
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHeaderText
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHeaderIconName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHeader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMobileSummaryHeader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getBody
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getMobileSummaryBody
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getState
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace GrowthExperiments\HomepageModules;
4
5use GrowthExperiments\ExperimentUserManager;
6use MediaWiki\Config\Config;
7use MediaWiki\Context\IContextSource;
8use MediaWiki\Html\Html;
9
10/**
11 * A module for displaying some text that can be specified on-wiki. This can be used as a low-key
12 * sitenotice aimed at new users.
13 *
14 * The Banner message is generated from the contents of the MediaWiki:Growth-homepage-banner wiki
15 * page, if it exists. If the page does not exist or the page content is empty, the banner module
16 * is not shown.
17 */
18class Banner extends BaseModule {
19
20    public const MESSAGE_KEY = 'growth-homepage-banner';
21
22    /** @inheritDoc */
23    protected static $supportedModes = [
24        self::RENDER_DESKTOP,
25        self::RENDER_MOBILE_SUMMARY
26        // RENDER_MOBILE_DETAILS is not supported
27    ];
28
29    /**
30     * Check whether the module is enabled (ie. if there's a banner message set by the wiki admin).
31     * @param IContextSource $context
32     * @return bool
33     */
34    public static function isEnabled( IContextSource $context ) {
35        return !$context->msg( self::MESSAGE_KEY )->isDisabled();
36    }
37
38    /** @inheritDoc */
39    public function __construct(
40        IContextSource $context,
41        Config $wikiConfig,
42        ExperimentUserManager $experimentUserManager
43    ) {
44        parent::__construct( 'banner', $context, $wikiConfig, $experimentUserManager );
45    }
46
47    /** @inheritDoc */
48    protected function canRender() {
49        return self::isEnabled( $this->getContext() );
50    }
51
52    /** @inheritDoc */
53    protected function getHeaderText() {
54        return '';
55    }
56
57    /** @inheritDoc */
58    protected function getHeaderIconName() {
59        return '';
60    }
61
62    /** @inheritDoc */
63    protected function getHeader() {
64        return '';
65    }
66
67    /** @inheritDoc */
68    protected function getMobileSummaryHeader() {
69        return '';
70    }
71
72    /** @inheritDoc */
73    protected function getBody() {
74        return Html::rawElement(
75            'div',
76            [
77                'class' => 'mw-parser-output',
78                'data-link-group-id' => 'banner',
79            ],
80            $this->getContext()->msg( self::MESSAGE_KEY )->parse()
81        );
82    }
83
84    /** @inheritDoc */
85    protected function getMobileSummaryBody() {
86        return Html::rawElement(
87            'div',
88            [ 'class' => 'mw-parser-output' ],
89            $this->getContext()->msg( self::MESSAGE_KEY )->parse()
90        );
91    }
92
93    /** @inheritDoc */
94    public function getState() {
95        return $this->canRender() ? self::MODULE_STATE_ACTIVATED : self::MODULE_STATE_UNACTIVATED;
96    }
97
98}