X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FAjaxResponse.php;h=f74956669a3d2dbd520c06e6994eb09c4c642827;hb=9d55bedd71195f850a58fa0641f0802213d6779b;hp=a814e57d4d6bba95c6573532cf52b04f82966760;hpb=5fef2333d43faed0571878e848d6c40ade2c9810;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index a814e57d4d..f74956669a 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -1,30 +1,51 @@ disable() */ + private $mDisabled; + + /** Date for the HTTP header Last-modified */ + private $mLastModified; + + /** HTTP response code */ + private $mResponseCode; + + /** HTTP Vary header */ + private $mVary; + + /** Content of our HTTP response */ + private $mText; - function __construct( $text = NULL ) { - $this->mCacheDuration = NULL; - $this->mVary = 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'; + $this->mContentType = 'application/x-wiki'; if ( $text ) { $this->addText( $text ); @@ -51,18 +72,21 @@ class AjaxResponse { $this->mDisabled = true; } + /** Add content to the response */ function addText( $text ) { if ( ! $this->mDisabled && $text ) { $this->mText .= $text; } } + /** Output text */ function printText() { if ( ! $this->mDisabled ) { print $this->mText; } } + /** Construct the header and output it */ function sendHeaders() { global $wgUseSquid, $wgUseESI; @@ -71,46 +95,46 @@ class AjaxResponse { header( "Status: " . $this->mResponseCode, true, (int)$n ); } - header ("Content-Type: " . $this->mContentType ); + header ( "Content-Type: " . $this->mContentType ); if ( $this->mLastModified ) { - header ("Last-Modified: " . $this->mLastModified ); + header ( "Last-Modified: " . $this->mLastModified ); } else { - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + 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, + # 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 ) { + 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( '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' ); + 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}"); + 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 + 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 ) { @@ -132,11 +156,11 @@ class AjaxResponse { wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" ); return; } - if( !$wgCachePages ) { + if ( !$wgCachePages ) { wfDebug( "$fname: CACHE DISABLED\n", false ); return; } - if( $wgUser->getOption( 'nocache' ) ) { + if ( $wgUser->getOption( 'nocache' ) ) { wfDebug( "$fname: USER DISABLED CACHE\n", false ); return; } @@ -144,7 +168,7 @@ class AjaxResponse { $timestamp = wfTimestamp( TS_MW, $timestamp ); $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->mTouched, $wgCacheEpoch ) ); - if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { + if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { # IE sends sizes after the date like this: # Wed, 20 Aug 2003 06:51:19 GMT; length=5202 # this breaks strtotime(). @@ -153,7 +177,8 @@ class AjaxResponse { $ismodsince = wfTimestamp( TS_MW, $modsinceTime ? $modsinceTime : 1 ); wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false ); wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false ); - if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) { + if ( ( $ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) { + ini_set( 'zlib.output_compression', 0 ); $this->setResponseCode( "304 Not Modified" ); $this->disable(); $this->mLastModified = $lastmod; @@ -203,4 +228,3 @@ class AjaxResponse { return true; } } -?>