Add array type hints to minor methods in the Html class
[lhc/web/wiklou.git] / includes / WebRequest.php
index e931f28..054eceb 100644 (file)
@@ -50,6 +50,12 @@ class WebRequest {
         */
        private $ip;
 
+       /**
+        * The timestamp of the start of the request, with microsecond precision.
+        * @var float
+        */
+       protected $requestTime;
+
        /**
         * Cached URL protocol
         * @var string
@@ -57,9 +63,8 @@ class WebRequest {
        protected $protocol;
 
        public function __construct() {
-               if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
-                       throw new MWException( "MediaWiki does not function when magic quotes are enabled." );
-               }
+               $this->requestTime = isset( $_SERVER['REQUEST_TIME_FLOAT'] )
+                       ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true );
 
                // POST overrides GET data
                // We don't use $_REQUEST here to avoid interference from cookies...
@@ -207,15 +212,26 @@ class WebRequest {
         * @return array
         */
        public static function detectProtocol() {
-               if ( ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ||
+               if ( ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) ||
                        ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
-                       $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) ) {
+                       $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) ) {
                        return 'https';
                } else {
                        return 'http';
                }
        }
 
+       /**
+        * Get the number of seconds to have elapsed since request start,
+        * in fractional seconds, with microsecond resolution.
+        *
+        * @return float
+        * @since 1.25
+        */
+       public function getElapsedTime() {
+               return microtime( true ) - $this->requestTime;
+       }
+
        /**
         * Get the current URL protocol (http or https)
         * @return string
@@ -289,7 +305,7 @@ class WebRequest {
                        }
                } else {
                        global $wgContLang;
-                       $data = isset( $wgContLang ) ? $wgContLang->normalize( $data ) : UtfNormal::cleanUp( $data );
+                       $data = isset( $wgContLang ) ? $wgContLang->normalize( $data ) : UtfNormal\Validator::cleanUp( $data );
                }
                return $data;
        }
@@ -1274,6 +1290,8 @@ class FauxRequest extends WebRequest {
        public function __construct( $data = array(), $wasPosted = false,
                $session = null, $protocol = 'http'
        ) {
+               $this->requestTime = microtime( true );
+
                if ( is_array( $data ) ) {
                        $this->data = $data;
                } else {
@@ -1497,4 +1515,8 @@ class DerivativeRequest extends FauxRequest {
        public function getProtocol() {
                return $this->base->getProtocol();
        }
+
+       public function getElapsedTime() {
+               return $this->base->getElapsedTime();
+       }
 }