MediaWiki master
OOUIModule.php
Go to the documentation of this file.
1<?php
22
23use InvalidArgumentException;
25
34 protected static $knownScriptsModules = [ 'core' ];
36 protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ];
38 protected static $knownImagesModules = [
39 'indicators',
40 // Extra icons
41 'icons-accessibility',
42 'icons-alerts',
43 'icons-content',
44 'icons-editing-advanced',
45 'icons-editing-citation',
46 'icons-editing-functions',
47 'icons-editing-core',
48 'icons-editing-list',
49 'icons-editing-styling',
50 'icons-interactions',
51 'icons-layout',
52 'icons-location',
53 'icons-media',
54 'icons-moderation',
55 'icons-movement',
56 'icons-user',
57 'icons-wikimedia',
58 ];
59
61 protected static $builtinSkinThemeMap = [
62 'default' => 'WikimediaUI',
63 ];
64
66 protected static $builtinThemePaths = [
67 'WikimediaUI' => [
68 'scripts' => 'resources/lib/ooui/oojs-ui-wikimediaui.js',
69 'styles' => 'resources/lib/ooui/oojs-ui-{module}-wikimediaui.css',
70 'images' => 'resources/lib/ooui/themes/wikimediaui/{module}.json',
71 ],
72 'Apex' => [
73 'scripts' => 'resources/lib/ooui/oojs-ui-apex.js',
74 'styles' => 'resources/lib/ooui/oojs-ui-{module}-apex.css',
75 'images' => 'resources/lib/ooui/themes/apex/{module}.json',
76 ],
77 ];
78
85 public static function getSkinThemeMap() {
87 $themeMap += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
88 return $themeMap;
89 }
90
101 protected static function getThemePaths() {
102 $themePaths = self::$builtinThemePaths;
103 $themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' );
104
105 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
107
108 // Allow custom themes' paths to be relative to the skin/extension that defines them,
109 // like with ResourceModuleSkinStyles
110 foreach ( $themePaths as &$paths ) {
111 [ $localBasePath, $remoteBasePath ] =
113 if ( $localBasePath !== $defaultLocalBasePath || $remoteBasePath !== $defaultRemoteBasePath ) {
114 foreach ( $paths as &$path ) {
115 $path = new FilePath( $path, $localBasePath, $remoteBasePath );
116 }
117 }
118 }
119
120 return $themePaths;
121 }
122
135 protected function getThemePath( $theme, $kind, $module ) {
136 $paths = self::getThemePaths();
137 $path = $paths[$theme][$kind];
138 if ( $path instanceof FilePath ) {
139 $path = new FilePath(
140 str_replace( '{module}', $module, $path->getPath() ),
141 $path->getLocalBasePath(),
142 $path->getRemoteBasePath()
143 );
144 } else {
145 $path = str_replace( '{module}', $module, $path );
146 }
147 return $path;
148 }
149
155 protected function getThemeScriptsPath( $theme, $module ) {
156 if ( !in_array( $module, self::$knownScriptsModules ) ) {
157 throw new InvalidArgumentException( "Invalid OOUI scripts module '$module'" );
158 }
159 return $this->getThemePath( $theme, 'scripts', $module );
160 }
161
167 protected function getThemeStylesPath( $theme, $module ) {
168 if ( !in_array( $module, self::$knownStylesModules ) ) {
169 throw new InvalidArgumentException( "Invalid OOUI styles module '$module'" );
170 }
171 return $this->getThemePath( $theme, 'styles', $module );
172 }
173
179 protected function getThemeImagesPath( $theme, $module ) {
180 if ( !in_array( $module, self::$knownImagesModules ) ) {
181 throw new InvalidArgumentException( "Invalid OOUI images module '$module'" );
182 }
183 return $this->getThemePath( $theme, 'images', $module );
184 }
185}
Load JSON files, and uses a Processor to extract information.
static extractBasePaths(array $options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information.
A path to a bundled file (such as JavaScript or CSS), along with a remote and local base path.
Definition FilePath.php:34
trait OOUIModule
Convenience methods for dealing with OOUI themes and their relations to MW skins.
getThemeStylesPath( $theme, $module)
static string[][] $builtinThemePaths
Note that keys must be TitleCase.
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
getThemeImagesPath( $theme, $module)
getThemeScriptsPath( $theme, $module)
static string[] $knownImagesModules
getThemePath( $theme, $kind, $module)
Return a path to load given module of given theme from.
static string[] $knownStylesModules
static string[] $builtinSkinThemeMap
Note that keys must be lowercase, values TitleCase.
static getThemePaths()
Return a map of theme names to lists of paths from which a given theme should be loaded.