Prettify upload form for RTL wikis
[lhc/web/wiklou.git] / includes / WebRequest.php
index 5ba1203..a7dd12b 100644 (file)
@@ -42,8 +42,17 @@ if ( !function_exists( '__autoload' ) ) {
  *
  */
 class WebRequest {
+       var $data = array();
+       
        function __construct() {
+               /// @fixme This preemptive de-quoting can interfere with other web libraries
+               ///        and increases our memory footprint. It would be cleaner to do on
+               ///        demand; but currently we have no wrapper for $_SERVER etc.
                $this->checkMagicQuotes();
+               
+               // POST overrides GET data
+               // We don't use $_REQUEST here to avoid interference from cookies...
+               $this->data = array_merge( $_GET, $_POST );
        }
        
        /**
@@ -70,11 +79,22 @@ class WebRequest {
                                if( $a ) {
                                        $path = $a['path'];
                                        
+                                       global $wgScript;
+                                       if( $path == $wgScript ) {
+                                               // Script inside a rewrite path?
+                                               // Abort to keep from breaking...
+                                               return;
+                                       }
+                                       // Raw PATH_INFO style
+                                       $matches = $this->extractTitle( $path, "$wgScript/$1" );
+                                       
                                        global $wgArticlePath;
-                                       $matches = $this->extractTitle( $path, $wgArticlePath );
+                                       if( !$matches && $wgArticlePath ) {
+                                               $matches = $this->extractTitle( $path, $wgArticlePath );
+                                       }
                                        
                                        global $wgActionPaths;
-                                       if( !$matches && $wgActionPaths) {
+                                       if( !$matches && $wgActionPaths ) {
                                                $matches = $this->extractTitle( $path, $wgActionPaths, 'action' );
                                        }
                                        
@@ -99,7 +119,7 @@ class WebRequest {
                                $matches['title'] = substr( $_SERVER['PATH_INFO'], 1 );
                        }
                        foreach( $matches as $key => $val) {
-                               $_GET[$key] = $_REQUEST[$key] = $val;
+                               $this->data[$key] = $_GET[$key] = $_REQUEST[$key] = $val;
                        }
                }
        }
@@ -122,7 +142,7 @@ class WebRequest {
                        if( substr( $path, 0, $baseLen ) == $base ) {
                                $raw = substr( $path, $baseLen );
                                if( $raw !== '' ) {
-                                       $matches = array( 'title' => urldecode( $raw ) );
+                                       $matches = array( 'title' => rawurldecode( $raw ) );
                                        if( $key ) {
                                                $matches[$key] = $keyValue;
                                        }
@@ -225,7 +245,7 @@ class WebRequest {
         * @return string
         */
        function getVal( $name, $default = NULL ) {
-               $val = $this->getGPCVal( $_REQUEST, $name, $default );
+               $val = $this->getGPCVal( $this->data, $name, $default );
                if( is_array( $val ) ) {
                        $val = $default;
                }
@@ -246,7 +266,7 @@ class WebRequest {
         * @return array
         */
        function getArray( $name, $default = NULL ) {
-               $val = $this->getGPCVal( $_REQUEST, $name, $default );
+               $val = $this->getGPCVal( $this->data, $name, $default );
                if( is_null( $val ) ) {
                        return null;
                } else {
@@ -351,7 +371,7 @@ class WebRequest {
        function getValues() {
                $names = func_get_args();
                if ( count( $names ) == 0 ) {
-                       $names = array_keys( $_REQUEST );
+                       $names = array_keys( $this->data );
                }
 
                $retVal = array();
@@ -576,9 +596,13 @@ class WebRequest {
  *
  */
 class FauxRequest extends WebRequest {
-       var $data = null;
        var $wasPosted = false;
 
+       /**
+        * @param array $data Array of *non*-urlencoded key => value pairs, the
+        *   fake GET/POST values
+        * @param bool $wasPosted Whether to treat the data as POST
+        */
        function FauxRequest( $data, $wasPosted = false ) {
                if( is_array( $data ) ) {
                        $this->data = $data;
@@ -588,13 +612,9 @@ class FauxRequest extends WebRequest {
                $this->wasPosted = $wasPosted;
        }
 
-       function getVal( $name, $default = NULL ) {
-               return $this->getGPCVal( $this->data, $name, $default );
-       }
-
        function getText( $name, $default = '' ) {
                # Override; don't recode since we're using internal data
-               return $this->getVal( $name, $default );
+               return (string)$this->getVal( $name, $default );
        }
 
        function getValues() {
@@ -619,4 +639,4 @@ class FauxRequest extends WebRequest {
 
 }
 
-?>
+