MediaWiki  master
ResourceLoaderUserStylesModule.php
Go to the documentation of this file.
1 <?php
30 
31  protected $origin = self::ORIGIN_USER_INDIVIDUAL;
32  protected $targets = [ 'desktop', 'mobile' ];
33 
38  protected function getPages( ResourceLoaderContext $context ) {
39  $config = $this->getConfig();
40  $user = $context->getUserObj();
41  if ( $user->isAnon() ) {
42  return [];
43  }
44 
45  // Use localised/normalised variant to ensure $excludepage matches
46  $userPage = $user->getUserPage()->getPrefixedDBkey();
47  $pages = [];
48 
49  if ( $config->get( 'AllowUserCss' ) ) {
50  $pages["$userPage/common.css"] = [ 'type' => 'style' ];
51  $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
52  }
53 
54  // User group pages are maintained site-wide and enabled with site JS/CSS.
55  if ( $config->get( 'UseSiteCss' ) ) {
56  foreach ( $user->getEffectiveGroups() as $group ) {
57  if ( $group == '*' ) {
58  continue;
59  }
60  $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
61  }
62  }
63 
64  // This is obsolete since 1.32 (T112474). It was formerly used by
65  // OutputPage to implement previewing of user CSS and JS.
66  // @todo: Remove it once we're sure nothing else is using the parameter
67  $excludepage = $context->getRequest()->getVal( 'excludepage' );
68  if ( isset( $pages[$excludepage] ) ) {
69  unset( $pages[$excludepage] );
70  }
71 
72  return $pages;
73  }
74 
78  public function getType() {
79  return self::LOAD_STYLES;
80  }
81 
87  public function getGroup() {
88  return 'user';
89  }
90 }
ResourceLoaderUserStylesModule\getType
getType()
Definition: ResourceLoaderUserStylesModule.php:78
ResourceLoaderUserStylesModule
Module for user customizations styles.
Definition: ResourceLoaderUserStylesModule.php:29
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:33
ResourceLoaderUserStylesModule\$origin
$origin
Definition: ResourceLoaderUserStylesModule.php:31
ResourceLoaderWikiModule
Abstraction for ResourceLoader modules which pull from wiki pages.
Definition: ResourceLoaderWikiModule.php:55
ResourceLoaderUserStylesModule\$targets
$targets
Definition: ResourceLoaderUserStylesModule.php:32
ResourceLoaderContext\getRequest
getRequest()
Definition: ResourceLoaderContext.php:138
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
ResourceLoaderUserStylesModule\getGroup
getGroup()
Get group name.
Definition: ResourceLoaderUserStylesModule.php:87
ResourceLoaderContext\getSkin
getSkin()
Definition: ResourceLoaderContext.php:188
ResourceLoaderWikiModule\$group
$group
Definition: ResourceLoaderWikiModule.php:81
ResourceLoaderModule\$config
Config $config
Definition: ResourceLoaderModule.php:41
ResourceLoaderContext\getUserObj
getUserObj()
Get the possibly-cached User object for the specified username.
Definition: ResourceLoaderContext.php:223
ResourceLoaderUserStylesModule\getPages
getPages(ResourceLoaderContext $context)
Definition: ResourceLoaderUserStylesModule.php:38
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:218