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;
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 ) ) );
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' ) ) ) )
{
// 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);
}
}
}
+ return $this->mMainLanguageCode;
}
+ else return $this->mPreferredVariant;
- return $this->mMainLanguageCode;
}
/**