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    /** @inheritDoc */
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::AllowUserJs ) ) {
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.js"] = [ 'type' => 'script' ];
58            $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
59        }
60
61        // User group pages are maintained site-wide and enabled with site JS/CSS.
62        if ( $config->get( MainConfigNames::UseSiteJs ) ) {
63            $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
64            foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
65                if ( $group == '*' ) {
66                    continue;
67                }
68                $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
69            }
70        }
71
72        return $pages;
73    }
74
75    /**
76     * Get group name
77     *
78     * @return string
79     */
80    public function getGroup() {
81        return self::GROUP_USER;
82    }
83}