From: Roan Kattouw Date: Wed, 3 Aug 2011 12:58:21 +0000 (+0000) Subject: Some random URL protocol forcing for protocol-relative URLs X-Git-Tag: 1.31.0-rc.0~28461 X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=commitdiff_plain;h=6adb2e86a52f485c649b7409c66c5ffde99c082e;p=lhc%2Fweb%2Fwiklou.git Some random URL protocol forcing for protocol-relative URLs --- diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 2e6139ec7d..df6dd49fdb 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -14,7 +14,7 @@ class Http { * 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 @@ -32,7 +32,7 @@ class Http { * @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 ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index b1cf069edc..0164ad3271 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2818,7 +2818,9 @@ $templates $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 ), ) ); } @@ -2840,7 +2842,7 @@ $templates } else { $tags[] = Html::element( 'link', array( 'rel' => 'canonical', - 'href' => $this->getTitle()->getFullURL() ) + 'href' => wfExpandUrl( $this->getTitle()->getFullURL(), PROTO_HTTP ) ) ); } } diff --git a/includes/User.php b/includes/User.php index a160e93a0d..ee9a736a34 100644 --- a/includes/User.php +++ b/includes/User.php @@ -3320,7 +3320,9 @@ class User { str_replace( '$1', "Special:$page/$token", - $wgArticlePath ) ); + $wgArticlePath ), + PROT_HTTP + ); } /** diff --git a/includes/WebRequest.php b/includes/WebRequest.php index fd21c9a1d6..8acd0dfcac 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -595,6 +595,8 @@ class WebRequest { * 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 */ diff --git a/includes/api/ApiRsd.php b/includes/api/ApiRsd.php index 16dc1faf02..040eb7ef43 100644 --- a/includes/api/ApiRsd.php +++ b/includes/api/ApiRsd.php @@ -48,7 +48,7 @@ class ApiRsd extends ApiBase { $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' ); diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 2e329b183a..46643849e4 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -370,7 +370,7 @@ class ForeignAPIRepo extends FileRepo { 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"; diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index a2aa879184..8fd83d681f 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -130,15 +130,16 @@ class CSSMin { // 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 diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 2c58ac4743..48cee4c0e4 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -723,7 +723,7 @@ class CoreParserFunctions { // ... 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' ) { diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index e1dfc4945c..59ca6dce15 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -204,8 +204,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { 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 ); } /**