MediaWiki master
UserModule.php
Go to the documentation of this file.
1<?php
24
28
35class UserModule extends WikiModule {
37 protected $origin = self::ORIGIN_USER_INDIVIDUAL;
38
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
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.
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
80 public function getGroup() {
81 return self::GROUP_USER;
82 }
83}
const NS_USER
Definition Defines.php:67
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:282
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.".