Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserModule
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 2
90
0.00% covered (danger)
0.00%
0 / 1
 getPages
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
72
 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 scripts.
31 *
32 * @ingroup ResourceLoader
33 * @internal
34 */
35class UserModule extends WikiModule {
36    protected $origin = self::ORIGIN_USER_INDIVIDUAL;
37
38    /**
39     * @param Context $context
40     * @return array[]
41     */
42    protected function getPages( Context $context ) {
43        $user = $context->getUserIdentity();
44        $tempUserConfig = MediaWikiServices::getInstance()->getTempUserConfig();
45        if ( !$user || !$user->isRegistered() || $tempUserConfig->isTempName( $user->getName() ) ) {
46            return [];
47        }
48
49        $config = $this->getConfig();
50        $pages = [];
51
52        if ( $config->get( MainConfigNames::AllowUserJs ) ) {
53            $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
54            // Use localised/normalised variant to ensure $excludepage matches
55            $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
56            $pages["$userPage/common.js"] = [ 'type' => 'script' ];
57            $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
58        }
59
60        // User group pages are maintained site-wide and enabled with site JS/CSS.
61        if ( $config->get( MainConfigNames::UseSiteJs ) ) {
62            $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
63            foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
64                if ( $group == '*' ) {
65                    continue;
66                }
67                $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
68            }
69        }
70
71        return $pages;
72    }
73
74    /**
75     * Get group name
76     *
77     * @return string
78     */
79    public function getGroup() {
80        return self::GROUP_USER;
81    }
82}