MediaWiki  master
UserModule.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\ResourceLoader;
24 
28 
35 class UserModule extends WikiModule {
36  protected $origin = self::ORIGIN_USER_INDIVIDUAL;
37 
42  protected function getPages( Context $context ) {
43  $user = $context->getUserIdentity();
44  if ( !$user || !$user->isRegistered() ) {
45  return [];
46  }
47 
48  $config = $this->getConfig();
49  $pages = [];
50 
52  $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
53  // Use localised/normalised variant to ensure $excludepage matches
54  $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
55  $pages["$userPage/common.js"] = [ 'type' => 'script' ];
56  $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
57  }
58 
59  // User group pages are maintained site-wide and enabled with site JS/CSS.
61  $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
62  foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
63  if ( $group == '*' ) {
64  continue;
65  }
66  $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
67  }
68  }
69 
70  return $pages;
71  }
72 
78  public function getGroup() {
79  return self::GROUP_USER;
80  }
81 }
82 
84 class_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:45
getUserIdentity()
Get the possibly-cached UserIdentity object for the specified username.
Definition: Context.php:278
Module for user customizations scripts.
Definition: UserModule.php:35
Abstraction for ResourceLoader modules which pull from wiki pages.
Definition: WikiModule.php:65
string null $group
Group of module.
Definition: WikiModule.php:97
Represents the target of a wiki link.
Definition: TitleValue.php:44
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".