84 $this->mCacheDuration =
null;
86 $this->mConfig = $config ?: MediaWikiServices::getInstance()->getMainConfig();
88 $this->mDisabled =
false;
90 $this->mResponseCode = 200;
91 $this->mLastModified =
false;
92 $this->mContentType =
'application/x-wiki';
104 $this->mCacheDuration = $duration;
112 $this->mVary = $vary;
120 $this->mResponseCode = $code;
128 $this->mContentType =
$type;
135 $this->mDisabled =
true;
143 if ( !$this->mDisabled && $text ) {
144 $this->mText .= $text;
152 if ( !$this->mDisabled ) {
161 if ( $this->mResponseCode ) {
166 $n = intval( trim( $this->mResponseCode ) );
167 HttpStatus::header( $n );
170 header(
"Content-Type: " . $this->mContentType );
172 if ( $this->mLastModified ) {
173 header(
"Last-Modified: " . $this->mLastModified );
175 header(
"Last-Modified: " . gmdate(
"D, d M Y H:i:s" ) .
" GMT" );
178 if ( $this->mCacheDuration ) {
179 # If CDN caches are configured, tell them to cache the response,
180 # and tell the client to always check with the CDN. Otherwise,
181 # tell the client to use a cached copy, without a way to purge it.
182 if ( $this->mConfig->get(
'UseCdn' ) ) {
183 # Expect explicit purge of the proxy cache, but require end user agents
184 # to revalidate against the proxy on each visit.
185 header(
'Cache-Control: s-maxage=' . $this->mCacheDuration .
', must-revalidate, max-age=0' );
187 # Let the client do the caching. Cache is not purged.
188 header(
"Expires: " . gmdate(
"D, d M Y H:i:s", time() + $this->mCacheDuration ) .
" GMT" );
189 header(
"Cache-Control: s-maxage={$this->mCacheDuration}," .
190 "public,max-age={$this->mCacheDuration}" );
194 # always expired, always modified
195 header(
"Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
196 header(
"Cache-Control: no-cache, must-revalidate" );
197 header(
"Pragma: no-cache" );
200 if ( $this->mVary ) {
201 header(
"Vary: " . $this->mVary );
215 $fname =
'AjaxResponse::checkLastModified';
217 if ( !$timestamp || $timestamp ==
'19700101000000' ) {
218 wfDebug(
"$fname: CACHE DISABLED, NO TIMESTAMP",
'private' );
223 wfDebug(
"$fname: CACHE DISABLED",
'private' );
230 if ( !empty( $_SERVER[
'HTTP_IF_MODIFIED_SINCE'] ) ) {
231 # IE sends sizes after the date like this:
232 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
233 # this breaks strtotime().
234 $modsince = preg_replace(
'/;.*$/',
'', $_SERVER[
"HTTP_IF_MODIFIED_SINCE"] );
235 $modsinceTime = strtotime( $modsince );
236 $ismodsince =
wfTimestamp( TS_MW, $modsinceTime ?: 1 );
237 wfDebug(
"$fname: -- client send If-Modified-Since: $modsince",
'private' );
238 wfDebug(
"$fname: -- we might send Last-Modified : $lastmod",
'private' );
240 if ( ( $ismodsince >= $timestamp )
241 && $wgUser->validateCache( $ismodsince ) &&
244 ini_set(
'zlib.output_compression', 0 );
247 $this->mLastModified = $lastmod;
249 wfDebug(
"$fname: CACHED client: $ismodsince ; user: {$wgUser->getTouched()} ; " .
250 "page: $timestamp ; site $wgCacheEpoch",
'private' );
254 wfDebug(
"$fname: READY client: $ismodsince ; user: {$wgUser->getTouched()} ; " .
255 "page: $timestamp ; site $wgCacheEpoch",
'private' );
256 $this->mLastModified = $lastmod;
259 wfDebug(
"$fname: client did not send If-Modified-Since header",
'private' );
260 $this->mLastModified = $lastmod;
275 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
276 $mcvalue =
$cache->get( $mckey );
278 # Check to see if the value has been invalidated
279 if ( $touched <= $mcvalue[
'timestamp'] ) {
280 wfDebug(
"Got $mckey from cache" );
281 $this->mText = $mcvalue[
'value'];
285 wfDebug(
"$mckey has expired" );
298 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
302 'value' => $this->mText
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
$wgCachePages
Allow client-side caching of pages.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Handle responses for Ajax requests (send headers, print content, that sort of thing)
setVary( $vary)
Set the HTTP Vary header.
sendHeaders()
Construct the header and output it.
$mContentType
HTTP header Content-Type.
$mLastModified
Date for the HTTP header Last-modified.
loadFromMemcached( $mckey, $touched)
setResponseCode( $code)
Set the HTTP response code.
addText( $text)
Add content to the response.
setCacheDuration( $duration)
Set the number of seconds to get the response cached by a proxy.
$mResponseCode
HTTP response code.
__construct( $text=null, Config $config=null)
$mDisabled
Disables output.
$mText
Content of our HTTP response.
setContentType( $type)
Set the HTTP header Content-Type.
checkLastModified( $timestamp)
checkLastModified tells the client to use the client-cached response if possible.
$mCacheDuration
Number of seconds to get the response cached by a proxy.
storeInMemcached( $mckey, $expiry=86400)
while(( $__line=Maintenance::readconsole()) !==false) print
Interface for configuration instances.