r93820 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93819‎ | r93820 | r93821 >
Date:12:58, 3 August 2011
Author:catrope
Status:ok
Tags:
Comment:
Some random URL protocol forcing for protocol-relative URLs
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/WebRequest.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRsd.php (modified) (history)
  • /trunk/phase3/includes/filerepo/ForeignAPIRepo.php (modified) (history)
  • /trunk/phase3/includes/libs/CSSMin.php (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -3320,7 +3320,9 @@
33213321 str_replace(
33223322 '$1',
33233323 "Special:$page/$token",
3324 - $wgArticlePath ) );
 3324+ $wgArticlePath ),
 3325+ PROT_HTTP
 3326+ );
33253327 }
33263328
33273329 /**
Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -723,7 +723,7 @@
724724 // ... and we can
725725 if ( $mto && !$mto->isError() ) {
726726 // ... change the URL to point to a thumbnail.
727 - $url = wfExpandUrl( $mto->getUrl() );
 727+ $url = wfExpandUrl( $mto->getUrl(), PROT_RELATIVE );
728728 }
729729 }
730730 if ( $option == 'nowiki' ) {
Index: trunk/phase3/includes/filerepo/ForeignAPIRepo.php
@@ -370,7 +370,7 @@
371371 public static function httpGet( $url, $timeout = 'default', $options = array() ) {
372372 $options['timeout'] = $timeout;
373373 /* Http::get */
374 - $url = wfExpandUrl( $url );
 374+ $url = wfExpandUrl( $url, PROT_HTTP );
375375 wfDebug( "ForeignAPIRepo: HTTP GET: $url\n" );
376376 $options['method'] = "GET";
377377
Index: trunk/phase3/includes/OutputPage.php
@@ -2818,7 +2818,9 @@
28192819 $tags[] = Html::element( 'link', array(
28202820 'rel' => 'EditURI',
28212821 'type' => 'application/rsd+xml',
2822 - 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
 2822+ // Output a protocol-relative URL here if $wgServer is protocol-relative
 2823+ // Whether RSD accepts relative or protocol-relative URLs is completely undocumented, though
 2824+ 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ), PROT_RELATIVE ),
28232825 ) );
28242826 }
28252827
@@ -2840,7 +2842,7 @@
28412843 } else {
28422844 $tags[] = Html::element( 'link', array(
28432845 'rel' => 'canonical',
2844 - 'href' => $this->getTitle()->getFullURL() )
 2846+ 'href' => wfExpandUrl( $this->getTitle()->getFullURL(), PROTO_HTTP ) )
28452847 );
28462848 }
28472849 }
Index: trunk/phase3/includes/api/ApiRsd.php
@@ -48,7 +48,7 @@
4949 $service = array( 'apis' => $this->formatRsdApiList() );
5050 ApiResult::setContent( $service, 'MediaWiki', 'engineName' );
5151 ApiResult::setContent( $service, 'http://www.mediawiki.org/', 'engineLink' );
52 - ApiResult::setContent( $service, Title::newMainPage()->getFullURL(), 'homePageLink' );
 52+ ApiResult::setContent( $service, wfExpandUrl( Title::newMainPage()->getFullURL() ), 'homePageLink' );
5353
5454 $result->setIndexedTagName( $service['apis'], 'api' );
5555
Index: trunk/phase3/includes/WebRequest.php
@@ -595,6 +595,8 @@
596596 * Return the request URI with the canonical service and hostname, path,
597597 * and query string. This will be suitable for use as an absolute link
598598 * in HTML or other output.
 599+ *
 600+ * NOTE: This will output a protocol-relative URL if $wgServer is protocol-relative
599601 *
600602 * @return String
601603 */
Index: trunk/phase3/includes/resourceloader/ResourceLoaderFileModule.php
@@ -204,8 +204,9 @@
205205 break;
206206 }
207207 }
208 - // Make sure the remote base path is a complete valid url
209 - $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath );
 208+ // Make sure the remote base path is a complete valid URL,
 209+ // but possibly protocol-relative to avoid cache pollution
 210+ $this->remoteBasePath = wfExpandUrl( $this->remoteBasePath, PROT_RELATIVE );
210211 }
211212
212213 /**
Index: trunk/phase3/includes/libs/CSSMin.php
@@ -130,15 +130,16 @@
131131 // URLs with absolute paths like /w/index.php need to be expanded
132132 // to absolute URLs but otherwise left alone
133133 if ( $match['file'][0] !== '' && $match['file'][0][0] === '/' ) {
134 - // Replace the file path with an expanded URL
135 - // ...but only if wfExpandUrl() is even available. This will not be the case if we're running outside of MW
 134+ // Replace the file path with an expanded (possibly protocol-relative) URL
 135+ // ...but only if wfExpandUrl() is even available.
 136+ // This will not be the case if we're running outside of MW
136137 $lengthIncrease = 0;
137138 if ( function_exists( 'wfExpandUrl' ) ) {
138139 $expanded = wfExpandUrl( $match['file'][0] );
139140 $origLength = strlen( $match['file'][0] );
140141 $lengthIncrease = strlen( $expanded ) - $origLength;
141 - $source = substr_replace( $source, wfExpandUrl( $match['file'][0] ),
142 - $match['file'][1], $origLength
 142+ $source = substr_replace( $source, wfExpandUrl( $match['file'][0], PROT_RELATIVE ),
 143+ $match['file'][1], $origLength,
143144 );
144145 }
145146 // Move the offset to the end of the match, leaving it alone
Index: trunk/phase3/includes/HttpFunctions.php
@@ -14,7 +14,7 @@
1515 * Perform an HTTP request
1616 *
1717 * @param $method String: HTTP method. Usually GET/POST
18 - * @param $url String: full URL to act on
 18+ * @param $url String: full URL to act on. If protocol-relative, will be expanded to an http:// URL
1919 * @param $options Array: options to pass to MWHttpRequest object.
2020 * Possible keys for the array:
2121 * - timeout Timeout length in seconds
@@ -32,7 +32,7 @@
3333 * @return Mixed: (bool)false on failure or a string on success
3434 */
3535 public static function request( $method, $url, $options = array() ) {
36 - $url = wfExpandUrl( $url );
 36+ $url = wfExpandUrl( $url, PROT_HTTP );
3737 wfDebug( "HTTP: $method: $url\n" );
3838 $options['method'] = strtoupper( $method );
3939

Follow-up revisions

RevisionCommit summaryAuthorDate
r93821Fix r93820: PROT_ -> PROTO_catrope13:11, 3 August 2011
r93822Fix syntax error in r93820catrope13:12, 3 August 2011
r938901.17wmf1: MFT rest of protocol-relative URL fixes and API cache splitting sup...catrope15:02, 4 August 2011
r94456Followup to r92580 and r93820: r92580 duplicated the call to wfExpandUrl(), a...catrope13:35, 14 August 2011
r94472MFT to REL1_18:...hashar19:43, 14 August 2011
r94996Reverse a bad decision in r93820, which added a comment to WebRequest::getFul...catrope13:25, 19 August 2011
r96562Move URL expansion from Http::request() (where it was put in r93820) to MWHtt...catrope13:48, 8 September 2011

Status & tagging log