| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\ResourceLoader; |
| 22 |
|
| 23 |
use InvalidArgumentException; |
| 24 |
use MediaWiki\Registration\ExtensionRegistry; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
trait OOUIModule { |
| 33 |
|
| 34 |
protected static $knownScriptsModules = [ 'core' ]; |
| 35 |
|
| 36 |
protected static $knownStylesModules = [ 'core', 'widgets', 'toolbars', 'windows' ]; |
| 37 |
|
| 38 |
protected static $knownImagesModules = [ |
| 39 |
'indicators', |
| 40 |
|
| 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 |
|
| 60 |
|
| 61 |
protected static $builtinSkinThemeMap = [ |
| 62 |
'default' => 'WikimediaUI', |
| 63 |
]; |
| 64 |
|
| 65 |
|
| 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 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public static function getSkinThemeMap() { |
| 86 |
$themeMap = self::$builtinSkinThemeMap; |
| 87 |
$themeMap += ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' ); |
| 88 |
return $themeMap; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
protected static function getThemePaths() { |
| 102 |
$themePaths = self::$builtinThemePaths; |
| 103 |
$themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' ); |
| 104 |
|
| 105 |
[ $defaultLocalBasePath, $defaultRemoteBasePath ] = |
| 106 |
FileModule::extractBasePaths(); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
foreach ( $themePaths as &$paths ) { |
| 111 |
[ $localBasePath, $remoteBasePath ] = |
| 112 |
FileModule::extractBasePaths( $paths ); |
| 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 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 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 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 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 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 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 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 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 |
} |