X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fresourceloader%2FResourceLoaderSkinModule.php;h=fbd0a24a7f6c2568d86a692656bbc12bd38f64e5;hb=d84c3dde5af90c5c3497d18e427a5c2a38ac6ca8;hp=5740925d2a4585dbd564b827993b177bbdd108e3;hpb=a4943f548be4cfc8f286f00fc8064ff0e377f2ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/resourceloader/ResourceLoaderSkinModule.php b/includes/resourceloader/ResourceLoaderSkinModule.php index 5740925d2a..fbd0a24a7f 100644 --- a/includes/resourceloader/ResourceLoaderSkinModule.php +++ b/includes/resourceloader/ResourceLoaderSkinModule.php @@ -22,14 +22,19 @@ */ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { + /** + * All skins are assumed to be compatible with mobile + */ + public $targets = [ 'desktop', 'mobile' ]; /** * @param ResourceLoaderContext $context * @return array */ public function getStyles( ResourceLoaderContext $context ) { - $logo = $this->getLogo( $this->getConfig() ); + $logo = $this->getLogoData( $this->getConfig() ); $styles = parent::getStyles( $context ); + $this->normalizeStyles( $styles ); $default = !is_array( $logo ) ? $logo : $logo['1x']; $styles['all'][] = '.mw-wiki-logo { background-image: ' . @@ -37,25 +42,34 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { '; }'; if ( is_array( $logo ) ) { - if ( isset( $logo['1.5x'] ) ) { - $styles[ - '(-webkit-min-device-pixel-ratio: 1.5), ' . - '(min--moz-device-pixel-ratio: 1.5), ' . + if ( isset( $logo['svg'] ) ) { + $styles['all'][] = '.mw-wiki-logo { ' . + 'background-image: -webkit-linear-gradient(transparent, transparent), ' . + CSSMin::buildUrlValue( $logo['svg'] ) . '; ' . + 'background-image: linear-gradient(transparent, transparent), ' . + CSSMin::buildUrlValue( $logo['svg'] ) . ';' . + 'background-size: 135px auto; }'; + } else { + if ( isset( $logo['1.5x'] ) ) { + $styles[ + '(-webkit-min-device-pixel-ratio: 1.5), ' . + '(min--moz-device-pixel-ratio: 1.5), ' . '(min-resolution: 1.5dppx), ' . - '(min-resolution: 144dpi)' - ][] = '.mw-wiki-logo { background-image: ' . - CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' . - 'background-size: 135px auto; }'; - } - if ( isset( $logo['2x'] ) ) { - $styles[ - '(-webkit-min-device-pixel-ratio: 2), ' . - '(min--moz-device-pixel-ratio: 2),' . - '(min-resolution: 2dppx), ' . - '(min-resolution: 192dpi)' - ][] = '.mw-wiki-logo { background-image: ' . - CSSMin::buildUrlValue( $logo['2x'] ) . ';' . - 'background-size: 135px auto; }'; + '(min-resolution: 144dpi)' + ][] = '.mw-wiki-logo { background-image: ' . + CSSMin::buildUrlValue( $logo['1.5x'] ) . ';' . + 'background-size: 135px auto; }'; + } + if ( isset( $logo['2x'] ) ) { + $styles[ + '(-webkit-min-device-pixel-ratio: 2), ' . + '(min--moz-device-pixel-ratio: 2), ' . + '(min-resolution: 2dppx), ' . + '(min-resolution: 192dpi)' + ][] = '.mw-wiki-logo { background-image: ' . + CSSMin::buildUrlValue( $logo['2x'] ) . ';' . + 'background-size: 135px auto; }'; + } } } @@ -63,10 +77,36 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { } /** + * 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 ]; + } + } + } + + /** + * @since 1.31 * @param Config $conf - * @return string|array Single url if no variants are defined - * or array of logo urls keyed by dppx in form "x". - * Key "1x" is always defined. + * @return string|array + */ + protected function getLogoData( Config $conf ) { + return static::getLogo( $conf ); + } + + /** + * @param Config $conf + * @return string|array Single url if no variants are defined, + * or an array of logo urls keyed by dppx in form "x". + * Key "1x" is always defined. Key "svg" may also be defined, + * in which case variants other than "1x" are omitted. */ public static function getLogo( Config $conf ) { $logo = $conf->get( 'Logo' ); @@ -82,18 +122,25 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { '1x' => $logo1Url, ]; - // Only 1.5x and 2x are supported - if ( isset( $logoHD['1.5x'] ) ) { - $logoUrls['1.5x'] = OutputPage::transformResourcePath( + if ( isset( $logoHD['svg'] ) ) { + $logoUrls['svg'] = OutputPage::transformResourcePath( $conf, - $logoHD['1.5x'] - ); - } - if ( isset( $logoHD['2x'] ) ) { - $logoUrls['2x'] = OutputPage::transformResourcePath( - $conf, - $logoHD['2x'] + $logoHD['svg'] ); + } else { + // Only 1.5x and 2x are supported + if ( isset( $logoHD['1.5x'] ) ) { + $logoUrls['1.5x'] = OutputPage::transformResourcePath( + $conf, + $logoHD['1.5x'] + ); + } + if ( isset( $logoHD['2x'] ) ) { + $logoUrls['2x'] = OutputPage::transformResourcePath( + $conf, + $logoHD['2x'] + ); + } } return $logoUrls;