private $mFollowPolicy = 'follow';
private $mVaryHeader = array(
'Accept-Encoding' => array( 'list-contains=gzip' ),
- 'Cookie' => null
);
/**
$this->mVaryHeader[$header] = array_unique( (array)$this->mVaryHeader[$header] );
}
+ /**
+ * Return a Vary: header on which to vary caches. Based on the keys of $mVaryHeader,
+ * such as Accept-Encoding or Cookie
+ *
+ * @return String
+ */
+ public function getVaryHeader() {
+ return 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) );
+ }
+
/**
* Get a complete X-Vary-Options header
*
$headers = array();
foreach( $this->mVaryHeader as $header => $option ) {
$newheader = $header;
- if( is_array( $option ) ) {
+ if ( is_array( $option ) && count( $option ) > 0 ) {
$newheader .= ';' . implode( ';', $option );
}
$headers[] = $newheader;
$response->header( "ETag: $this->mETag" );
}
+ $this->addVaryHeader( 'Cookie' );
$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 ) ) );
+ $response->header( $this->getVaryHeader() );
if ( $wgUseXVO ) {
# Add an X-Vary-Options header for Squid with Wikimedia patches
wfRunHooks( 'AjaxAddScript', array( &$this ) );
if( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
- $this->addModules( 'mediawiki.action.watch.ajax' );
+ $this->addModules( 'mediawiki.page.watch.ajax' );
}
if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array(), $loadCall = false ) {
global $wgResourceLoaderUseESI;
+ $modules = (array) $modules;
+
if ( !count( $modules ) ) {
return '';
}
if ( count( $modules ) > 1 ) {
// Remove duplicate module requests
- $modules = array_unique( (array) $modules );
+ $modules = array_unique( $modules );
// Sort module names so requests are more uniform
sort( $modules );
// Create keyed-by-group list of module objects from modules list
$groups = array();
$resourceLoader = $this->getResourceLoader();
- foreach ( (array) $modules as $name ) {
+ foreach ( $modules as $name ) {
$module = $resourceLoader->getModule( $name );
# Check that we're allowed to include this module on this page
if ( !$module
}
$links = '';
- foreach ( $groups as $group => $modules ) {
+ foreach ( $groups as $group => $grpModules ) {
// Special handling for user-specific groups
$user = null;
if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) {
$context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
// Extract modules that know they're empty
$emptyModules = array ();
- foreach ( $modules as $key => $module ) {
+ foreach ( $grpModules as $key => $module ) {
if ( $module->isKnownEmpty( $context ) ) {
$emptyModules[$key] = 'ready';
- unset( $modules[$key] );
+ unset( $grpModules[$key] );
}
}
// Inline empty modules: since they're empty, just mark them as 'ready'
}
// If there are no modules left, skip this group
- if ( $modules === array() ) {
+ if ( count( $grpModules ) === 0 ) {
continue;
}
if ( $group === 'private' ) {
if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
$links .= Html::inlineStyle(
- $resourceLoader->makeModuleResponse( $context, $modules )
+ $resourceLoader->makeModuleResponse( $context, $grpModules )
);
} else {
$links .= Html::inlineScript(
ResourceLoader::makeLoaderConditionalScript(
- $resourceLoader->makeModuleResponse( $context, $modules )
+ $resourceLoader->makeModuleResponse( $context, $grpModules )
)
);
}
if ( $group === 'user' ) {
// Get the maximum timestamp
$timestamp = 1;
- foreach ( $modules as $module ) {
+ foreach ( $grpModules as $module ) {
$timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
}
// Add a version parameter so cache will break when things change
}
$url = ResourceLoader::makeLoaderURL(
- array_keys( $modules ),
+ array_keys( $grpModules ),
$this->getLanguage()->getCode(),
$this->getSkin()->getSkinName(),
$user,