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
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 */
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 );
# 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
*/
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' );
}
// 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();
// 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;
}