MediaWiki REL1_41
OOUIModule.php
Go to the documentation of this file.
1<?php
22
24use InvalidArgumentException;
25
33 protected static $knownScriptsModules = [ 'core' ];
34 protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ];
35 protected static $knownImagesModules = [
36 'indicators',
37 // Extra icons
38 'icons-accessibility',
39 'icons-alerts',
40 'icons-content',
41 'icons-editing-advanced',
42 'icons-editing-citation',
43 'icons-editing-core',
44 'icons-editing-list',
45 'icons-editing-styling',
46 'icons-interactions',
47 'icons-layout',
48 'icons-location',
49 'icons-media',
50 'icons-moderation',
51 'icons-movement',
52 'icons-user',
53 'icons-wikimedia',
54 ];
55
57 protected static $builtinSkinThemeMap = [
58 'default' => 'WikimediaUI',
59 ];
60
62 protected static $builtinThemePaths = [
63 'WikimediaUI' => [
64 'scripts' => 'resources/lib/ooui/oojs-ui-wikimediaui.js',
65 'styles' => 'resources/lib/ooui/oojs-ui-{module}-wikimediaui.css',
66 'images' => 'resources/lib/ooui/themes/wikimediaui/{module}.json',
67 ],
68 'Apex' => [
69 'scripts' => 'resources/lib/ooui/oojs-ui-apex.js',
70 'styles' => 'resources/lib/ooui/oojs-ui-{module}-apex.css',
71 'images' => 'resources/lib/ooui/themes/apex/{module}.json',
72 ],
73 ];
74
81 public static function getSkinThemeMap() {
83 $themeMap += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
84 return $themeMap;
85 }
86
97 protected static function getThemePaths() {
98 $themePaths = self::$builtinThemePaths;
99 $themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' );
100
101 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
103
104 // Allow custom themes' paths to be relative to the skin/extension that defines them,
105 // like with ResourceModuleSkinStyles
106 foreach ( $themePaths as &$paths ) {
107 [ $localBasePath, $remoteBasePath ] =
109 if ( $localBasePath !== $defaultLocalBasePath || $remoteBasePath !== $defaultRemoteBasePath ) {
110 foreach ( $paths as &$path ) {
111 $path = new FilePath( $path, $localBasePath, $remoteBasePath );
112 }
113 }
114 }
115
116 return $themePaths;
117 }
118
131 protected function getThemePath( $theme, $kind, $module ) {
132 $paths = self::getThemePaths();
133 $path = $paths[$theme][$kind];
134 if ( $path instanceof FilePath ) {
135 $path = new FilePath(
136 str_replace( '{module}', $module, $path->getPath() ),
137 $path->getLocalBasePath(),
138 $path->getRemoteBasePath()
139 );
140 } else {
141 $path = str_replace( '{module}', $module, $path );
142 }
143 return $path;
144 }
145
151 protected function getThemeScriptsPath( $theme, $module ) {
152 if ( !in_array( $module, self::$knownScriptsModules ) ) {
153 throw new InvalidArgumentException( "Invalid OOUI scripts module '$module'" );
154 }
155 return $this->getThemePath( $theme, 'scripts', $module );
156 }
157
163 protected function getThemeStylesPath( $theme, $module ) {
164 if ( !in_array( $module, self::$knownStylesModules ) ) {
165 throw new InvalidArgumentException( "Invalid OOUI styles module '$module'" );
166 }
167 return $this->getThemePath( $theme, 'styles', $module );
168 }
169
175 protected function getThemeImagesPath( $theme, $module ) {
176 if ( !in_array( $module, self::$knownImagesModules ) ) {
177 throw new InvalidArgumentException( "Invalid OOUI images module '$module'" );
178 }
179 return $this->getThemePath( $theme, 'images', $module );
180 }
181}
182
184class_alias( OOUIModule::class, 'ResourceLoaderOOUIModule' );
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)
getThemePath( $theme, $kind, $module)
Return a path to load given module of given theme from.
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.