Go to the documentation of this file.
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 ) );
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.
183 if ( $this->mConfig->get(
'UseSquid' ) ) {
184 # Expect explicit purge of the proxy cache, but require end user agents
185 # to revalidate against the proxy on each visit.
186 # Surrogate-Control controls our CDN, Cache-Control downstream caches
188 if ( $this->mConfig->get(
'UseESI' ) ) {
189 header(
'Surrogate-Control: max-age=' . $this->mCacheDuration .
', content="ESI/1.0"' );
190 header(
'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
192 header(
'Cache-Control: s-maxage=' . $this->mCacheDuration .
', must-revalidate, max-age=0' );
196 # Let the client do the caching. Cache is not purged.
197 header(
"Expires: " . gmdate(
"D, d M Y H:i:s", time() + $this->mCacheDuration ) .
" GMT" );
198 header(
"Cache-Control: s-maxage={$this->mCacheDuration}," .
199 "public,max-age={$this->mCacheDuration}" );
203 # always expired, always modified
204 header(
"Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
205 header(
"Cache-Control: no-cache, must-revalidate" );
206 header(
"Pragma: no-cache" );
209 if ( $this->mVary ) {
210 header(
"Vary: " . $this->mVary );
224 $fname =
'AjaxResponse::checkLastModified';
226 if ( !$timestamp || $timestamp ==
'19700101000000' ) {
227 wfDebug(
"$fname: CACHE DISABLED, NO TIMESTAMP",
'private' );
232 wfDebug(
"$fname: CACHE DISABLED",
'private' );
239 if ( !empty( $_SERVER[
'HTTP_IF_MODIFIED_SINCE'] ) ) {
240 # IE sends sizes after the date like this:
241 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
242 # this breaks strtotime().
243 $modsince = preg_replace(
'/;.*$/',
'', $_SERVER[
"HTTP_IF_MODIFIED_SINCE"] );
244 $modsinceTime = strtotime( $modsince );
245 $ismodsince =
wfTimestamp( TS_MW, $modsinceTime ?: 1 );
246 wfDebug(
"$fname: -- client send If-Modified-Since: $modsince",
'private' );
247 wfDebug(
"$fname: -- we might send Last-Modified : $lastmod",
'private' );
249 if ( ( $ismodsince >= $timestamp )
250 && $wgUser->validateCache( $ismodsince ) &&
253 ini_set(
'zlib.output_compression', 0 );
256 $this->mLastModified = $lastmod;
258 wfDebug(
"$fname: CACHED client: $ismodsince ; user: {$wgUser->getTouched()} ; " .
259 "page: $timestamp ; site $wgCacheEpoch",
'private' );
263 wfDebug(
"$fname: READY client: $ismodsince ; user: {$wgUser->getTouched()} ; " .
264 "page: $timestamp ; site $wgCacheEpoch",
'private' );
265 $this->mLastModified = $lastmod;
268 wfDebug(
"$fname: client did not send If-Modified-Since header",
'private' );
269 $this->mLastModified = $lastmod;
286 # Check to see if the value has been invalidated
287 if ( $touched <= $mcvalue[
'timestamp'] ) {
288 wfDebug(
"Got $mckey from cache" );
289 $this->mText = $mcvalue[
'value'];
293 wfDebug(
"$mckey has expired" );
309 'value' => $this->mText
$mText
Content of our HTTP response.
setResponseCode( $code)
Set the HTTP response code.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
checkLastModified( $timestamp)
checkLastModified tells the client to use the client-cached response if possible.
$mContentType
HTTP header Content-Type.
loadFromMemcached( $mckey, $touched)
$mResponseCode
HTTP response code.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
setContentType( $type)
Set the HTTP header Content-Type.
Interface for configuration instances.
__construct( $text=null, Config $config=null)
setVary( $vary)
Set the HTTP Vary header.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
addText( $text)
Add content to the response.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
$wgCachePages
Allow client-side caching of pages.
Handle responses for Ajax requests (send headers, print content, that sort of thing)
storeInMemcached( $mckey, $expiry=86400)
$mLastModified
Date for the HTTP header Last-modified.
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
static header( $code)
Output an HTTP status code header.
static getMainWANInstance()
Get the main WAN cache object.
setCacheDuration( $duration)
Set the number of seconds to get the response cached by a proxy.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
sendHeaders()
Construct the header and output it.
$mDisabled
Disables output.
$mCacheDuration
Number of seconds to get the response cached by a proxy.