* Perform an HTTP request
*
* @param $method String: HTTP method. Usually GET/POST
- * @param $url String: full URL to act on
+ * @param $url String: full URL to act on. If protocol-relative, will be expanded to an http:// URL
* @param $options Array: options to pass to MWHttpRequest object.
* Possible keys for the array:
* - timeout Timeout length in seconds
* @return Mixed: (bool)false on failure or a string on success
*/
public static function request( $method, $url, $options = array() ) {
- $url = wfExpandUrl( $url );
+ $url = wfExpandUrl( $url, PROT_HTTP );
wfDebug( "HTTP: $method: $url\n" );
$options['method'] = strtoupper( $method );
$tags[] = Html::element( 'link', array(
'rel' => 'EditURI',
'type' => 'application/rsd+xml',
- 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
+ // Output a protocol-relative URL here if $wgServer is protocol-relative
+ // Whether RSD accepts relative or protocol-relative URLs is completely undocumented, though
+ 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ), PROT_RELATIVE ),
) );
}
} else {
$tags[] = Html::element( 'link', array(
'rel' => 'canonical',
- 'href' => $this->getTitle()->getFullURL() )
+ 'href' => wfExpandUrl( $this->getTitle()->getFullURL(), PROTO_HTTP ) )
);
}
}
str_replace(
'$1',
"Special:$page/$token",
- $wgArticlePath ) );
+ $wgArticlePath ),
+ PROT_HTTP
+ );
}
/**
* Return the request URI with the canonical service and hostname, path,
* and query string. This will be suitable for use as an absolute link
* in HTML or other output.
+ *
+ * NOTE: This will output a protocol-relative URL if $wgServer is protocol-relative
*
* @return String
*/
$service = array( 'apis' => $this->formatRsdApiList() );
ApiResult::setContent( $service, 'MediaWiki', 'engineName' );
ApiResult::setContent( $service, 'http://www.mediawiki.org/', 'engineLink' );
- ApiResult::setContent( $service, Title::newMainPage()->getFullURL(), 'homePageLink' );
+ ApiResult::setContent( $service, wfExpandUrl( Title::newMainPage()->getFullURL() ), 'homePageLink' );
$result->setIndexedTagName( $service['apis'], 'api' );
public static function httpGet( $url, $timeout = 'default', $options = array() ) {
$options['timeout'] = $timeout;
/* Http::get */
- $url = wfExpandUrl( $url );
+ $url = wfExpandUrl( $url, PROT_HTTP );
wfDebug( "ForeignAPIRepo: HTTP GET: $url\n" );
$options['method'] = "GET";
// URLs with absolute paths like /w/index.php need to be expanded
// to absolute URLs but otherwise left alone
if ( $match['file'][0] !== '' && $match['file'][0][0] === '/' ) {
- // Replace the file path with an expanded URL
- // ...but only if wfExpandUrl() is even available. This will not be the case if we're running outside of MW
+ // Replace the file path with an expanded (possibly protocol-relative) URL
+ // ...but only if wfExpandUrl() is even available.
+ // This will not be the case if we're running outside of MW
$lengthIncrease = 0;
if ( function_exists( 'wfExpandUrl' ) ) {
$expanded = wfExpandUrl( $match['file'][0] );
$origLength = strlen( $match['file'][0] );
$lengthIncrease = strlen( $expanded ) - $origLength;
- $source = substr_replace( $source, wfExpandUrl( $match['file'][0] ),
- $match['file'][1], $origLength
+ $source = substr_replace( $source, wfExpandUrl( $match['file'][0], PROT_RELATIVE ),
+ $match['file'][1], $origLength,
);
}
// Move the offset to the end of the match, leaving it alone
// ... and we can
if ( $mto && !$mto->isError() ) {
// ... change the URL to point to a thumbnail.
- $url = wfExpandUrl( $mto->getUrl() );
+ $url = wfExpandUrl( $mto->getUrl(), PROT_RELATIVE );
}
}
if ( $option == 'nowiki' ) {
break;
}
}
- // Make sure the remote base path is a complete valid url
- $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath );
+ // Make sure the remote base path is a complete valid URL,
+ // but possibly protocol-relative to avoid cache pollution
+ $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath, PROT_RELATIVE );
}
/**