MediaWiki master
UserModule.php
Go to the documentation of this file.
1<?php
24
28
35class UserModule extends WikiModule {
36 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
37
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
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}
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:45
getUserIdentity()
Get the possibly-cached UserIdentity object for the specified username.
Definition Context.php:278
Module for user customizations scripts.
Abstraction for ResourceLoader modules which pull from wiki pages.
string null $group
Group of module.
Represents the target of a wiki link.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".