MediaWiki  master
UserStylesModule.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\ResourceLoader;
24 
27 use TitleValue;
28 
36 
37  protected $origin = self::ORIGIN_USER_INDIVIDUAL;
38  protected $targets = [ 'desktop', 'mobile' ];
39 
44  protected function getPages( Context $context ) {
45  $user = $context->getUserIdentity();
46  if ( !$user || !$user->isRegistered() ) {
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.css"] = [ 'type' => 'style' ];
58  $pages["$userPage/" . $context->getSkin() . '.css'] = [ 'type' => 'style' ];
59  }
60 
61  // User group pages are maintained site-wide and enabled with site JS/CSS.
63  $effectiveGroups = MediaWikiServices::getInstance()->getUserGroupManager()
64  ->getUserEffectiveGroups( $user );
65  foreach ( $effectiveGroups as $group ) {
66  if ( $group == '*' ) {
67  continue;
68  }
69  $pages["MediaWiki:Group-$group.css"] = [ 'type' => 'style' ];
70  }
71  }
72 
73  return $pages;
74  }
75 
79  public function getType() {
80  return self::LOAD_STYLES;
81  }
82 
88  public function getGroup() {
89  return self::GROUP_USER;
90  }
91 }
92 
94 class_alias( UserStylesModule::class, 'ResourceLoaderUserStylesModule' );
const NS_USER
Definition: Defines.php:66
A class containing constants representing the names of configuration variables.
const UseSiteCss
Name constant for the UseSiteCss setting, for use with Config::get()
const AllowUserCss
Name constant for the AllowUserCss 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:46
getUserIdentity()
Get the possibly-cached UserIdentity object for the specified username.
Definition: Context.php:286
Module for user customizations styles.
Abstraction for ResourceLoader modules which pull from wiki pages.
Definition: WikiModule.php:65
string null $group
Group of module.
Definition: WikiModule.php:97
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".