Some random URL protocol forcing for protocol-relative URLs
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 3 Aug 2011 12:58:21 +0000 (12:58 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 3 Aug 2011 12:58:21 +0000 (12:58 +0000)
includes/HttpFunctions.php
includes/OutputPage.php
includes/User.php
includes/WebRequest.php
includes/api/ApiRsd.php
includes/filerepo/ForeignAPIRepo.php
includes/libs/CSSMin.php
includes/parser/CoreParserFunctions.php
includes/resourceloader/ResourceLoaderFileModule.php

index 2e6139e..df6dd49 100644 (file)
@@ -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 );
 
index b1cf069..0164ad3 100644 (file)
@@ -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 ) )
                                );
                        }
                }
index a160e93..ee9a736 100644 (file)
@@ -3320,7 +3320,9 @@ class User {
                        str_replace(
                                '$1',
                                "Special:$page/$token",
-                               $wgArticlePath ) );
+                               $wgArticlePath ),
+                       PROT_HTTP
+               );
        }
 
        /**
index fd21c9a..8acd0df 100644 (file)
@@ -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
         */
index 16dc1fa..040eb7e 100644 (file)
@@ -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' );
 
index 2e329b1..4664384 100644 (file)
@@ -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";
 
index a2aa879..8fd83d6 100644 (file)
@@ -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
index 2c58ac4..48cee4c 100644 (file)
@@ -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' ) {
index e1dfc49..59ca6dc 100644 (file)
@@ -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 );
        }
 
        /**