Add support for HD versions of the wiki logo in MonoBook-like skins.
authorisarra <s@zaori.org>
Mon, 9 Mar 2015 01:55:31 +0000 (01:55 +0000)
committerisarra <s@zaori.org>
Fri, 13 Mar 2015 06:20:00 +0000 (06:20 +0000)
Done using an array $wgLogoHD, which expects something like the following:

$wgLogoHD = array(
"1.5x" => "path/to/1.5x_version.png",
"2x" => "path/to/2x_version.png"
);

This is still horrible, but I dunno how to make it less horrible. Help.

Bug: T37337
Change-Id: Iee3e73c1f96b81c2094418986cf1c267d93d1bdd

includes/DefaultSettings.php
includes/resourceloader/ResourceLoaderSkinModule.php

index 8080774..bc6db86 100644 (file)
@@ -257,6 +257,23 @@ $wgFileCacheDirectory = false;
  */
 $wgLogo = false;
 
+/**
+ * Array with URL paths to HD versions of the wiki logo. The scaled logo size
+ * should be under 135x155 pixels.
+ * Only 1.5x and 2x versions are supported.
+ *
+ * @par Example:
+ * @code
+ * $wgLogoHD = array(
+ *     "1.5x" => "path/to/1.5x_version.png",
+ *     "2x" => "path/to/2x_version.png"
+ * );
+ * @endcode
+ *
+ * @since 1.25
+ */
+$wgLogoHD = false;
+
 /**
  * The URL path of the shortcut icon.
  * @since 1.6
index 9835932..3ba63e6 100644 (file)
@@ -31,11 +31,33 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
         */
        public function getStyles( ResourceLoaderContext $context ) {
                $logo = $this->getConfig()->get( 'Logo' );
+               $logoHD = $this->getConfig()->get( 'LogoHD' );
                $styles = parent::getStyles( $context );
                $styles['all'][] = '.mw-wiki-logo { background-image: ' .
                        CSSMin::buildUrlValue( $logo ) .
                        '; }';
-
+               if ( $logoHD ) {
+                       if ( isset( $logoHD['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( $logoHD['1.5x'] ) .';' .
+                               'background-size: 135px auto; }';
+                       }
+                       if ( isset( $logoHD['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( $logoHD['2x'] ) . ';' .
+                               'background-size: 135px auto; }';
+                       }
+               }
                return $styles;
        }
 
@@ -64,6 +86,7 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
         */
        public function getModifiedHash( ResourceLoaderContext $context ) {
                $logo = $this->getConfig()->get( 'Logo' );
-               return md5( parent::getModifiedHash( $context ) . $logo );
+               $logoHD = $this->getConfig()->get( 'LogoHD' );
+               return md5( parent::getModifiedHash( $context ) . $logo . json_encode( $logoHD ) );
        }
 }