Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SiteAdminHelperModule
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 getStyleFiles
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20namespace MediaWiki\Extension\WikimediaMessages;
21
22use MediaWiki\ResourceLoader\Context;
23use MediaWiki\ResourceLoader\FileModule;
24use MediaWiki\ResourceLoader\FilePath;
25
26/**
27 * This style module aids Wikimedia projects in helping them make their content
28 * friendly for mobile devices and friendly to night mode.
29 *
30 * While helpful for projects which do not have the capacity to update the many templates
31 * and site scripts and styles on their projects, we recognize that projects where there
32 * are lots of admins, may prefer to opt out of some of these styles.
33 *
34 * It can be configured using the configuration variable $wgWikimediaStylesFeatures
35 * by site admins
36 *
37 * It works similar to the ResourceLoader//SkinModule.
38 *
39 * @ingroup ResourceLoader
40 * @internal
41 */
42class SiteAdminHelperModule extends FileModule {
43
44    /**
45     * Every skin should define which features it would like to reuse for core inside a
46     * ResourceLoader module that has set the class to SkinModule.
47     * For a feature to be valid it must be listed here along with the associated resources
48     *
49     * The following features are available.
50     * Admins can opt out by using MediaWiki:wikimedia-styles-exclude.
51     */
52    private const FEATURE_FILES = [
53        'ambox' => [ 'ambox.less' ],
54        'infobox' => [ 'infobox.less' ],
55        'hatnote' => [ 'hatnote.less' ],
56        'navbox' => [ 'navbox.less' ],
57        'theme-night' => [ 'theme-night.less' ],
58        'theme-night-mainpage' => [ 'theme-night-mainpage.less' ],
59    ];
60
61    /**
62     * Get styles defined in the module definition, plus any enabled feature styles.
63     *
64     * @param Context $context
65     * @return string[][]
66     */
67    public function getStyleFiles( Context $context ) {
68        $config = $this->getConfig();
69        $excludeFeatures = explode( '|', $context->msg( 'wikimedia-styles-exclude' ) );
70
71        $featureFilePaths = [];
72
73        foreach ( self::FEATURE_FILES as $feature => $featureFiles ) {
74            if ( !in_array( $feature, $excludeFeatures ) ) {
75                foreach ( $featureFiles as $filepath ) {
76                    $featureFilePaths['all'][] = new FilePath( $filepath );
77                }
78            }
79        }
80
81        return $featureFilePaths;
82    }
83}