MediaWiki master
OOUIModule.php
Go to the documentation of this file.
1<?php
8
9use InvalidArgumentException;
11
20 protected static $knownScriptsModules = [ 'core' ];
22 protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ];
24 protected static $knownImagesModules = [
25 'indicators',
26 // Extra icons
27 'icons-accessibility',
28 'icons-alerts',
29 'icons-content',
30 'icons-editing-advanced',
31 'icons-editing-citation',
32 'icons-editing-functions',
33 'icons-editing-core',
34 'icons-editing-list',
35 'icons-editing-styling',
36 'icons-interactions',
37 'icons-layout',
38 'icons-location',
39 'icons-media',
40 'icons-moderation',
41 'icons-movement',
42 'icons-user',
43 'icons-wikimedia',
44 ];
45
47 protected static $builtinSkinThemeMap = [
48 'default' => 'WikimediaUI',
49 ];
50
52 protected static $builtinThemePaths = [
53 'WikimediaUI' => [
54 'scripts' => 'resources/lib/ooui/oojs-ui-wikimediaui.js',
55 'styles' => 'resources/lib/ooui/oojs-ui-{module}-wikimediaui.css',
56 'images' => 'resources/lib/ooui/themes/wikimediaui/{module}.json',
57 ],
58 'Apex' => [
59 'scripts' => 'resources/lib/ooui/oojs-ui-apex.js',
60 'styles' => 'resources/lib/ooui/oojs-ui-{module}-apex.css',
61 'images' => 'resources/lib/ooui/themes/apex/{module}.json',
62 ],
63 ];
64
71 public static function getSkinThemeMap() {
73 $themeMap += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
74 return $themeMap;
75 }
76
87 protected static function getThemePaths() {
88 $themePaths = self::$builtinThemePaths;
89 $themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' );
90
91 [ $defaultLocalBasePath, $defaultRemoteBasePath ] =
93
94 // Allow custom themes' paths to be relative to the skin/extension that defines them,
95 // like with ResourceModuleSkinStyles
96 foreach ( $themePaths as &$paths ) {
97 [ $localBasePath, $remoteBasePath ] =
99 if ( $localBasePath !== $defaultLocalBasePath || $remoteBasePath !== $defaultRemoteBasePath ) {
100 foreach ( $paths as &$path ) {
101 $path = new FilePath( $path, $localBasePath, $remoteBasePath );
102 }
103 }
104 }
105
106 return $themePaths;
107 }
108
121 protected function getThemePath( $theme, $kind, $module ) {
122 $paths = self::getThemePaths();
123 $path = $paths[$theme][$kind];
124 if ( $path instanceof FilePath ) {
125 $path = new FilePath(
126 str_replace( '{module}', $module, $path->getPath() ),
127 $path->getLocalBasePath(),
128 $path->getRemoteBasePath()
129 );
130 } else {
131 $path = str_replace( '{module}', $module, $path );
132 }
133 return $path;
134 }
135
141 protected function getThemeScriptsPath( $theme, $module ) {
142 if ( !in_array( $module, self::$knownScriptsModules ) ) {
143 throw new InvalidArgumentException( "Invalid OOUI scripts module '$module'" );
144 }
145 return $this->getThemePath( $theme, 'scripts', $module );
146 }
147
153 protected function getThemeStylesPath( $theme, $module ) {
154 if ( !in_array( $module, self::$knownStylesModules ) ) {
155 throw new InvalidArgumentException( "Invalid OOUI styles module '$module'" );
156 }
157 return $this->getThemePath( $theme, 'styles', $module );
158 }
159
165 protected function getThemeImagesPath( $theme, $module ) {
166 if ( !in_array( $module, self::$knownImagesModules ) ) {
167 throw new InvalidArgumentException( "Invalid OOUI images module '$module'" );
168 }
169 return $this->getThemePath( $theme, 'images', $module );
170 }
171}
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:20
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.