make it a bit cleared: users should not modify the file
[lhc/web/wiklou.git] / includes / WebRequest.php
index 31195eb..cd21edc 100644 (file)
@@ -101,15 +101,15 @@ class WebRequest {
        /**
         * Fetch a value from the given array or return $default if it's not set.
         *
-        * @param array &$arr
+        * @param array $arr
         * @param string $name
         * @param mixed $default
         * @return mixed
         * @private
         */
-       function getGPCVal( &$arr, $name, $default ) {
+       function getGPCVal( $arr, $name, $default ) {
                if( isset( $arr[$name] ) ) {
-                       global $wgServer, $wgContLang;
+                       global $wgContLang;
                        $data = $arr[$name];
                        if( isset( $_GET[$name] ) && !is_array( $data ) ) {
                                # Check for alternate/legacy character encoding.
@@ -172,7 +172,7 @@ class WebRequest {
         * @return int
         */
        function getInt( $name, $default = 0 ) {
-               return IntVal( $this->getVal( $name, $default ) );
+               return intval( $this->getVal( $name, $default ) );
        }
        
        /**
@@ -185,7 +185,7 @@ class WebRequest {
        function getIntOrNull( $name ) {
                $val = $this->getVal( $name );
                return is_numeric( $val )
-                       ? IntVal( $val )
+                       ? intval( $val )
                        : null;
        }
        
@@ -281,7 +281,13 @@ class WebRequest {
         * @return string
         */
        function getRequestURL() {
-               return $_SERVER['REQUEST_URI'];
+               $base = $_SERVER['REQUEST_URI'];
+               if( $base{0} == '/' ) {
+                       return $base;
+               } else {
+                       // We may get paths with a host prepended; strip it.
+                       return preg_replace( '!^[^:]+://[^/]+/!', '/', $base );
+               }
        }
        
        /**
@@ -371,6 +377,18 @@ class WebRequest {
                return $_FILES[$key]['size'];
        }
        
+       /**
+        * Return the upload error or 0
+        * @param string $key
+        * @return integer
+        */
+       function getUploadError( $key ) {
+               if( !isset( $_FILES[$key] ) || !isset( $_FILES[$key]['error'] ) ) {
+                       return 0/*UPLOAD_ERR_OK*/;
+               }
+               return $_FILES[$key]['error'];
+       }
+       
        /**
         * Return the original filename of the uploaded file, as reported by
         * the submitting user agent. HTML-style character entities are