(bug 26497) printable=yes and handheld=yes request parameters were broken. Fixed...
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 7 Jan 2011 20:22:50 +0000 (20:22 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 7 Jan 2011 20:22:50 +0000 (20:22 +0000)
includes/OutputPage.php
includes/resourceloader/ResourceLoader.php

index 0d761a6..fd527d2 100644 (file)
@@ -2221,7 +2221,7 @@ class OutputPage {
         */
        protected function makeResourceLoaderLink( Skin $skin, $modules, $only, $useESI = false ) {
                global $wgUser, $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
-                       $wgResourceLoaderInlinePrivateModules;
+                       $wgResourceLoaderInlinePrivateModules, $wgRequest;
                // Lazy-load ResourceLoader
                // TODO: Should this be a static function of ResourceLoader instead?
                // TODO: Divide off modules starting with "user", and add the user parameter to them
@@ -2231,6 +2231,13 @@ class OutputPage {
                        'skin' => $skin->getSkinName(),
                        'only' => $only,
                );
+               // Propagate printable and handheld parameters if present
+               if ( $wgRequest->getBool( 'printable' ) ) {
+                       $query['printable'] = 1;
+               }
+               if ( $wgRequest->getBool( 'handheld' ) ) {
+                       $query['handheld'] = 1;
+               }
                
                if ( !count( $modules ) ) {
                        return '';
@@ -2615,7 +2622,7 @@ class OutputPage {
                }
 
                if( isset( $options['media'] ) ) {
-                       $media = $this->transformCssMedia( $options['media'] );
+                       $media = self::transformCssMedia( $options['media'] );
                        if( is_null( $media ) ) {
                                return '';
                        }
@@ -2647,7 +2654,7 @@ class OutputPage {
         * @param $media String: current value of the "media" attribute
         * @return String: modified value of the "media" attribute
         */
-       function transformCssMedia( $media ) {
+       public static function transformCssMedia( $media ) {
                global $wgRequest, $wgHandheldForIPhone;
 
                // Switch in on-screen display for media testing
index a3c1cd1..2ee7a6e 100644 (file)
@@ -558,7 +558,18 @@ class ResourceLoader {
        public static function makeCombinedStyles( array $styles ) {
                $out = '';
                foreach ( $styles as $media => $style ) {
-                       $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
+                       // Transform the media type based on request params and config
+                       // The way that this relies on $wgRequest to propagate request params is slightly evil
+                       $media = OutputPage::transformCssMedia( $media );
+                       
+                       if ( $media === null ) {
+                               // Skip
+                       } else if ( $media === '' || $media == 'all' ) {
+                               // Don't output invalid or frivolous @media statements
+                               $out .= "$style\n";
+                       } else {
+                               $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
+                       }
                }
                return $out;
        }