API: (bug 19004) Add support for tags. Patch by Matthew Britton
[lhc/web/wiklou.git] / includes / AjaxResponse.php
index c3c15ad..26b6f44 100644 (file)
@@ -1,18 +1,41 @@
 <?php
+/**
+ * @file
+ * @ingroup Ajax
+ */
+
 if( !defined( 'MEDIAWIKI' ) ) {
        die( 1 );
 }
 
-/** @todo document */
+/**
+ * Handle responses for Ajax requests (send headers, print
+ * content, that sort of thing)
+ * 
+ * @ingroup Ajax
+ */
 class AjaxResponse {
-       var $mCacheDuration;
-       var $mVary;
 
-       var $mDisabled;
-       var $mText;
-       var $mResponseCode;
-       var $mLastModified;
-       var $mContentType;
+       /** Number of seconds to get the response cached by a proxy */
+       private $mCacheDuration;
+
+       /** HTTP header Content-Type */
+       private $mContentType;
+
+       /** Disables output. Can be set by calling $AjaxResponse->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;
@@ -22,7 +45,7 @@ class AjaxResponse {
                $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 );
@@ -49,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;
 
@@ -80,7 +106,7 @@ class AjaxResponse {
 
                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.
 
@@ -152,6 +178,7 @@ class AjaxResponse {
                        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 ) {
+                               ini_set('zlib.output_compression', 0);
                                $this->setResponseCode( "304 Not Modified" );
                                $this->disable();
                                $this->mLastModified = $lastmod;
@@ -201,4 +228,3 @@ class AjaxResponse {
                return true;
        }
 }
-?>