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.
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.
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
19 * @author Trevor Parscal
20 * @author Roan Kattouw
24 * Module for user customizations scripts
26 class ResourceLoaderUserModule
extends ResourceLoaderWikiModule
{
28 protected $origin = self
::ORIGIN_USER_INDIVIDUAL
;
29 protected $targets = [ 'desktop', 'mobile' ];
32 * @param ResourceLoaderContext $context
33 * @return array List of pages
35 protected function getPages( ResourceLoaderContext
$context ) {
36 $config = $this->getConfig();
37 $user = $context->getUserObj();
38 if ( $user->isAnon() ) {
42 // Use localised/normalised variant to ensure $excludepage matches
43 $userPage = $user->getUserPage()->getPrefixedDBkey();
46 if ( $config->get( 'AllowUserJs' ) ) {
47 $pages["$userPage/common.js"] = [ 'type' => 'script' ];
48 $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
51 // User group pages are maintained site-wide and enabled with site JS/CSS.
52 if ( $config->get( 'UseSiteJs' ) ) {
53 foreach ( $user->getEffectiveGroups() as $group ) {
54 if ( $group == '*' ) {
57 $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
61 // Hack for T28283: Allow excluding pages for preview on a CSS/JS page.
62 // The excludepage parameter is set by OutputPage.
63 $excludepage = $context->getRequest()->getVal( 'excludepage' );
64 if ( isset( $pages[$excludepage] ) ) {
65 unset( $pages[$excludepage] );
76 public function getGroup() {
83 public function getDependencies( ResourceLoaderContext
$context = null ) {
84 return [ 'user.styles' ];