From 303b2b745db1115a0ea2dfe4e18a0dc426705e17 Mon Sep 17 00:00:00 2001 From: Philip Tzou Date: Sun, 29 Nov 2009 06:47:51 +0000 Subject: [PATCH] follow-up r59522, r59523, r59527, r59529, r59530. 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 | 29 ++++++++++++----------------- includes/Title.php | 2 +- includes/Wiki.php | 6 +++++- languages/LanguageConverter.php | 7 ++----- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 503466d4c4..2f69ab8dad 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 diff --git a/includes/Title.php b/includes/Title.php index be871f3ea4..939d92e2b6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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. diff --git a/includes/Wiki.php b/includes/Wiki.php index c7d80c27c6..c2dfb5f6ce 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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(); diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 8dbd8b1855..7136bfe1df 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -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; } -- 2.20.1