From: Timo Tijhof Date: Fri, 16 Jun 2017 19:25:41 +0000 (+0200) Subject: ResourceLoaderSkinModule: Fix SkinStyles extending of known media queries X-Git-Tag: 1.31.0-rc.0~2753 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%2C%22id_auteur=%24connecte%22%29%20.%20%22?a=commitdiff_plain;h=171bcfaae9aa28ee356a62e5e1d273823ae3cd9e;p=lhc%2Fweb%2Fwiklou.git ResourceLoaderSkinModule: Fix SkinStyles extending of known media queries If any of the styles given in its module definition (in the 'styles' or 'skinStyles' properties) used the same media queries as the module's own CSS (e.g. 'all'), the module would fail with "PHP Fatal error: [] operator not supported for strings" because FileModule defaults to merging all the stylesheets into a single string. Fix this by ensuring they are arrays before trying to extend them. This previously made it impossible to use $wgResourceModuleSkinStyles for modules that use SkinModule (instead of plain FileModule), such as the 'mediawiki.skinning.interface' module. Bug: T168088 Change-Id: I3effcaa4982728e707fbf9efeec4e5e78fc8aab6 --- diff --git a/includes/resourceloader/ResourceLoaderSkinModule.php b/includes/resourceloader/ResourceLoaderSkinModule.php index 1967a95714..ca6e59f2bf 100644 --- a/includes/resourceloader/ResourceLoaderSkinModule.php +++ b/includes/resourceloader/ResourceLoaderSkinModule.php @@ -34,6 +34,7 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { public function getStyles( ResourceLoaderContext $context ) { $logo = $this->getLogo( $this->getConfig() ); $styles = parent::getStyles( $context ); + $this->normalizeStyles( $styles ); $default = !is_array( $logo ) ? $logo : $logo['1x']; $styles['all'][] = '.mw-wiki-logo { background-image: ' . @@ -66,6 +67,22 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { return $styles; } + /** + * Ensure all media keys use array values. + * + * Normalises arrays returned by the ResourceLoaderFileModule::getStyles() method. + * + * @param array &$styles Associative array, keys are strings (media queries), + * values are strings or arrays + */ + private function normalizeStyles( &$styles ) { + foreach ( $styles as $key => $val ) { + if ( !is_array( $val ) ) { + $styles[$key] = [ $val ]; + } + } + } + /** * @param Config $conf * @return string|array Single url if no variants are defined