(bug 32412) TOC links on [[Special:EditWatchlist]] now points to the fieldset
[lhc/web/wiklou.git] / includes / HttpFunctions.php
index 47dc682..f25a806 100644 (file)
@@ -29,6 +29,8 @@ class Http {
         *    - followRedirects     Whether to follow redirects (defaults to false).
         *                                  Note: this should only be used when the target URL is trusted,
         *                                  to avoid attacks on intranet services accessible by HTTP.
+        *    - userAgent           A user agent, if you want to override the default
+        *                          MediaWiki/$wgVersion
         * @return Mixed: (bool)false on failure or a string on success
         */
        public static function request( $method, $url, $options = array() ) {
@@ -40,6 +42,9 @@ class Http {
                }
 
                $req = MWHttpRequest::factory( $url, $options );
+               if( isset( $options['userAgent'] ) ) {
+                       $req->setUserAgent( $options['userAgent'] );
+               }
                $status = $req->execute();
 
                if ( $status->isOK() ) {
@@ -53,6 +58,9 @@ class Http {
         * Simple wrapper for Http::request( 'GET' )
         * @see Http::request()
         *
+        * @param $url
+        * @param $timeout string
+        * @param $options array
         * @return string
         */
        public static function get( $url, $timeout = 'default', $options = array() ) {
@@ -64,6 +72,8 @@ class Http {
         * Simple wrapper for Http::request( 'POST' )
         * @see Http::request()
         *
+        * @param $url
+        * @param $options array
         * @return string
         */
        public static function post( $url, $options = array() ) {
@@ -124,6 +134,8 @@ class Http {
         * protocols, because we only want protocols that both cURL
         * and php support.
         *
+        * file:// should not be allowed here for security purpose (r67684)
+        *
         * @fixme this is wildly inaccurate and fails to actually check most stuff
         *
         * @param $uri Mixed: URI to check for validity
@@ -221,6 +233,7 @@ class MWHttpRequest {
         * Generate a new request object
         * @param $url String: url to use
         * @param $options Array: (optional) extra params to pass (see Http::request())
+        * @return \CurlHttpRequest|\PhpHttpRequest
         * @see MWHttpRequest::__construct
         */
        public static function factory( $url, $options = null ) {
@@ -295,6 +308,7 @@ class MWHttpRequest {
 
        /**
         * Set the user agent
+        * @param $UA string
         */
        public function setUserAgent( $UA ) {
                $this->setHeader( 'User-Agent', $UA );
@@ -302,6 +316,8 @@ class MWHttpRequest {
 
        /**
         * Set an arbitrary header
+        * @param $name
+        * @param $value
         */
        public function setHeader( $name, $value ) {
                // I feel like I should normalize the case here...
@@ -310,6 +326,7 @@ class MWHttpRequest {
 
        /**
         * Get an array of the headers
+        * @return array
         */
        public function getHeaderList() {
                $list = array();
@@ -540,6 +557,9 @@ class MWHttpRequest {
         * cookies.      Used internally after a request to parse the
         * Set-Cookie headers.
         * @see Cookie::set
+        * @param $name
+        * @param $value null
+        * @param $attr null
         */
        public function setCookie( $name, $value = null, $attr = null ) {
                if ( !$this->cookieJar ) {
@@ -614,6 +634,7 @@ class MWHttpRequest {
        /**
         * Returns true if the backend can follow redirects. Overridden by the
         * child classes.
+        * @return bool
         */
        public function canFollowRedirects() {
                return true;
@@ -634,6 +655,11 @@ class CurlHttpRequest extends MWHttpRequest {
        protected $curlOptions = array();
        protected $headerText = "";
 
+       /**
+        * @param $fh
+        * @param $content
+        * @return int
+        */
        protected function readHeader( $fh, $content ) {
                $this->headerText .= $content;
                return strlen( $content );
@@ -725,6 +751,9 @@ class CurlHttpRequest extends MWHttpRequest {
                return $this->status;
        }
 
+       /**
+        * @return bool
+        */
        public function canFollowRedirects() {
                if ( strval( ini_get( 'open_basedir' ) ) !== '' || wfIniGetBool( 'safe_mode' ) ) {
                        wfDebug( "Cannot follow redirects in safe mode\n" );
@@ -741,6 +770,11 @@ class CurlHttpRequest extends MWHttpRequest {
 }
 
 class PhpHttpRequest extends MWHttpRequest {
+
+       /**
+        * @param $url string
+        * @return string
+        */
        protected function urlToTcp( $url ) {
                $parsedUrl = parse_url( $url );
 
@@ -828,7 +862,7 @@ class PhpHttpRequest extends MWHttpRequest {
                        # Check security of URL
                        $url = $this->getResponseHeader( "Location" );
 
-                       if ( substr( $url, 0, 7 ) !== 'http://' ) {
+                       if ( !Http::isValidURI( $url ) ) {
                                wfDebug( __METHOD__ . ": insecure redirection\n" );
                                break;
                        }