UserCSSPrefsModule: Remove redundant inline text-decoration:none css rules
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 8 Jul 2015 18:56:31 +0000 (19:56 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 22 Dec 2015 23:00:40 +0000 (15:00 -0800)
By default user option 'underline' is '2' which means no skin override.

Once a upon a time, none of the popular MediaWiki skins specified whether links should have
underlines, and most browsers default to having an underline on links (when not hovering).

As such, there was an exception added for languages where underlines cause text to be unreadable.

Nowadays however all modern skins explicitly specify the intended design for links.
Neither the default skin (Vector) nor other popular skins I checked have underlines by default.
As such, this rule is redundant.

If a skin comes along that does specify underlines by default, then these rules should be placed
in that skins' stylesheet. Not in the HTML of all pages.

Incidentally, this was the last code branch in ResourceLoaderUserCSSPrefsModule that is true by
default. Which means from now on this <style> tag is automatically omitted from the HTML for
logged-out users and users that haven't changed the 'underline' or 'editfont' preference.

Implement the missing isKnownEmpty() method so that OutputPage does the automatic omission.

To test the new text-decoration rule in mediawiki.skinning:
* Change user preference language to "ar" and observe anchor links in the interface
  not having underlines on-hover.
* Change $wgLanguageCode to "ar" and observe anchor links in the content not having
  underlines on-hover.

History:
* 2011 (043f98a3; r101445) Move overrides from shared.css to ResourceLoaderUserOptionsModule
                           Also remove "!important" from underline css
* 2011 (33293c9b; r96261) Apply "!important" to underline user option css
* 2011 (81446abc; r91432; T31712) Move overrides from MessageXX.php to skins/common/shared.css
* 2006 (43b2fb56; r15823) Move overrides from LanguageXX.php to MessageX.php
* 2004 (f9f3e915) Add override to LanguageAr.php

Bug: T105313
Change-Id: I94dda30fb80b30e9c12a74a8b09065da55681929

includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
resources/src/mediawiki.skinning/elements.css

index 6705336..04b0434 100644 (file)
@@ -50,14 +50,10 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
                // Build CSS rules
                $rules = array();
 
-               // Underline: 2 = browser default, 1 = always, 0 = never
+               // Underline: 2 = skin default, 1 = always, 0 = never
                if ( $options['underline'] < 2 ) {
                        $rules[] = "a { text-decoration: " .
                                ( $options['underline'] ? 'underline' : 'none' ) . "; }";
-               } else {
-                       # The scripts of these languages are very hard to read with underlines
-                       $rules[] = 'a:lang(ar), a:lang(kk-arab), a:lang(mzn), ' .
-                       'a:lang(ps), a:lang(ur) { text-decoration: none; }';
                }
                if ( $options['editfont'] !== 'default' ) {
                        // Double-check that $options['editfont'] consists of safe characters only
@@ -72,6 +68,15 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
                return array( 'all' => $style );
        }
 
+       /**
+        * @param ResourceLoaderContext $context
+        * @return bool
+        */
+       public function isKnownEmpty( ResourceLoaderContext $context ) {
+               $styles = $this->getStyles( $context );
+               return isset( $styles['all'] ) && $styles['all'] === '';
+       }
+
        /**
         * @return string
         */
index d706d26..7872085 100644 (file)
@@ -25,6 +25,14 @@ a:hover, a:focus {
        text-decoration: underline;
 }
 
+a:lang(ar),
+a:lang(kk-arab),
+a:lang(mzn),
+a:lang(ps),
+a:lang(ur) {
+       text-decoration: none;
+}
+
 a.stub {
        color: #772233;
 }