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 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserStylesModule
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 getPages
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
72
 getType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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 * @author Trevor Parscal
20 * @author Roan Kattouw
21 */
22
23namespace MediaWiki\ResourceLoader;
24
25use MediaWiki\MainConfigNames;
26use MediaWiki\MediaWikiServices;
27use MediaWiki\Title\TitleValue;
28
29/**
30 * Module for user customizations styles.
31 *
32 * @ingroup ResourceLoader
33 * @internal
34 */
35class UserStylesModule extends WikiModule {
36
37    protected $origin = self::ORIGIN_USER_INDIVIDUAL;
38
39    /**
40     * @param Context $context
41     * @return array[]
42     */
43    protected function getPages( Context $context ) {
44        $user = $context->getUserIdentity();
45        $tempUserConfig = MediaWikiServices::getInstance()->getTempUserConfig();
46        if ( !$user || !$user->isRegistered() || $tempUserConfig->isTempName( $user->getName() ) ) {
47            return [];
48        }
49
50        $config = $this->getConfig();
51        $pages = [];
52
53        if ( $config->get( MainConfigNames::AllowUserCss ) ) {
54            $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
55            // Use localised/normalised variant to ensure $excludepage matches
56            $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
57            $pages["$userPage/common.css"] = [ 'type' => 'style' ];
58            $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
59        }
60
61        // User group pages are maintained site-wide and enabled with site JS/CSS.
62        if ( $config->get( MainConfigNames::UseSiteCss ) ) {
63            $effectiveGroups = MediaWikiServices::getInstance()->getUserGroupManager()
64                ->getUserEffectiveGroups( $user );
65            foreach ( $effectiveGroups as $group ) {
66                if ( $group == '*' ) {
67                    continue;
68                }
69                $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
70            }
71        }
72
73        return $pages;
74    }
75
76    /**
77     * @return string
78     */
79    public function getType() {
80        return self::LOAD_STYLES;
81    }
82
83    /**
84     * Get group name
85     *
86     * @return string
87     */
88    public function getGroup() {
89        return self::GROUP_USER;
90    }
91}