Fixing dump tests for non-wikitext in NS_MAIN.
[lhc/web/wiklou.git] / includes / WebRequest.php
index 91bd923..80fb81a 100644 (file)
@@ -498,8 +498,7 @@ class WebRequest {
        public function getCheck( $name ) {
                # Checkboxes and buttons are only present when clicked
                # Presence connotes truth, abscense false
-               $val = $this->getVal( $name, null );
-               return isset( $val );
+               return $this->getVal( $name, null ) !== null;
        }
 
        /**
@@ -564,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).
@@ -574,7 +582,7 @@ class WebRequest {
         * @return Boolean
         */
        public function wasPosted() {
-               return isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] == 'POST';
+               return $this->getMethod() == 'POST';
        }
 
        /**
@@ -612,6 +620,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() {
@@ -899,6 +908,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() ) {
@@ -1048,9 +1058,10 @@ HTML;
        /**
         * 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() {
@@ -1230,6 +1241,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 ) ) {
@@ -1278,6 +1290,10 @@ class FauxRequest extends WebRequest {
                }
        }
 
+       public function getMethod() {
+               return $this->wasPosted ? 'POST' : 'GET';
+       }
+
        /**
         * @return bool
         */