* allow interwiki {{subst:...}} using action=raw fetches
* Allowed non-MSIE browsers to access action=raw via the article alias. This is necessary to allow action=raw transclusion, since the only known URL is the article path, not the script path.
* Specify a user agent in wfGetHttp() fetches, when using curl.
* Added transcache table to tables.sql, it was in the updater but not there for some reason.
* Fixed transcache expiry, added option
* Allow interwiki transclusion outside the template namespace using leading colon syntax. Syntax is counterintuitive at times, e.g. to subst the wikipedia main page you would use {{subst::Wikipedia:Main_Page}} not {{subst:Wikipedia::Main_Page}}.
80 lines
2 KiB
PHP
80 lines
2 KiB
PHP
<?php
|
|
/**
|
|
* Various HTTP related functions
|
|
*/
|
|
|
|
/**
|
|
* Get the contents of a file by HTTP
|
|
*
|
|
* if $timeout is 'default', $wgHTTPTimeout is used
|
|
*/
|
|
function wfGetHTTP( $url, $timeout = 'default' ) {
|
|
global $wgHTTPTimeout, $wgHTTPProxy, $wgVersion;
|
|
|
|
# Use curl if available
|
|
if ( function_exists( 'curl_init' ) ) {
|
|
$c = curl_init( $url );
|
|
if ( wfIsLocalURL( $url ) ) {
|
|
curl_setopt( $c, CURLOPT_PROXY, 'localhost:80' );
|
|
} else if ($wgHTTPProxy) {
|
|
curl_setopt($c, CURLOPT_PROXY, $wgHTTPProxy);
|
|
}
|
|
|
|
if ( $timeout == 'default' ) {
|
|
$timeout = $wgHTTPTimeout;
|
|
}
|
|
curl_setopt( $c, CURLOPT_TIMEOUT, $timeout );
|
|
curl_setopt( $c, CURLOPT_USERAGENT, "MediaWiki/$wgVersion" );
|
|
ob_start();
|
|
curl_exec( $c );
|
|
$text = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
# Don't return the text of error messages, return false on error
|
|
if ( curl_getinfo( $c, CURLINFO_HTTP_CODE ) != 200 ) {
|
|
$text = false;
|
|
}
|
|
curl_close( $c );
|
|
} else {
|
|
# Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
|
|
# This may take 3 minutes to time out, and doesn't have local fetch capabilities
|
|
$url_fopen = ini_set( 'allow_url_fopen', 1 );
|
|
$text = file_get_contents( $url );
|
|
ini_set( 'allow_url_fopen', $url_fopen );
|
|
}
|
|
return $text;
|
|
}
|
|
|
|
/**
|
|
* Check if the URL can be served by localhost
|
|
*/
|
|
function wfIsLocalURL( $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;
|
|
}
|
|
|
|
?>
|