add some abstraction for web responses, so far minimal and not that used, requires...
authorDomas Mituzas <midom@users.mediawiki.org>
Sat, 12 Aug 2006 23:03:53 +0000 (23:03 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Sat, 12 Aug 2006 23:03:53 +0000 (23:03 +0000)
includes/AutoLoader.php
includes/WebRequest.php
includes/WebResponse.php [new file with mode: 0644]

index e6cc99c..24ac7cd 100644 (file)
@@ -213,6 +213,7 @@ function __autoload($className) {
                'EmailNotification' => 'includes/UserMailer.php',
                'WatchedItem' => 'includes/WatchedItem.php',
                'WebRequest' => 'includes/WebRequest.php',
+               'WebResponse' => 'includes/WebResponse.php',
                'FauxRequest' => 'includes/WebRequest.php',
                'MediaWiki' => 'includes/Wiki.php',
                'WikiError' => 'includes/WikiError.php',
index 4031e36..6b8e944 100644 (file)
@@ -44,6 +44,8 @@ class WebRequest {
                                substr( $_SERVER['PATH_INFO'], 1 );
                }
        }
+       
+       private $_response;
 
        /**
         * Recursively strips slashes from the given array;
@@ -437,6 +439,19 @@ class WebRequest {
                wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" );
                return $name;
        }
+       
+       /**
+        * Return a handle to WebResponse style object, for setting cookies, 
+        * headers and other stuff, for Request being worked on.
+        */
+       function response() {
+               /* Lazy initialization of response object for this request */
+               if (!is_object($this->_response)) {
+                       $this->_response = new WebResponse;
+               } 
+               return $this->_response;
+       }
+       
 }
 
 /**
diff --git a/includes/WebResponse.php b/includes/WebResponse.php
new file mode 100644 (file)
index 0000000..e159152
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+/* 
+ * Allow programs to request this object from WebRequest::response() and handle all outputting (or lack of outputting) via it.
+ */
+
+class WebResponse {
+       function header($string, $replace=true) {
+               header($string,$replace);
+       }
+       
+       function setcookie($name, $value, $expire) {
+               global $wgCookiePath, $wgCookieDomain, $wgCookieSecure;
+               setcookie($name,$value,$expire, $wgCookiePath, $wgCookieDomain, $wgCookieSecure);
+       }
+}
+
+?>
\ No newline at end of file