follow-up r59522. follow Tim's suggestion to serve same vary and XVO headers for...
authorPhilip Tzou <philip@users.mediawiki.org>
Mon, 21 Dec 2009 18:55:42 +0000 (18:55 +0000)
committerPhilip Tzou <philip@users.mediawiki.org>
Mon, 21 Dec 2009 18:55:42 +0000 (18:55 +0000)
includes/OutputPage.php
includes/Wiki.php
languages/LanguageConverter.php

index d6b72c7..b7f06b3 100644 (file)
@@ -844,6 +844,29 @@ class OutputPage {
                return $xvo;
        }
 
+       /** bug 21672: Add Accept-Language to Vary and XVO headers
+               if there's no 'variant' parameter existed in $_GET.
+               
+               For example:
+                /w/index.php?title=Main_page should always be served; but
+                /w/index.php?title=Main_page&variant=zh-cn should never be served.
+               
+               patched by Liangent and Philip */
+       function addAcceptLanguage() {
+               global $wgContLang;
+               if( !isset( $_GET['variant'] ) && $wgContLang->hasVariants() ) {
+                       $variants = $wgContLang->getVariants();
+                       $aloption = array();
+                       foreach ( $variants as $variant ) {
+                               if( $variant === $wgContLang->getCode() )
+                                       continue;
+                               else
+                                       $aloption[] = "string-contains=$variant";
+                       }
+                       $this->addVaryHeader( 'Accept-Language', $aloption );
+               }
+       }
+
        public function sendCacheControl() {
                global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
 
@@ -851,6 +874,8 @@ class OutputPage {
                if ($wgUseETag && $this->mETag)
                        $response->header("ETag: $this->mETag");
 
+               $this->addAcceptLanguage();
+
                # 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( ', ', array_keys( $this->mVaryHeader ) ) );
index 0a6c263..bbe2cb2 100644 (file)
@@ -206,11 +206,11 @@ class MediaWiki {
                                wfProfileOut( __METHOD__ );
                                throw new ErrorPageError( 'badtitle', 'badtitletext' );
                        }
-               // Redirect loops, no title in URL, $wgUsePathInfo URLs
+               // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
                } else if( $action == 'view' && !$request->wasPosted() &&
                        ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
                          // No valid variant in URL (if the main-language has multi-variants), to ensure
-                         // the Accept-Language would only be added to XVO when a 301 redirection happened
+                         // anonymous access would always be redirect to a URL with 'variant' parameter
                          ( !isset($this->GET['variant']) && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
                        !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
                {
index 3f23f3b..e53933a 100644 (file)
@@ -186,19 +186,6 @@ class LanguageConverter {
                        // variable in case this is called before the user's
                        // preference is loaded
                        if( $fromHeader && array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
-
-                               // bug 21672: Add Accept-Language to Vary and XVO headers
-                               // to help Squid to determine user's perferred local language
-                               // ONLY add Accept-Language when a variant has been found out
-                               // patched by Liangent
-                               $aloption = array();
-                               foreach ( $this->mVariants as $variant ) {
-                                       if( $variant === $this->mMainLanguageCode )
-                                               continue;
-                                       $aloption[] = "string-contains=$variant";
-                               }
-                               $wgOut->addVaryHeader( 'Accept-Language', $aloption );
-
                                $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
                                // explode by comma
                                $result = explode(',', $acceptLanguage);
@@ -243,9 +230,10 @@ class LanguageConverter {
                                        }
                                }
                        }
+                       return $this->mMainLanguageCode;
                }
+               else return $this->mPreferredVariant;
 
-               return $this->mMainLanguageCode;
        }
        
        /**