follow-up r59522, r59523, r59527, r59529, r59530.
authorPhilip Tzou <philip@users.mediawiki.org>
Sun, 29 Nov 2009 06:47:51 +0000 (06:47 +0000)
committerPhilip Tzou <philip@users.mediawiki.org>
Sun, 29 Nov 2009 06:47:51 +0000 (06:47 +0000)
1. Only use Accept-Language when 301 redirection happens. It won't call the parser, but it is the most case we need to ensure it uncacheable.
2. Merge addXVOHeader with addVaryHeader.

includes/OutputPage.php
includes/Title.php
includes/Wiki.php
languages/LanguageConverter.php

index 503466d..2f69ab8 100644 (file)
@@ -50,8 +50,8 @@ class OutputPage {
 
        private $mIndexPolicy = 'index';
        private $mFollowPolicy = 'follow';
-       private $mVaryHeader = array( 'Accept-Encoding', 'Cookie' );
-       private $mXVOHeader = array( 'Accept-Encoding' => array('list-contains=gzip') );
+       private $mVaryHeader = array( 'Accept-Encoding' => array('list-contains=gzip'),
+                                                                 'Cookie' => null );
 
        /**
         * Constructor
@@ -807,24 +807,19 @@ class OutputPage {
                return false;
        }
 
-       public function addXVOHeader( $header, $option = null ) {
-               if ( !array_key_exists( $header, $this->mXVOHeader ) ) {
-                       $this->mXVOHeader[$header] = $option;
+       public function addVaryHeader( $header, $option = null ) {
+               if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
+                       $this->mVaryHeader[$header] = $option;
                }
                elseif( is_array( $option ) ) {
-                       if( is_array( $this->mXVOHeader[$header] ) ) {
-                               $this->mXVOHeader[$header] = array_merge( $this->mXVOHeader[$header], $option );
+                       if( is_array( $this->mVaryHeader[$header] ) ) {
+                               $this->mVaryHeader[$header] = array_merge( $this->mVaryHeader[$header], $option );
                        }
                        else {
-                               $this->mXVOHeader[$header] = $option;
+                               $this->mVaryHeader[$header] = $option;
                        }
                }
-       }
-
-       public function addVaryHeader( $header ) {
-               if ( !in_array( $header, $this->mVaryHeader ) ) {
-                       $this->mVaryHeader[] = $header;
-               }
+               $this->mVaryHeader[$header] = array_unique( $this->mVaryHeader[$header] );
        }
 
        /** Get a complete X-Vary-Options header */
@@ -835,10 +830,10 @@ class OutputPage {
                foreach ( $cvCookies as $cookieName ) {
                        $cookiesOption[] = 'string-contains=' . $cookieName;
                }
-               $this->addXVOHeader( 'Cookie', $cookiesOption );
+               $this->addVaryHeader( 'Cookie', $cookiesOption );
                
                $headers = array();
-               foreach( $this->mXVOHeader as $header => $option ) {
+               foreach( $this->mVaryHeader as $header => $option ) {
                        $newheader = $header;
                        if( is_array( $option ) )
                                $newheader .= ';' . implode( ';', $option );
@@ -858,7 +853,7 @@ class OutputPage {
 
                # don't serve compressed data to clients who can't handle it
                # maintain different caches for logged-in users and non-logged in ones
-               $response->header( 'Vary: ' . join( ', ', $this->mVaryHeader ) );
+               $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
 
                if ( $wgUseXVO ) {
                        # Add an X-Vary-Options header for Squid with Wikimedia patches
index be871f3..939d92e 100644 (file)
@@ -733,7 +733,7 @@ class Title {
 
                $interwiki = Interwiki::fetch( $this->mInterwiki );
                if ( !$interwiki ) {
-                       $url = $this->getLocalUrl( $query, $variant );
+                       $url = $this->getLocalURL( $query, $variant );
 
                        // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
                        // Correct fix would be to move the prepending elsewhere.
index c7d80c2..c2dfb5f 100644 (file)
@@ -197,7 +197,9 @@ class MediaWiki {
         */
        function handleSpecialCases( &$title, &$output, $request ) {
                wfProfileIn( __METHOD__ );
+               global $wgContLang, $wgUser;
                $action = $this->getVal( 'Action' );
+               $perferred = $wgContLang->getPreferredVariant( false );
                // Invalid titles
                if( is_null($title) || $title->getDBkey() == '' ) {
                        $title = SpecialPage::getTitleFor( 'Badtitle' );
@@ -222,7 +224,9 @@ class MediaWiki {
                        }
                // Redirect loops, no title in URL, $wgUsePathInfo URLs
                } else if( $action == 'view' && !$request->wasPosted() &&
-                       ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
+                       ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
+                         ( !isset($this->GET['variant']) && $perferred != $wgContLang->getCode() &&
+                           $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
                        !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
                {
                        $targetUrl = $title->getFullURL();
index 8dbd8b1..7136bfe 100644 (file)
@@ -240,11 +240,8 @@ class LanguageConverter {
                                // ONLY add Accept-Language when a variant has been found out
                                // thanks to Liangent's help
                                if( $ret_language !== $this->mMainLanguageCode ) {
-                                       global $wgOut, $wgUseXVO;
-                                       $wgOut->addVaryHeader( 'Accept-Language' );
-                                       if( $wgUseXVO ) {
-                                               $wgOut->addXVOHeader( 'Accept-Language', array($ret_language) );
-                                       }
+                                       global $wgOut;
+                                       $wgOut->addVaryHeader( 'Accept-Language', array('string-contains=' .$ret_language) );
                                }
                                return $ret_language;
                        }