SpecialVersion: Handle Closures in $wgHooks nicer
[lhc/web/wiklou.git] / includes / HttpFunctions.php
index 8e05f59..fec8adc 100644 (file)
@@ -25,6 +25,8 @@
  * @defgroup HTTP HTTP
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * Various HTTP related functions
  * @ingroup HTTP
@@ -73,11 +75,14 @@ class Http {
                $req = MWHttpRequest::factory( $url, $options, $caller );
                $status = $req->execute();
 
-               $content = false;
                if ( $status->isOK() ) {
-                       $content = $req->getContent();
+                       return $req->getContent();
+               } else {
+                       $errors = $status->getErrorsByType( 'error' );
+                       $logger = LoggerFactory::getInstance( 'http' );
+                       $logger->warning( $status->getWikiText(), array( 'caller' => $caller ) );
+                       return false;
                }
-               return $content;
        }
 
        /**
@@ -252,7 +257,7 @@ class MWHttpRequest {
                $this->parsedUrl = wfParseUrl( $this->url );
 
                if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) {
-                       $this->status = Status::newFatal( 'http-invalid-url' );
+                       $this->status = Status::newFatal( 'http-invalid-url', $url );
                } else {
                        $this->status = Status::newGood( 100 ); // continue
                }
@@ -792,14 +797,14 @@ class CurlHttpRequest extends MWHttpRequest {
                }
 
                if ( $this->followRedirects && $this->canFollowRedirects() ) {
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) {
                                wfDebug( __METHOD__ . ": Couldn't set CURLOPT_FOLLOWLOCATION. " .
                                        "Probably safe_mode or open_basedir is set.\n" );
                                // Continue the processing. If it were in curl_setopt_array,
                                // processing would have halted on its entry
                        }
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                }
 
                if ( $this->profiler ) {
@@ -938,9 +943,9 @@ class PhpHttpRequest extends MWHttpRequest {
                }
                do {
                        $reqCount++;
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        $fh = fopen( $url, "r", false, $context );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
 
                        if ( !$fh ) {
                                break;