Merge "(bug 44024) ObjectCache changes break XCache 3.x support"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 436e2f9..5b0f36c 100644 (file)
@@ -1435,6 +1435,9 @@ class OutputPage extends ContextSource {
         */
        public function addWikiText( $text, $linestart = true, $interface = true ) {
                $title = $this->getTitle(); // Work arround E_STRICT
+               if ( !$title ) {
+                       throw new MWException( 'Title is null' );
+               }
                $this->addWikiTextTitle( $text, $title, $linestart, /*tidy*/false, $interface );
        }
 
@@ -3512,11 +3515,15 @@ $templates
         * Transform "media" attribute based on request parameters
         *
         * @param $media String: current value of the "media" attribute
-        * @return String: modified value of the "media" attribute
+        * @return String: modified value of the "media" attribute, or null to skip
+        * this stylesheet
         */
        public static function transformCssMedia( $media ) {
                global $wgRequest, $wgHandheldForIPhone;
 
+               // http://www.w3.org/TR/css3-mediaqueries/#syntax
+               $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i';
+
                // Switch in on-screen display for media testing
                $switches = array(
                        'printable' => 'print',
@@ -3526,8 +3533,20 @@ $templates
                        if( $wgRequest->getBool( $switch ) ) {
                                if( $media == $targetMedia ) {
                                        $media = '';
-                               } elseif( $media == 'screen' ) {
-                                       return null;
+                               } elseif( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
+                                       // This regex will not attempt to understand a comma-separated media_query_list
+                                       //
+                                       // Example supported values for $media: 'screen', 'only screen', 'screen and (min-width: 982px)' ),
+                                       // Example NOT supported value for $media: '3d-glasses, screen, print and resolution > 90dpi'
+                                       //
+                                       // If it's a print request, we never want any kind of screen styesheets
+                                       // If it's a handheld request (currently the only other choice with a switch),
+                                       // we don't want simple 'screen' but we might want screen queries that
+                                       // have a max-width or something, so we'll pass all others on and let the
+                                       // client do the query.
+                                       if( $targetMedia == 'print' || $media == 'screen' ) {
+                                               return null;
+                                       }
                                }
                        }
                }