Merge "[FileBackend] Added optional callback parameter to concatenate()."
[lhc/web/wiklou.git] / includes / WebRequest.php
index 26b943c..e251ac5 100644 (file)
@@ -380,10 +380,9 @@ class WebRequest {
                return $ret;
        }
 
-       
        /**
         * Unset an arbitrary value from our get/post data.
-        *
+        *
         * @param $key String: key name to use
         * @return Mixed: old value if one was present, null otherwise
         */
@@ -563,6 +562,15 @@ class WebRequest {
                return $_GET;
         }
 
+       /**
+        * Get the HTTP method used for this request.
+        *
+        * @return String
+        */
+       public function getMethod() {
+               return isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : 'GET';
+       }
+
        /**
         * Returns true if the present request was reached by a POST operation,
         * false otherwise (GET, HEAD, or command-line).
@@ -573,7 +581,7 @@ class WebRequest {
         * @return Boolean
         */
        public function wasPosted() {
-               return isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST';
+               return $this->getMethod() == 'POST';
        }
 
        /**
@@ -611,6 +619,7 @@ class WebRequest {
         * Return the path and query string portion of the request URI.
         * This will be suitable for use as a relative link in HTML output.
         *
+        * @throws MWException
         * @return String
         */
        public function getRequestURL() {
@@ -898,6 +907,7 @@ class WebRequest {
         * false if an error message has been shown and the request should be aborted.
         *
         * @param $extWhitelist array
+        * @throws HttpError
         * @return bool
         */
        public function checkUrlExtension( $extWhitelist = array() ) {
@@ -1037,19 +1047,26 @@ HTML;
         * @return String
         */
        protected function getRawIP() {
-               if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
-                       return IP::canonicalize( $_SERVER['REMOTE_ADDR'] );
-               } else {
+               if ( !isset( $_SERVER['REMOTE_ADDR'] ) ) {
                        return null;
                }
+
+               if ( is_array( $_SERVER['REMOTE_ADDR'] ) || strpos( $_SERVER['REMOTE_ADDR'], ',' ) !== false ) {
+                       throw new MWException( __METHOD__ . " : Could not determine the remote IP address due to multiple values." );
+               } else {
+                       $ipchain = $_SERVER['REMOTE_ADDR'];
+               }
+
+               return IP::canonicalize( $ipchain );
        }
 
        /**
         * Work out the IP address based on various globals
         * For trusted proxies, use the XFF client IP (first of the chain)
-        * 
+        *
         * @since 1.19
         *
+        * @throws MWException
         * @return string
         */
        public function getIP() {
@@ -1229,6 +1246,7 @@ class FauxRequest extends WebRequest {
         *   fake GET/POST values
         * @param $wasPosted Bool: whether to treat the data as POST
         * @param $session Mixed: session array or null
+        * @throws MWException
         */
        public function __construct( $data = array(), $wasPosted = false, $session = null ) {
                if( is_array( $data ) ) {
@@ -1277,6 +1295,10 @@ class FauxRequest extends WebRequest {
                }
        }
 
+       public function getMethod() {
+               return $this->wasPosted ? 'POST' : 'GET';
+       }
+
        /**
         * @return bool
         */