Added WebRequest::getMethod() to get the HTTP method of the request.
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 7 Aug 2012 06:33:41 +0000 (08:33 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Tue, 7 Aug 2012 16:28:43 +0000 (18:28 +0200)
This is to replace the usage of $_SERVER['REQUEST_METHOD'].

Change-Id: I45084254c5452b00b0665df78628cfd214e39cab

includes/Setup.php
includes/WebRequest.php
includes/debug/Debug.php

index dedfca9..518ef6d 100644 (file)
@@ -449,7 +449,7 @@ if ( $wgCommandLineMode ) {
        # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
        $wgRequest = new WebRequest;
 
-       $debug = "\n\nStart request {$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}\n";
+       $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
 
        if ( $wgDebugPrintHttpHeaders ) {
                $debug .= "HTTP HEADERS:\n";
index 26b943c..2cc6338 100644 (file)
@@ -563,6 +563,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 +582,7 @@ class WebRequest {
         * @return Boolean
         */
        public function wasPosted() {
-               return isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST';
+               return $this->getMethod() == 'POST';
        }
 
        /**
@@ -1277,6 +1286,10 @@ class FauxRequest extends WebRequest {
                }
        }
 
+       public function getMethod() {
+               return $this->wasPosted ? 'POST' : 'GET';
+       }
+
        /**
         * @return bool
         */
index 0c0052f..5330a4b 100644 (file)
@@ -352,7 +352,7 @@ class MWDebug {
                        'debugLog' => self::$debug,
                        'queries' => self::$query,
                        'request' => array(
-                               'method' => $_SERVER['REQUEST_METHOD'],
+                               'method' => $request->getMethod(),
                                'url' => $request->getRequestURL(),
                                'headers' => $request->getAllHeaders(),
                                'params' => $request->getValues(),