summaryrefslogtreecommitdiff
path: root/includes/AjaxResponse.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2007-05-16 20:58:53 +0000
committerPierre Schmitz <pierre@archlinux.de>2007-05-16 20:58:53 +0000
commitcecb985bee3bdd252e1b8dc0bd500b37cd52be01 (patch)
tree17266aa237742640aabee7856f0202317a45d540 /includes/AjaxResponse.php
parent0bac06c301f2a83edb0236e4c2434da16848d549 (diff)
Aktualisierung auf MediaWiki 1.10.0
Plugins angepasst und verbessert kleine Korrekturen am Design
Diffstat (limited to 'includes/AjaxResponse.php')
-rw-r--r--includes/AjaxResponse.php70
1 files changed, 37 insertions, 33 deletions
diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php
index a59c73bb..cb4af1b5 100644
--- a/includes/AjaxResponse.php
+++ b/includes/AjaxResponse.php
@@ -1,28 +1,32 @@
<?php
+if( !defined( 'MEDIAWIKI' ) ) {
+ die( 1 );
+}
-if( !defined( 'MEDIAWIKI' ) )
- die( 1 );
-
+/**
+ * @todo document
+ * @addtogroup Ajax
+ */
class AjaxResponse {
var $mCacheDuration;
var $mVary;
-
+
var $mDisabled;
var $mText;
var $mResponseCode;
var $mLastModified;
var $mContentType;
- function AjaxResponse( $text = NULL ) {
+ function __construct( $text = NULL ) {
$this->mCacheDuration = NULL;
$this->mVary = NULL;
-
+
$this->mDisabled = false;
$this->mText = '';
$this->mResponseCode = '200 OK';
$this->mLastModified = false;
$this->mContentType= 'text/html; charset=utf-8';
-
+
if ( $text ) {
$this->addText( $text );
}
@@ -39,15 +43,15 @@ class AjaxResponse {
function setResponseCode( $code ) {
$this->mResponseCode = $code;
}
-
+
function setContentType( $type ) {
$this->mContentType = $type;
}
-
+
function disable() {
$this->mDisabled = true;
}
-
+
function addText( $text ) {
if ( ! $this->mDisabled && $text ) {
$this->mText .= $text;
@@ -59,62 +63,62 @@ class AjaxResponse {
print $this->mText;
}
}
-
+
function sendHeaders() {
global $wgUseSquid, $wgUseESI;
-
+
if ( $this->mResponseCode ) {
$n = preg_replace( '/^ *(\d+)/', '\1', $this->mResponseCode );
header( "Status: " . $this->mResponseCode, true, (int)$n );
}
-
+
header ("Content-Type: " . $this->mContentType );
-
+
if ( $this->mLastModified ) {
header ("Last-Modified: " . $this->mLastModified );
}
else {
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
}
-
+
if ( $this->mCacheDuration ) {
-
+
# If squid caches are configured, tell them to cache the response,
# and tell the client to always check with the squid. Otherwise,
# tell the client to use a cached copy, without a way to purge it.
-
+
if( $wgUseSquid ) {
-
+
# Expect explicite purge of the proxy cache, but require end user agents
# to revalidate against the proxy on each visit.
# Surrogate-Control controls our Squid, Cache-Control downstream caches
-
+
if ( $wgUseESI ) {
header( 'Surrogate-Control: max-age='.$this->mCacheDuration.', content="ESI/1.0"');
header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
} else {
header( 'Cache-Control: s-maxage='.$this->mCacheDuration.', must-revalidate, max-age=0' );
}
-
+
} else {
-
+
# Let the client do the caching. Cache is not purged.
header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->mCacheDuration ) . " GMT");
header ("Cache-Control: s-max-age={$this->mCacheDuration},public,max-age={$this->mCacheDuration}");
}
-
+
} else {
# always expired, always modified
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
}
-
+
if ( $this->mVary ) {
header ( "Vary: " . $this->mVary );
}
}
-
+
/**
* checkLastModified tells the client to use the client-cached response if
* possible. If sucessful, the AjaxResponse is disabled so that
@@ -154,9 +158,9 @@ class AjaxResponse {
$this->setResponseCode( "304 Not Modified" );
$this->disable();
$this->mLastModified = $lastmod;
-
+
wfDebug( "$fname: CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
-
+
return true;
} else {
wfDebug( "$fname: READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp ; site $wgCacheEpoch\n", false );
@@ -167,11 +171,11 @@ class AjaxResponse {
$this->mLastModified = $lastmod;
}
}
-
+
function loadFromMemcached( $mckey, $touched ) {
global $wgMemc;
if ( !$touched ) return false;
-
+
$mcvalue = $wgMemc->get( $mckey );
if ( $mcvalue ) {
# Check to see if the value has been invalidated
@@ -183,20 +187,20 @@ class AjaxResponse {
wfDebug( "$mckey has expired\n" );
}
}
-
+
return false;
}
-
+
function storeInMemcached( $mckey, $expiry = 86400 ) {
global $wgMemc;
-
- $wgMemc->set( $mckey,
+
+ $wgMemc->set( $mckey,
array(
'timestamp' => wfTimestampNow(),
'value' => $this->mText
), $expiry
);
-
+
return true;
}
}