X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fresourceloader%2FResourceLoaderOOUIModule.php;h=fdcc2135e2c9d667abdeded90304baef0268b10d;hb=fd130247c28da68c351029124d8ddf1ad77db3f7;hp=899fbbde72f5c3d95e5b1f5833a6ade09de7b132;hpb=8fc57e9555b704edf883e828878f0120d85a7b1c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderOOUIModule.php b/includes/resourceloader/ResourceLoaderOOUIModule.php index 899fbbde72..fdcc2135e2 100644 --- a/includes/resourceloader/ResourceLoaderOOUIModule.php +++ b/includes/resourceloader/ResourceLoaderOOUIModule.php @@ -82,7 +82,7 @@ trait ResourceLoaderOOUIModule { * Return a map of theme names to lists of paths from which a given theme should be loaded. * * Keys are theme names, values are associative arrays. Keys of the inner array are 'scripts', - * 'styles', or 'images', and values are string paths. + * 'styles', or 'images', and values are paths. Paths may be strings or ResourceLoaderFilePaths. * * Additionally, the string '{module}' in paths represents the name of the module to load. * @@ -90,29 +90,57 @@ trait ResourceLoaderOOUIModule { */ protected static function getThemePaths() { $themePaths = self::$builtinThemePaths; + $themePaths += ExtensionRegistry::getInstance()->getAttribute( 'OOUIThemePaths' ); + + list( $defaultLocalBasePath, $defaultRemoteBasePath ) = + ResourceLoaderFileModule::extractBasePaths(); + + // Allow custom themes' paths to be relative to the skin/extension that defines them, + // like with ResourceModuleSkinStyles + foreach ( $themePaths as $theme => &$paths ) { + list( $localBasePath, $remoteBasePath ) = + ResourceLoaderFileModule::extractBasePaths( $paths ); + if ( $localBasePath !== $defaultLocalBasePath || $remoteBasePath !== $defaultRemoteBasePath ) { + foreach ( $paths as &$path ) { + $path = new ResourceLoaderFilePath( $path, $localBasePath, $remoteBasePath ); + } + } + } + return $themePaths; } /** * Return a path to load given module of given theme from. * + * The file at this path may not exist. This should be handled by the caller (throwing an error or + * falling back to default theme). + * * @param string $theme OOUI theme name, for example 'WikimediaUI' or 'Apex' * @param string $kind Kind of the module: 'scripts', 'styles', or 'images' * @param string $module Module name, for valid values see $knownScriptsModules, * $knownStylesModules, $knownImagesModules - * @return string + * @return string|ResourceLoaderFilePath */ protected function getThemePath( $theme, $kind, $module ) { $paths = self::getThemePaths(); $path = $paths[$theme][$kind]; - $path = str_replace( '{module}', $module, $path ); + if ( $path instanceof ResourceLoaderFilePath ) { + $path = new ResourceLoaderFilePath( + str_replace( '{module}', $module, $path->getPath() ), + $path->getLocalBasePath(), + $path->getRemoteBasePath() + ); + } else { + $path = str_replace( '{module}', $module, $path ); + } return $path; } /** * @param string $theme See getThemePath() * @param string $module See getThemePath() - * @return string + * @return string|ResourceLoaderFilePath */ protected function getThemeScriptsPath( $theme, $module ) { if ( !in_array( $module, self::$knownScriptsModules ) ) { @@ -124,7 +152,7 @@ trait ResourceLoaderOOUIModule { /** * @param string $theme See getThemePath() * @param string $module See getThemePath() - * @return string + * @return string|ResourceLoaderFilePath */ protected function getThemeStylesPath( $theme, $module ) { if ( !in_array( $module, self::$knownStylesModules ) ) { @@ -136,7 +164,7 @@ trait ResourceLoaderOOUIModule { /** * @param string $theme See getThemePath() * @param string $module See getThemePath() - * @return string + * @return string|ResourceLoaderFilePath */ protected function getThemeImagesPath( $theme, $module ) { if ( !in_array( $module, self::$knownImagesModules ) ) {