http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93820

Revision: 93820
Author:   catrope
Date:     2011-08-03 12:58:21 +0000 (Wed, 03 Aug 2011)
Log Message:
-----------
Some random URL protocol forcing for protocol-relative URLs

Modified Paths:
--------------
    trunk/phase3/includes/HttpFunctions.php
    trunk/phase3/includes/OutputPage.php
    trunk/phase3/includes/User.php
    trunk/phase3/includes/WebRequest.php
    trunk/phase3/includes/api/ApiRsd.php
    trunk/phase3/includes/filerepo/ForeignAPIRepo.php
    trunk/phase3/includes/libs/CSSMin.php
    trunk/phase3/includes/parser/CoreParserFunctions.php
    trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php

Modified: trunk/phase3/includes/HttpFunctions.php
===================================================================
--- trunk/phase3/includes/HttpFunctions.php     2011-08-03 12:52:17 UTC (rev 
93819)
+++ trunk/phase3/includes/HttpFunctions.php     2011-08-03 12:58:21 UTC (rev 
93820)
@@ -14,7 +14,7 @@
         * 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 @@
         * @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 );
 

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2011-08-03 12:52:17 UTC (rev 
93819)
+++ trunk/phase3/includes/OutputPage.php        2011-08-03 12:58:21 UTC (rev 
93820)
@@ -2818,7 +2818,9 @@
                        $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 @@
                        } else {
                                $tags[] = Html::element( 'link', array(
                                        'rel' => 'canonical',
-                                       'href' => 
$this->getTitle()->getFullURL() )
+                                       'href' => wfExpandUrl( 
$this->getTitle()->getFullURL(), PROTO_HTTP ) )
                                );
                        }
                }

Modified: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php      2011-08-03 12:52:17 UTC (rev 93819)
+++ trunk/phase3/includes/User.php      2011-08-03 12:58:21 UTC (rev 93820)
@@ -3320,7 +3320,9 @@
                        str_replace(
                                '$1',
                                "Special:$page/$token",
-                               $wgArticlePath ) );
+                               $wgArticlePath ),
+                       PROT_HTTP
+               );
        }
 
        /**

Modified: trunk/phase3/includes/WebRequest.php
===================================================================
--- trunk/phase3/includes/WebRequest.php        2011-08-03 12:52:17 UTC (rev 
93819)
+++ trunk/phase3/includes/WebRequest.php        2011-08-03 12:58:21 UTC (rev 
93820)
@@ -595,6 +595,8 @@
         * 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
         */

Modified: trunk/phase3/includes/api/ApiRsd.php
===================================================================
--- trunk/phase3/includes/api/ApiRsd.php        2011-08-03 12:52:17 UTC (rev 
93819)
+++ trunk/phase3/includes/api/ApiRsd.php        2011-08-03 12:58:21 UTC (rev 
93820)
@@ -48,7 +48,7 @@
                $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' );
 

Modified: trunk/phase3/includes/filerepo/ForeignAPIRepo.php
===================================================================
--- trunk/phase3/includes/filerepo/ForeignAPIRepo.php   2011-08-03 12:52:17 UTC 
(rev 93819)
+++ trunk/phase3/includes/filerepo/ForeignAPIRepo.php   2011-08-03 12:58:21 UTC 
(rev 93820)
@@ -370,7 +370,7 @@
        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";
 

Modified: trunk/phase3/includes/libs/CSSMin.php
===================================================================
--- trunk/phase3/includes/libs/CSSMin.php       2011-08-03 12:52:17 UTC (rev 
93819)
+++ trunk/phase3/includes/libs/CSSMin.php       2011-08-03 12:58:21 UTC (rev 
93820)
@@ -130,15 +130,16 @@
                        // 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

Modified: trunk/phase3/includes/parser/CoreParserFunctions.php
===================================================================
--- trunk/phase3/includes/parser/CoreParserFunctions.php        2011-08-03 
12:52:17 UTC (rev 93819)
+++ trunk/phase3/includes/parser/CoreParserFunctions.php        2011-08-03 
12:58:21 UTC (rev 93820)
@@ -723,7 +723,7 @@
                                // ... 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' ) {

Modified: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php
===================================================================
--- trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php   
2011-08-03 12:52:17 UTC (rev 93819)
+++ trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php   
2011-08-03 12:58:21 UTC (rev 93820)
@@ -204,8 +204,9 @@
                                        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 );
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to