3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * Convenience methods for dealing with OOUI themes and their relations to MW skins.
26 trait ResourceLoaderOOUIModule
{
27 protected static $knownScriptsModules = [ 'core' ];
28 protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ];
29 protected static $knownImagesModules = [
30 'indicators', 'textures',
32 'icons-accessibility',
35 'icons-editing-advanced',
36 'icons-editing-citation',
39 'icons-editing-styling',
50 // Note that keys must be lowercase, values TitleCase.
51 protected static $builtinSkinThemeMap = [
52 'default' => 'WikimediaUI',
55 // Note that keys must be TitleCase.
56 protected static $builtinThemePaths = [
58 'scripts' => 'resources/lib/ooui/oojs-ui-wikimediaui.js',
59 'styles' => 'resources/lib/ooui/oojs-ui-{module}-wikimediaui.css',
60 'images' => 'resources/lib/ooui/themes/wikimediaui/{module}.json',
63 'scripts' => 'resources/lib/ooui/oojs-ui-apex.js',
64 'styles' => 'resources/lib/ooui/oojs-ui-{module}-apex.css',
65 'images' => 'resources/lib/ooui/themes/apex/{module}.json',
70 * Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given
75 public static function getSkinThemeMap() {
76 $themeMap = self
::$builtinSkinThemeMap;
77 $themeMap +
= ExtensionRegistry
::getInstance()->getAttribute( 'SkinOOUIThemes' );
82 * Return a map of theme names to lists of paths from which a given theme should be loaded.
84 * Keys are theme names, values are associative arrays. Keys of the inner array are 'scripts',
85 * 'styles', or 'images', and values are string paths.
87 * Additionally, the string '{module}' in paths represents the name of the module to load.
91 protected static function getThemePaths() {
92 $themePaths = self
::$builtinThemePaths;
97 * Return a path to load given module of given theme from.
99 * @param string $theme OOUI theme name, for example 'WikimediaUI' or 'Apex'
100 * @param string $kind Kind of the module: 'scripts', 'styles', or 'images'
101 * @param string $module Module name, for valid values see $knownScriptsModules,
102 * $knownStylesModules, $knownImagesModules
105 protected function getThemePath( $theme, $kind, $module ) {
106 $paths = self
::getThemePaths();
107 $path = $paths[ $theme ][ $kind ];
108 $path = str_replace( '{module}', $module, $path );
113 * @param string $theme See getThemePath()
114 * @param string $module See getThemePath()
117 protected function getThemeScriptsPath( $theme, $module ) {
118 if ( !in_array( $module, self
::$knownScriptsModules ) ) {
119 throw new InvalidArgumentException( "Invalid OOUI scripts module '$module'" );
121 return $this->getThemePath( $theme, 'scripts', $module );
125 * @param string $theme See getThemePath()
126 * @param string $module See getThemePath()
129 protected function getThemeStylesPath( $theme, $module ) {
130 if ( !in_array( $module, self
::$knownStylesModules ) ) {
131 throw new InvalidArgumentException( "Invalid OOUI styles module '$module'" );
133 return $this->getThemePath( $theme, 'styles', $module );
137 * @param string $theme See getThemePath()
138 * @param string $module See getThemePath()
141 protected function getThemeImagesPath( $theme, $module ) {
142 if ( !in_array( $module, self
::$knownImagesModules ) ) {
143 throw new InvalidArgumentException( "Invalid OOUI images module '$module'" );
145 return $this->getThemePath( $theme, 'images', $module );