MediaWiki REL1_39
UserModule.php
Go to the documentation of this file.
1<?php
24
27use TitleValue;
28
35class UserModule extends WikiModule {
36 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
37 protected $targets = [ 'desktop', 'mobile' ];
38
43 protected function getPages( Context $context ) {
44 $user = $context->getUserIdentity();
45 if ( !$user || !$user->isRegistered() ) {
46 return [];
47 }
48
49 $config = $this->getConfig();
50 $pages = [];
51
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.
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
79 public function getGroup() {
80 return self::GROUP_USER;
81 }
82}
83
85class_alias( UserModule::class, 'ResourceLoaderUserModule' );
const NS_USER
Definition Defines.php:66
A class containing constants representing the names of configuration variables.
const UseSiteJs
Name constant for the UseSiteJs setting, for use with Config::get()
const AllowUserJs
Name constant for the AllowUserJs setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition Context.php:46
getUserIdentity()
Get the possibly-cached UserIdentity object for the specified username.
Definition Context.php:286
Module for user customizations scripts.
Abstraction for ResourceLoader modules which pull from wiki pages.
string null $group
Group of module.
Represents a page (or page fragment) title within MediaWiki.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".