3 * Various HTTP related functions
7 * Get the contents of a file by HTTP
9 * if $timeout is 'default', $wgHTTPTimeout is used
11 function wfGetHTTP( $url, $timeout = 'default' ) {
12 global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion;
14 # Use curl if available
15 if ( function_exists( 'curl_init' ) ) {
16 $c = curl_init( $url );
17 if ( wfIsLocalURL( $url ) ) {
18 curl_setopt( $c, CURLOPT_PROXY
, 'localhost:80' );
19 } else if ($wgHTTPProxy) {
20 curl_setopt($c, CURLOPT_PROXY
, $wgHTTPProxy);
23 if ( $timeout == 'default' ) {
24 $timeout = $wgHTTPTimeout;
26 curl_setopt( $c, CURLOPT_TIMEOUT
, $timeout );
27 curl_setopt( $c, CURLOPT_USERAGENT
, "MediaWiki/$wgVersion" );
30 $text = ob_get_contents();
33 # Don't return the text of error messages, return false on error
34 if ( curl_getinfo( $c, CURLINFO_HTTP_CODE
) != 200 ) {
39 # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
40 # This may take 3 minutes to time out, and doesn't have local fetch capabilities
41 $url_fopen = ini_set( 'allow_url_fopen', 1 );
42 $text = file_get_contents( $url );
43 ini_set( 'allow_url_fopen', $url_fopen );
49 * Check if the URL can be served by localhost
51 function wfIsLocalURL( $url ) {
52 global $wgCommandLineMode, $wgConf;
53 if ( $wgCommandLineMode ) {
59 if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
62 $domainParts = explode( '.', $host );
63 // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
64 $domainParts = array_reverse( $domainParts );
65 for ( $i = 0; $i < count( $domainParts ); $i++
) {
66 $domainPart = $domainParts[$i];
68 $domain = $domainPart;
70 $domain = $domainPart . '.' . $domain;
72 if ( $wgConf->isLocalVHost( $domain ) ) {