X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderOOUIFileModule.php;h=7d39a58e9c249c0557828100691fd0b2415f78e0;hb=99f611d07087ad0ec9ffc2d1919cad45c131002d;hp=135efa705caa1f98c31574815ed2d8a766da4d99;hpb=e4930c996bc52d81528614c105ce74c3a0063610;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderOOUIFileModule.php b/includes/resourceloader/ResourceLoaderOOUIFileModule.php index 135efa705c..7d39a58e9c 100644 --- a/includes/resourceloader/ResourceLoaderOOUIFileModule.php +++ b/includes/resourceloader/ResourceLoaderOOUIFileModule.php @@ -28,11 +28,19 @@ class ResourceLoaderOOUIFileModule extends ResourceLoaderFileModule { use ResourceLoaderOOUIModule; public function __construct( $options = [] ) { - if ( isset( $options[ 'themeScripts' ] ) ) { - $options['skinScripts'] = $this->getSkinSpecific( $options[ 'themeScripts' ], 'scripts' ); + if ( isset( $options['themeScripts'] ) ) { + $skinScripts = $this->getSkinSpecific( $options['themeScripts'], 'scripts' ); + if ( !isset( $options['skinScripts'] ) ) { + $options['skinScripts'] = []; + } + $this->extendSkinSpecific( $options['skinScripts'], $skinScripts ); } - if ( isset( $options[ 'themeStyles' ] ) ) { - $options['skinStyles'] = $this->getSkinSpecific( $options[ 'themeStyles' ], 'styles' ); + if ( isset( $options['themeStyles'] ) ) { + $skinStyles = $this->getSkinSpecific( $options['themeStyles'], 'styles' ); + if ( !isset( $options['skinStyles'] ) ) { + $options['skinStyles'] = []; + } + $this->extendSkinSpecific( $options['skinStyles'], $skinStyles ); } parent::__construct( $options ); @@ -60,4 +68,31 @@ class ResourceLoaderOOUIFileModule extends ResourceLoaderFileModule { }, array_values( $themes ) ) ); } + + /** + * Prepend the $extraSkinSpecific assoc. array to the $skinSpecific assoc. array. + * Both of them represent a 'skinScripts' or 'skinStyles' definition. + * + * @param array &$skinSpecific + * @param array $extraSkinSpecific + */ + private function extendSkinSpecific( &$skinSpecific, $extraSkinSpecific ) { + // For each skin where skinStyles/skinScripts are defined, add our ones at the beginning + foreach ( $skinSpecific as $skin => $files ) { + if ( !is_array( $files ) ) { + $files = [ $files ]; + } + if ( isset( $extraSkinSpecific[$skin] ) ) { + $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific[$skin] ], $files ); + } elseif ( isset( $extraSkinSpecific['default'] ) ) { + $skinSpecific[$skin] = array_merge( [ $extraSkinSpecific['default'] ], $files ); + } + } + // Add our remaining skinStyles/skinScripts for skins that did not have them defined + foreach ( $extraSkinSpecific as $skin => $file ) { + if ( !isset( $skinSpecific[$skin] ) ) { + $skinSpecific[$skin] = $file; + } + } + } }