r60272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60271‎ | r60272 | r60273 >
Date:18:55, 21 December 2009
Author:philip
Status:resolved (Comments)
Tags:
Comment:
follow-up r59522. follow Tim's suggestion to serve same vary and XVO headers for the same URL. Now the vary headers should be consistent. Feel free to test it.
Modified paths:
  • /trunk/phase3/includes/OutputPage.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
@@ -844,6 +844,29 @@
845845 return $xvo;
846846 }
847847
 848+ /** bug 21672: Add Accept-Language to Vary and XVO headers
 849+ if there's no 'variant' parameter existed in $_GET.
 850+
 851+ For example:
 852+ /w/index.php?title=Main_page should always be served; but
 853+ /w/index.php?title=Main_page&variant=zh-cn should never be served.
 854+
 855+ patched by Liangent and Philip */
 856+ function addAcceptLanguage() {
 857+ global $wgContLang;
 858+ if( !isset( $_GET['variant'] ) && $wgContLang->hasVariants() ) {
 859+ $variants = $wgContLang->getVariants();
 860+ $aloption = array();
 861+ foreach ( $variants as $variant ) {
 862+ if( $variant === $wgContLang->getCode() )
 863+ continue;
 864+ else
 865+ $aloption[] = "string-contains=$variant";
 866+ }
 867+ $this->addVaryHeader( 'Accept-Language', $aloption );
 868+ }
 869+ }
 870+
848871 public function sendCacheControl() {
849872 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
850873
@@ -851,6 +874,8 @@
852875 if ($wgUseETag && $this->mETag)
853876 $response->header("ETag: $this->mETag");
854877
 878+ $this->addAcceptLanguage();
 879+
855880 # don't serve compressed data to clients who can't handle it
856881 # maintain different caches for logged-in users and non-logged in ones
857882 $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
Index: trunk/phase3/includes/Wiki.php
@@ -206,11 +206,11 @@
207207 wfProfileOut( __METHOD__ );
208208 throw new ErrorPageError( 'badtitle', 'badtitletext' );
209209 }
210 - // Redirect loops, no title in URL, $wgUsePathInfo URLs
 210+ // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
211211 } else if( $action == 'view' && !$request->wasPosted() &&
212212 ( ( !isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title'] ) ||
213213 // No valid variant in URL (if the main-language has multi-variants), to ensure
214 - // the Accept-Language would only be added to XVO when a 301 redirection happened
 214+ // anonymous access would always be redirect to a URL with 'variant' parameter
215215 ( !isset($this->GET['variant']) && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) ) &&
216216 !count( array_diff( array_keys( $this->GET ), array( 'action', 'title' ) ) ) )
217217 {
Index: trunk/phase3/languages/LanguageConverter.php
@@ -186,19 +186,6 @@
187187 // variable in case this is called before the user's
188188 // preference is loaded
189189 if( $fromHeader && array_key_exists( 'HTTP_ACCEPT_LANGUAGE', $_SERVER ) ) {
190 -
191 - // bug 21672: Add Accept-Language to Vary and XVO headers
192 - // to help Squid to determine user's perferred local language
193 - // ONLY add Accept-Language when a variant has been found out
194 - // patched by Liangent
195 - $aloption = array();
196 - foreach ( $this->mVariants as $variant ) {
197 - if( $variant === $this->mMainLanguageCode )
198 - continue;
199 - $aloption[] = "string-contains=$variant";
200 - }
201 - $wgOut->addVaryHeader( 'Accept-Language', $aloption );
202 -
203190 $acceptLanguage = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
204191 // explode by comma
205192 $result = explode(',', $acceptLanguage);
@@ -243,9 +230,10 @@
244231 }
245232 }
246233 }
 234+ return $this->mMainLanguageCode;
247235 }
 236+ else return $this->mPreferredVariant;
248237
249 - return $this->mMainLanguageCode;
250238 }
251239
252240 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r60292follow-up r60272. replace $_GET with $wgRequest->getText.philip14:12, 22 December 2009
r60293follow-up r60272 and r60292. replace getText with getCheck.philip14:36, 22 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

Comments

#Comment by 😂 (talk | contribs)   20:49, 21 December 2009

Do not use $_GET, $_POST, etc etc. Use the appropriate WebRequest method.

#Comment by PhiLiP (talk | contribs)   14:13, 22 December 2009

fixed on r60292.

Status & tagging log