getFullURL() ); } if ( is_array( $curlOptions ) ) { foreach( $curlOptions as $option => $value ) { curl_setopt( $c, $option, $value ); } } ob_start(); curl_exec( $c ); $text = ob_get_contents(); ob_end_clean(); # Don't return the text of error messages, return false on error $retcode = curl_getinfo( $c, CURLINFO_HTTP_CODE ); if ( $retcode != 200 ) { wfDebug( __METHOD__ . ": HTTP return code $retcode\n" ); $text = false; } # Don't return truncated output $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 doesn't have local fetch capabilities... $headers = array( "User-Agent: " . self :: userAgent() ); if( strcasecmp( $method, 'post' ) == 0 ) { // Required for HTTP 1.0 POSTs $headers[] = "Content-Length: 0"; } $opts = array( 'http' => array( 'method' => $method, 'header' => implode( "\r\n", $headers ), 'timeout' => $timeout ) ); $ctx = stream_context_create($opts); $text = file_get_contents( $url, false, $ctx ); } return $text; } /** * Check if the URL can be served by localhost * @param $url string Full url to check * @return bool */ public static function isLocalURL( $url ) { global $wgCommandLineMode, $wgConf; if ( $wgCommandLineMode ) { return false; } // Extract host part $matches = array(); if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) { $host = $matches[1]; // Split up dotwise $domainParts = explode( '.', $host ); // Check if this domain or any superdomain is listed in $wgConf as a local virtual host $domainParts = array_reverse( $domainParts ); for ( $i = 0; $i < count( $domainParts ); $i++ ) { $domainPart = $domainParts[$i]; if ( $i == 0 ) { $domain = $domainPart; } else { $domain = $domainPart . '.' . $domain; } if ( $wgConf->isLocalVHost( $domain ) ) { return true; } } } return false; } /** * Return a standard user-agent we can use for external requests. */ public static function userAgent() { global $wgVersion; return "MediaWiki/$wgVersion"; } }