MediaWiki  master
ResourceLoaderUserModule.php
Go to the documentation of this file.
1 <?php
25 
33  protected $origin = self::ORIGIN_USER_INDIVIDUAL;
34  protected $targets = [ 'desktop', 'mobile' ];
35 
40  protected function getPages( ResourceLoaderContext $context ) {
41  $user = $context->getUserIdentity();
42  if ( !$user || !$user->isRegistered() ) {
43  return [];
44  }
45 
46  $config = $this->getConfig();
47  $pages = [];
48 
49  if ( $config->get( MainConfigNames::AllowUserJs ) ) {
50  $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
51  // Use localised/normalised variant to ensure $excludepage matches
52  $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
53  $pages["$userPage/common.js"] = [ 'type' => 'script' ];
54  $pages["$userPage/" . $context->getSkin() . '.js'] = [ 'type' => 'script' ];
55  }
56 
57  // User group pages are maintained site-wide and enabled with site JS/CSS.
58  if ( $config->get( MainConfigNames::UseSiteJs ) ) {
59  $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager();
60  foreach ( $userGroupManager->getUserEffectiveGroups( $user ) as $group ) {
61  if ( $group == '*' ) {
62  continue;
63  }
64  $pages["MediaWiki:Group-$group.js"] = [ 'type' => 'script' ];
65  }
66  }
67 
68  // This is obsolete since 1.32 (T112474). It was formerly used by
69  // OutputPage to implement previewing of user CSS and JS.
70  // @todo: Remove it once we're sure nothing else is using the parameter
71  $excludepage = $context->getRequest()->getVal( 'excludepage' );
72  unset( $pages[$excludepage] );
73 
74  return $pages;
75  }
76 
82  public function getGroup() {
83  return self::GROUP_USER;
84  }
85 }
const NS_USER
Definition: Defines.php:66
A class containing constants representing the names of configuration variables.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Context object that contains information about the state of a specific ResourceLoader web request.
getUserIdentity()
Get the possibly-cached UserIdentity object for the specified username.
Module for user customizations scripts.
getPages(ResourceLoaderContext $context)
Abstraction for ResourceLoader modules which pull from wiki pages.
string null $group
Group of module.
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".