(bug 38024) Skip styles for modules that don't have stylesheets
authorTimo Tijhof <ttijhof@wikimedia.org>
Thu, 28 Jun 2012 13:10:39 +0000 (15:10 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Thu, 28 Jun 2012 13:10:39 +0000 (15:10 +0200)
* <s>Best viewed in IE 4 and with a 800x600 resolution.<s>
  Best viewed with -w due to additional indention.

* Saves number of <style> tags inserted, which in turn is good for
  IE's stupid stylesheet limit (bug 31676).

* Also saves a little bit of bandwidth by outputting
  {} instead of {"":""}.

Change-Id: I436a6a1c64452fc60a58fd9a478a2ac2b1328211

RELEASE-NOTES-1.20
includes/resourceloader/ResourceLoader.php

index a838a37..709f2ea 100644 (file)
@@ -128,6 +128,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 27283) SqlBagOStuff breaks PostgreSQL transactions.
 * (bug 35727) mw.Api ajax() should put token parameter last.
 * (bug 37708) mw.Uri.clone() should make a deep copy.
+* (bug 38024) ResourceLoader should not create empty stylesheets for modules
+  that don't have stylesheets.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index b3d7e75..93dac7b 100644 (file)
@@ -713,23 +713,27 @@ class ResourceLoader {
                                // Styles
                                $styles = array();
                                if ( $context->shouldIncludeStyles() ) {
-                                       // If we are in debug mode without &only= set, we'll want to return an array of URLs
-                                       // See comment near shouldIncludeScripts() for more details
-                                       if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) {
-                                               $styles = $module->getStyleURLsForDebug( $context );
-                                       } else {
-                                               $styles = $module->getStyles( $context );
-                                               // Minify CSS before embedding in mw.loader.implement call
-                                               // (unless in debug mode)
-                                               if ( !$context->getDebug() ) {
-                                                       foreach ( $styles as $media => $style ) {
-                                                               if ( is_string( $style ) ) {
-                                                                       $styles[$media] = $this->filter( 'minify-css', $style );
+                                       // Don't create empty stylesheets like array( '' => '' ) for modules
+                                       // that don't *have* any stylesheets (bug 38024).
+                                       $stylePairs = $module->getStyles( $context );
+                                       if ( count ( $stylePairs ) ) {
+                                               // If we are in debug mode without &only= set, we'll want to return an array of URLs
+                                               // See comment near shouldIncludeScripts() for more details
+                                               if ( $context->getDebug() && !$context->getOnly() && $module->supportsURLLoading() ) {
+                                                       $styles = $module->getStyleURLsForDebug( $context );
+                                               } else {
+                                                       // Minify CSS before embedding in mw.loader.implement call
+                                                       // (unless in debug mode)
+                                                       if ( !$context->getDebug() ) {
+                                                               foreach ( $stylePairs as $media => $style ) {
+                                                                       if ( is_string( $style ) ) {
+                                                                               $stylePairs[$media] = $this->filter( 'minify-css', $style );
+                                                                       }
                                                                }
                                                        }
+                                                       // Combine styles into @media groups as one big string
+                                                       $styles = array( '' => self::makeCombinedStyles( $stylePairs ) );
                                                }
-                                               // Combine styles for all media types
-                                               $styles = array( '' => self::makeCombinedStyles( $styles ) );
                                        }
                                }