From b9b85843572bf283f48285001e276ba7e61b63f6 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Feb 2009 13:37:51 +0100 Subject: updated to MediaWiki 1.14.0 --- includes/HttpFunctions.php | 86 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 22 deletions(-) (limited to 'includes/HttpFunctions.php') diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 555a79b7..269d45ff 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -1,24 +1,48 @@ getFullURL() ); } + + if ( is_array( $curlOptions ) ) { + foreach( $curlOptions as $option => $value ) { + curl_setopt( $c, $option, $value ); + } + } ob_start(); curl_exec( $c ); @@ -55,20 +84,24 @@ class Http { ob_end_clean(); # Don't return the text of error messages, return false on error - if ( curl_getinfo( $c, CURLINFO_HTTP_CODE ) != 200 ) { + $retcode = curl_getinfo( $c, CURLINFO_HTTP_CODE ); + if ( $retcode != 200 ) { + wfDebug( __METHOD__ . ": HTTP return code $retcode\n" ); $text = false; } # Don't return truncated output - if ( curl_errno( $c ) != CURLE_OK ) { + $errno = curl_errno( $c ); + if ( $errno != CURLE_OK ) { + $errstr = curl_error( $c ); + wfDebug( __METHOD__ . ": CURL error code $errno: $errstr\n" ); $text = false; } curl_close( $c ); } else { # Otherwise use file_get_contents... - # This may take 3 minutes to time out, and doesn't have local fetch capabilities + # This doesn't have local fetch capabilities... - global $wgVersion; - $headers = array( "User-Agent: MediaWiki/$wgVersion" ); + $headers = array( "User-Agent: " . self :: userAgent() ); if( strcasecmp( $method, 'post' ) == 0 ) { // Required for HTTP 1.0 POSTs $headers[] = "Content-Length: 0"; @@ -76,20 +109,21 @@ class Http { $opts = array( 'http' => array( 'method' => $method, - 'header' => implode( "\r\n", $headers ) ) ); + 'header' => implode( "\r\n", $headers ), + 'timeout' => $timeout ) ); $ctx = stream_context_create($opts); - $url_fopen = ini_set( 'allow_url_fopen', 1 ); $text = file_get_contents( $url, false, $ctx ); - ini_set( 'allow_url_fopen', $url_fopen ); } return $text; } /** * Check if the URL can be served by localhost + * @param $url string Full url to check + * @return bool */ - static function isLocalURL( $url ) { + public static function isLocalURL( $url ) { global $wgCommandLineMode, $wgConf; if ( $wgCommandLineMode ) { return false; @@ -117,4 +151,12 @@ class Http { } return false; } + + /** + * Return a standard user-agent we can use for external requests. + */ + public static function userAgent() { + global $wgVersion; + return "MediaWiki/$wgVersion"; + } } -- cgit v1.2.2