MediaWiki REL1_35
ResourceLoaderOOUIModule.php
Go to the documentation of this file.
1<?php
28 protected static $knownScriptsModules = [ 'core' ];
29 protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ];
30 protected static $knownImagesModules = [
31 'indicators',
32 // Extra icons
33 'icons-accessibility',
34 'icons-alerts',
35 'icons-content',
36 'icons-editing-advanced',
37 'icons-editing-citation',
38 'icons-editing-core',
39 'icons-editing-list',
40 'icons-editing-styling',
41 'icons-interactions',
42 'icons-layout',
43 'icons-location',
44 'icons-media',
45 'icons-moderation',
46 'icons-movement',
47 'icons-user',
48 'icons-wikimedia',
49 ];
50
51 // Note that keys must be lowercase, values TitleCase.
52 protected static $builtinSkinThemeMap = [
53 'default' => 'WikimediaUI',
54 ];
55
56 // Note that keys must be TitleCase.
57 protected static $builtinThemePaths = [
58 'WikimediaUI' => [
59 'scripts' => 'resources/lib/ooui/oojs-ui-wikimediaui.js',
60 'styles' => 'resources/lib/ooui/oojs-ui-{module}-wikimediaui.css',
61 'images' => 'resources/lib/ooui/themes/wikimediaui/{module}.json',
62 ],
63 'Apex' => [
64 'scripts' => 'resources/lib/ooui/oojs-ui-apex.js',
65 'styles' => 'resources/lib/ooui/oojs-ui-{module}-apex.css',
66 'images' => 'resources/lib/ooui/themes/apex/{module}.json',
67 ],
68 ];
69
76 public static function getSkinThemeMap() {
78 $themeMap += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
79 return $themeMap;
80 }
81
92 protected static function getThemePaths() {
93 $themePaths = self::$builtinThemePaths;
94 $themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' );
95
96 list( $defaultLocalBasePath, $defaultRemoteBasePath ) =
98
99 // Allow custom themes' paths to be relative to the skin/extension that defines them,
100 // like with ResourceModuleSkinStyles
101 foreach ( $themePaths as $theme => &$paths ) {
102 list( $localBasePath, $remoteBasePath ) =
104 if ( $localBasePath !== $defaultLocalBasePath || $remoteBasePath !== $defaultRemoteBasePath ) {
105 foreach ( $paths as &$path ) {
106 $path = new ResourceLoaderFilePath( $path, $localBasePath, $remoteBasePath );
107 }
108 }
109 }
110
111 return $themePaths;
112 }
113
126 protected function getThemePath( $theme, $kind, $module ) {
127 $paths = self::getThemePaths();
128 $path = $paths[$theme][$kind];
129 if ( $path instanceof ResourceLoaderFilePath ) {
131 str_replace( '{module}', $module, $path->getPath() ),
132 $path->getLocalBasePath(),
133 $path->getRemoteBasePath()
134 );
135 } else {
136 $path = str_replace( '{module}', $module, $path );
137 }
138 return $path;
139 }
140
146 protected function getThemeScriptsPath( $theme, $module ) {
147 if ( !in_array( $module, self::$knownScriptsModules ) ) {
148 throw new InvalidArgumentException( "Invalid OOUI scripts module '$module'" );
149 }
150 return $this->getThemePath( $theme, 'scripts', $module );
151 }
152
158 protected function getThemeStylesPath( $theme, $module ) {
159 if ( !in_array( $module, self::$knownStylesModules ) ) {
160 throw new InvalidArgumentException( "Invalid OOUI styles module '$module'" );
161 }
162 return $this->getThemePath( $theme, 'styles', $module );
163 }
164
170 protected function getThemeImagesPath( $theme, $module ) {
171 if ( !in_array( $module, self::$knownImagesModules ) ) {
172 throw new InvalidArgumentException( "Invalid OOUI images module '$module'" );
173 }
174 return $this->getThemePath( $theme, 'images', $module );
175 }
176}
static $knownImagesModules
static getThemePaths()
Return a map of theme names to lists of paths from which a given theme should be loaded.
static $knownStylesModules
static $builtinSkinThemeMap
static $builtinThemePaths
getThemePath( $theme, $kind, $module)
Return a path to load given module of given theme from.
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
getThemeScriptsPath( $theme, $module)
getThemeStylesPath( $theme, $module)
getThemeImagesPath( $theme, $module)
static extractBasePaths(array $options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information.
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
trait ResourceLoaderOOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.