(bug 28868) Include the number of pages in the default getLongDesc for multipaged...
[lhc/web/wiklou.git] / includes / WebResponse.php
index 09d3738..a0f7776 100644 (file)
@@ -1,4 +1,10 @@
 <?php
+/**
+ * Classes used to send headers and cookies back to the user
+ *
+ * @file
+ */
+
 /**
  * Allow programs to request this object from WebRequest::response()
  * and handle all outputting (or lack of outputting) via it.
@@ -6,7 +12,7 @@
  */
 class WebResponse {
 
-       /** 
+       /**
         * Output a HTTP header, wrapper for PHP's
         * header()
         * @param $string String: header to output
@@ -27,7 +33,7 @@ class WebResponse {
                if ( $expire == 0 ) {
                        $expire = time() + $wgCookieExpiration;
                }
-               $httpOnlySafe = wfHttpOnlySafe();
+               $httpOnlySafe = wfHttpOnlySafe() && $wgCookieHttpOnly;
                wfDebugLog( 'cookie',
                        'setcookie: "' . implode( '", "',
                                array(
@@ -37,24 +43,41 @@ class WebResponse {
                                        $wgCookiePath,
                                        $wgCookieDomain,
                                        $wgCookieSecure,
-                                       $httpOnlySafe && $wgCookieHttpOnly ) ) . '"' );
-               if( $httpOnlySafe && isset( $wgCookieHttpOnly ) ) {
-                       setcookie( $wgCookiePrefix . $name,
-                               $value,
-                               $expire,
-                               $wgCookiePath,
-                               $wgCookieDomain,
-                               $wgCookieSecure,
-                               $wgCookieHttpOnly );
-               } else {
-                       // setcookie() fails on PHP 5.1 if you give it future-compat paramters.
-                       // stab stab!
-                       setcookie( $wgCookiePrefix . $name,
-                               $value,
-                               $expire,
-                               $wgCookiePath,
-                               $wgCookieDomain,
-                               $wgCookieSecure );
+                                       $httpOnlySafe ) ) . '"' );
+               setcookie( $wgCookiePrefix . $name,
+                       $value,
+                       $expire,
+                       $wgCookiePath,
+                       $wgCookieDomain,
+                       $wgCookieSecure,
+                       $httpOnlySafe );
+       }
+}
+
+
+class FauxResponse extends WebResponse {
+       private $headers;
+       private $cookies;
+
+       public function header($string, $replace=true) {
+               list($key, $val) = explode(":", $string, 2);
+
+               if($replace || !isset($this->headers[$key])) {
+                       $this->headers[$key] = $val;
+               }
+       }
+
+       public function getheader($key) {
+               return $this->headers[$key];
+       }
+
+       public function setcookie( $name, $value, $expire = 0 ) {
+               $this->cookies[$name] = $value;
+       }
+
+       public function getcookie( $name )  {
+               if ( isset($this->cookies[$name]) ) {
+                       return $this->cookies[$name];
                }
        }
 }