X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FAjaxResponse.php;h=8fa08539a6ef651ca201b1fc4608e518e559d507;hb=af7be3b1b7b2f9e1aa32007857a21df3c6a0cfc0;hp=a59c73bb14a5f3ed56a375856d967c5c9a39e384;hpb=ae8554c45b2b5766d4ad59f9a7b12c58198d2142;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index a59c73bb14..8fa08539a6 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -1,28 +1,45 @@ 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,82 +56,85 @@ class AjaxResponse { function setResponseCode( $code ) { $this->mResponseCode = $code; } - + function setContentType( $type ) { $this->mContentType = $type; } - + function disable() { $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; - + 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 +174,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 +187,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,21 +203,21 @@ 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; } } -?> +