MediaWiki  master
ResourceLoaderUserStylesModule.php
Go to the documentation of this file.
1 <?php
25 
33 
34  protected $origin = self::ORIGIN_USER_INDIVIDUAL;
35  protected $targets = [ 'desktop', 'mobile' ];
36 
41  protected function getPages( ResourceLoaderContext $context ) {
42  $user = $context->getUserIdentity();
43  if ( !$user || !$user->isRegistered() ) {
44  return [];
45  }
46 
47  $config = $this->getConfig();
48  $pages = [];
49 
50  if ( $config->get( MainConfigNames::AllowUserCss ) ) {
51  $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
52  // Use localised/normalised variant to ensure $excludepage matches
53  $userPage = $titleFormatter->getPrefixedDBkey( new TitleValue( NS_USER, $user->getName() ) );
54  $pages["$userPage/common.css"] = [ 'type' => 'style' ];
55  $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
56  }
57 
58  // User group pages are maintained site-wide and enabled with site JS/CSS.
59  if ( $config->get( MainConfigNames::UseSiteCss ) ) {
60  $effectiveGroups = MediaWikiServices::getInstance()->getUserGroupManager()
61  ->getUserEffectiveGroups( $user );
62  foreach ( $effectiveGroups as $group ) {
63  if ( $group == '*' ) {
64  continue;
65  }
66  $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
67  }
68  }
69 
70  // This is obsolete since 1.32 (T112474). It was formerly used by
71  // OutputPage to implement previewing of user CSS and JS.
72  // @todo: Remove it once we're sure nothing else is using the parameter
73  $excludepage = $context->getRequest()->getVal( 'excludepage' );
74  unset( $pages[$excludepage] );
75 
76  return $pages;
77  }
78 
82  public function getType() {
83  return self::LOAD_STYLES;
84  }
85 
91  public function getGroup() {
92  return self::GROUP_USER;
93  }
94 }
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 styles.
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.".