'epoch' => $config->get( 'CacheEpoch' )
];
if ( $config->get( 'UseSquid' ) ) {
- // T46570: the core page itself may not change, but resources might
- $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, time() - $config->get( 'SquidMaxage' ) );
+ $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
+ time(),
+ $config->get( 'SquidMaxage' )
+ ) );
}
Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this ] );
return true;
}
+ /**
+ * @param int $reqTime Time of request (eg. now)
+ * @param int $maxAge Cache TTL in seconds
+ * @return int Timestamp
+ */
+ private function getCdnCacheEpoch( $reqTime, $maxAge ) {
+ // Ensure Last-Modified is never more than (wgSquidMaxage) in the past,
+ // because even if the wiki page content hasn't changed since, static
+ // resources may have changed (skin HTML, interface messages, urls, etc.)
+ // and must roll-over in a timely manner (T46570)
+ return $reqTime - $maxAge;
+ }
+
/**
* Override the last modified timestamp
*
] );
}
+ public static function provideCdnCacheEpoch() {
+ $base = [
+ 'pageTime' => '2011-04-01T12:00:00+00:00',
+ 'maxAge' => 24 * 3600,
+ ];
+ return [
+ 'after 1s' => [ $base + [
+ 'reqTime' => '2011-04-01T12:00:01+00:00',
+ 'expect' => '2011-04-01T12:00:00+00:00',
+ ] ],
+ 'after 23h' => [ $base + [
+ 'reqTime' => '2011-04-02T11:00:00+00:00',
+ 'expect' => '2011-04-01T12:00:00+00:00',
+ ] ],
+ 'after 24h and a bit' => [ $base + [
+ 'reqTime' => '2011-04-02T12:34:56+00:00',
+ 'expect' => '2011-04-01T12:34:56+00:00',
+ ] ],
+ 'after a year' => [ $base + [
+ 'reqTime' => '2012-05-06T00:12:07+00:00',
+ 'expect' => '2012-05-05T00:12:07+00:00',
+ ] ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideCdnCacheEpoch
+ */
+ public function testCdnCacheEpoch( $params ) {
+ $out = TestingAccessWrapper::newFromObject( $this->newInstance() );
+ $reqTime = strtotime( $params['reqTime'] );
+ $pageTime = strtotime( $params['pageTime'] );
+ $actual = max( $pageTime, $out->getCdnCacheEpoch( $reqTime, $params['maxAge'] ) );
+
+ $this->assertEquals(
+ $params['expect'],
+ gmdate( DateTime::ATOM, $actual ),
+ 'cdn epoch'
+ );
+ }
+
/**
* Tests screen requests, without either query parameter set
* @covers OutputPage::transformCssMedia