r79839 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79838‎ | r79839 | r79840 >
Date:20:22, 7 January 2011
Author:catrope
Status:ok
Tags:
Comment:
(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)
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2221,7 +2221,7 @@
22222222 */
22232223 protected function makeResourceLoaderLink( Skin $skin, $modules, $only, $useESI = false ) {
22242224 global $wgUser, $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
2225 - $wgResourceLoaderInlinePrivateModules;
 2225+ $wgResourceLoaderInlinePrivateModules, $wgRequest;
22262226 // Lazy-load ResourceLoader
22272227 // TODO: Should this be a static function of ResourceLoader instead?
22282228 // TODO: Divide off modules starting with "user", and add the user parameter to them
@@ -2231,6 +2231,13 @@
22322232 'skin' => $skin->getSkinName(),
22332233 'only' => $only,
22342234 );
 2235+ // Propagate printable and handheld parameters if present
 2236+ if ( $wgRequest->getBool( 'printable' ) ) {
 2237+ $query['printable'] = 1;
 2238+ }
 2239+ if ( $wgRequest->getBool( 'handheld' ) ) {
 2240+ $query['handheld'] = 1;
 2241+ }
22352242
22362243 if ( !count( $modules ) ) {
22372244 return '';
@@ -2615,7 +2622,7 @@
26162623 }
26172624
26182625 if( isset( $options['media'] ) ) {
2619 - $media = $this->transformCssMedia( $options['media'] );
 2626+ $media = self::transformCssMedia( $options['media'] );
26202627 if( is_null( $media ) ) {
26212628 return '';
26222629 }
@@ -2647,7 +2654,7 @@
26482655 * @param $media String: current value of the "media" attribute
26492656 * @return String: modified value of the "media" attribute
26502657 */
2651 - function transformCssMedia( $media ) {
 2658+ public static function transformCssMedia( $media ) {
26522659 global $wgRequest, $wgHandheldForIPhone;
26532660
26542661 // Switch in on-screen display for media testing
Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -558,7 +558,18 @@
559559 public static function makeCombinedStyles( array $styles ) {
560560 $out = '';
561561 foreach ( $styles as $media => $style ) {
562 - $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
 562+ // Transform the media type based on request params and config
 563+ // The way that this relies on $wgRequest to propagate request params is slightly evil
 564+ $media = OutputPage::transformCssMedia( $media );
 565+
 566+ if ( $media === null ) {
 567+ // Skip
 568+ } else if ( $media === '' || $media == 'all' ) {
 569+ // Don't output invalid or frivolous @media statements
 570+ $out .= "$style\n";
 571+ } else {
 572+ $out .= "@media $media {\n" . str_replace( "\n", "\n\t", "\t" . $style ) . "\n}\n";
 573+ }
563574 }
564575 return $out;
565576 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r810091.17: MFT r79839, r79862, r79863, r79895, r80003, r80005, r80164, r80692catrope00:20, 26 January 2011

Status & tagging log