From fb80a53b1ba3c0c5dc9b01b2a058b716a046461d Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 7 Jan 2011 20:22:50 +0000 Subject: [PATCH] (bug 26497) printable=yes and handheld=yes request parameters were broken. Fixed this in a bit of an ugly way, by propagating these parameters to load.php and running OutputPage::transformCssMedia() on it there. This revision also fixes the fact that ResourceLoader ignored $wgHandheldForIPhone, and no longer wraps styles in @media all { } because it's useless and breaks @import (which can't be used inside @media ; this is bug 26478) --- includes/OutputPage.php | 13 ++++++++++--- includes/resourceloader/ResourceLoader.php | 13 ++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 0d761a64d2..fd527d257d 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index a3c1cd13b1..2ee7a6e0de 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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; } -- 2.20.1