r59541 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59540‎ | r59541 | r59542 >
Date:06:47, 29 November 2009
Author:philip
Status:deferred (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -50,8 +50,8 @@
5151
5252 private $mIndexPolicy = 'index';
5353 private $mFollowPolicy = 'follow';
54 - private $mVaryHeader = array( 'Accept-Encoding', 'Cookie' );
55 - private $mXVOHeader = array( 'Accept-Encoding' => array('list-contains=gzip') );
 54+ private $mVaryHeader = array( 'Accept-Encoding' => array('list-contains=gzip'),
 55+ 'Cookie' => null );
5656
5757 /**
5858 * Constructor
@@ -807,26 +807,21 @@
808808 return false;
809809 }
810810
811 - public function addXVOHeader( $header, $option = null ) {
812 - if ( !array_key_exists( $header, $this->mXVOHeader ) ) {
813 - $this->mXVOHeader[$header] = $option;
 811+ public function addVaryHeader( $header, $option = null ) {
 812+ if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
 813+ $this->mVaryHeader[$header] = $option;
814814 }
815815 elseif( is_array( $option ) ) {
816 - if( is_array( $this->mXVOHeader[$header] ) ) {
817 - $this->mXVOHeader[$header] = array_merge( $this->mXVOHeader[$header], $option );
 816+ if( is_array( $this->mVaryHeader[$header] ) ) {
 817+ $this->mVaryHeader[$header] = array_merge( $this->mVaryHeader[$header], $option );
818818 }
819819 else {
820 - $this->mXVOHeader[$header] = $option;
 820+ $this->mVaryHeader[$header] = $option;
821821 }
822822 }
 823+ $this->mVaryHeader[$header] = array_unique( $this->mVaryHeader[$header] );
823824 }
824825
825 - public function addVaryHeader( $header ) {
826 - if ( !in_array( $header, $this->mVaryHeader ) ) {
827 - $this->mVaryHeader[] = $header;
828 - }
829 - }
830 -
831826 /** Get a complete X-Vary-Options header */
832827 public function getXVO() {
833828 $cvCookies = $this->getCacheVaryCookies();
@@ -835,10 +830,10 @@
836831 foreach ( $cvCookies as $cookieName ) {
837832 $cookiesOption[] = 'string-contains=' . $cookieName;
838833 }
839 - $this->addXVOHeader( 'Cookie', $cookiesOption );
 834+ $this->addVaryHeader( 'Cookie', $cookiesOption );
840835
841836 $headers = array();
842 - foreach( $this->mXVOHeader as $header => $option ) {
 837+ foreach( $this->mVaryHeader as $header => $option ) {
843838 $newheader = $header;
844839 if( is_array( $option ) )
845840 $newheader .= ';' . implode( ';', $option );
@@ -858,7 +853,7 @@
859854
860855 # don't serve compressed data to clients who can't handle it
861856 # maintain different caches for logged-in users and non-logged in ones
862 - $response->header( 'Vary: ' . join( ', ', $this->mVaryHeader ) );
 857+ $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
863858
864859 if ( $wgUseXVO ) {
865860 # Add an X-Vary-Options header for Squid with Wikimedia patches
Index: trunk/phase3/includes/Wiki.php
@@ -197,7 +197,9 @@
198198 */
199199 function handleSpecialCases( &$title, &$output, $request ) {
200200 wfProfileIn( __METHOD__ );
 201+ global $wgContLang, $wgUser;
201202 $action = $this->getVal( 'Action' );
 203+ $perferred = $wgContLang->getPreferredVariant( false );
202204 // Invalid titles
203205 if( is_null($title) || $title->getDBkey() == '' ) {
204206 $title = SpecialPage::getTitleFor( 'Badtitle' );
@@ -222,7 +224,9 @@
223225 }
224226 // Redirect loops, no title in URL, $wgUsePathInfo URLs
225227 } else if( $action == 'view' && !$request->wasPosted() &&
226 - ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
 228+ ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
 229+ ( !isset($this->GET['variant']) && $perferred != $wgContLang->getCode() &&
 230+ $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
227231 !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
228232 {
229233 $targetUrl = $title->getFullURL();
Index: trunk/phase3/includes/Title.php
@@ -733,7 +733,7 @@
734734
735735 $interwiki = Interwiki::fetch( $this->mInterwiki );
736736 if ( !$interwiki ) {
737 - $url = $this->getLocalUrl( $query, $variant );
 737+ $url = $this->getLocalURL( $query, $variant );
738738
739739 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
740740 // Correct fix would be to move the prepending elsewhere.
Index: trunk/phase3/languages/LanguageConverter.php
@@ -240,11 +240,8 @@
241241 // ONLY add Accept-Language when a variant has been found out
242242 // thanks to Liangent's help
243243 if( $ret_language !== $this->mMainLanguageCode ) {
244 - global $wgOut, $wgUseXVO;
245 - $wgOut->addVaryHeader( 'Accept-Language' );
246 - if( $wgUseXVO ) {
247 - $wgOut->addXVOHeader( 'Accept-Language', array($ret_language) );
248 - }
 244+ global $wgOut;
 245+ $wgOut->addVaryHeader( 'Accept-Language', array('string-contains=' .$ret_language) );
249246 }
250247 return $ret_language;
251248 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r59544follow-up r59541. Fix the problem reported on [[Special:Code/MediaWiki/59541#...philip10:53, 29 November 2009
r59735follow-up r59522 and r59541. To make the condition when we'll use Accept-Lang...philip15:47, 4 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59522bug 21672: Add Accept-Language to Vary and XVO headers to help Squid to deter...philip19:13, 28 November 2009
r59523follow-up r59522, add missing credit.philip19:15, 28 November 2009
r59527follow-up r59522. ONLY add Accept-Language when a valid variant has been foun...philip20:00, 28 November 2009
r59529follow-up r59522. "string-contains" added.philip20:13, 28 November 2009
r59530follow-up r59522, r59529. Just include the current variant.philip20:20, 28 November 2009

Comments

#Comment by Liangent (talk | contribs)   06:59, 29 November 2009

I think $wgOut->addVaryHeader( 'Accept-Language', array('string-contains=' .$ret_language) ); is incorrect.

Consider this situation:

Squid has no cached version. User A requests: Accept-Language: en Squid asks MediaWiki; MediaWiki returns without Accept-Language in X-Vary-Options or Vary.

 (since there's no variant en, $ret_language == $this->mMainLanguageCode)

User B requests: Accept-Language: zh-tw Squid returns cached version.

Status & tagging log