r103208 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103207‎ | r103208 | r103209 >
Date:18:53, 15 November 2011
Author:gicode
Status:ok (Comments)
Tags:
Comment:
Make wfExpandUrl use wfRemoveDotSegments on the resulting path. This finishes
off bug 32168.

Also follow-up r103199 (related) to use isset.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -136,6 +136,7 @@
137137 * (bug 32358) Do not display "No higher resolution available" for dimensionless
138138 files (like audio files)
139139 * (bug 32168) Add wfAssembleUrl for use in wfExpandUrl
 140+* (bug 32168) fixed - wfExpandUrl expands dot segments now
140141
141142 === API changes in 1.19 ===
142143 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -444,8 +444,11 @@
445445 * like "subdir/foo.html", etc.
446446 *
447447 * @param $url String: either fully-qualified or a local path + query
448 - * @param $defaultProto Mixed: one of the PROTO_* constants. Determines the protocol to use if $url or $wgServer is protocol-relative
449 - * @return string Fully-qualified URL
 448+ * @param $defaultProto Mixed: one of the PROTO_* constants. Determines the
 449+ * protocol to use if $url or $wgServer is
 450+ * protocol-relative
 451+ * @return string Fully-qualified URL, current-path-relative URL or false if
 452+ * no valid URL can be constructed
450453 */
451454 function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
452455 global $wgServer, $wgCanonicalServer, $wgInternalServer;
@@ -478,13 +481,26 @@
479482 $defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 );
480483
481484 if ( substr( $url, 0, 2 ) == '//' ) {
482 - return $defaultProtoWithoutSlashes . $url;
 485+ $url = $defaultProtoWithoutSlashes . $url;
483486 } elseif ( substr( $url, 0, 1 ) == '/' ) {
484487 // If $serverUrl is protocol-relative, prepend $defaultProtoWithoutSlashes, otherwise leave it alone
485 - return ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url;
486 - } else {
 488+ $url = ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url;
 489+ }
 490+
 491+ $bits = wfParseUrl( $url );
 492+ if ( $bits && isset( $bits['path'] ) ) {
 493+ $bits['path'] = wfRemoveDotSegments( $bits['path'] );
 494+ return wfAssembleUrl( $bits );
 495+ } elseif ( $bits ) {
 496+ # No path to expand
487497 return $url;
 498+ } elseif ( substr( $url, 0, 1 ) != '/' ) {
 499+ # URL is a relative path
 500+ return wfRemoveDotSegments( $url );
488501 }
 502+
 503+ # Expanded URL is not valid.
 504+ return false;
489505 }
490506
491507 /**
@@ -502,18 +518,18 @@
503519 function wfAssembleUrl( $urlParts ) {
504520 $result = '';
505521
506 - if ( array_key_exists( 'delimiter', $urlParts ) ) {
507 - if ( array_key_exists( 'scheme', $urlParts ) ) {
 522+ if ( isset( $urlParts['delimiter'] ) ) {
 523+ if ( isset( $urlParts['scheme'] ) ) {
508524 $result .= $urlParts['scheme'];
509525 }
510526
511527 $result .= $urlParts['delimiter'];
512528 }
513529
514 - if ( array_key_exists( 'host', $urlParts ) ) {
515 - if ( array_key_exists( 'user', $urlParts ) ) {
 530+ if ( isset( $urlParts['host'] ) ) {
 531+ if ( isset( $urlParts['user'] ) ) {
516532 $result .= $urlParts['user'];
517 - if ( array_key_exists( 'pass', $urlParts ) ) {
 533+ if ( isset( $urlParts['pass'] ) ) {
518534 $result .= ':' . $urlParts['pass'];
519535 }
520536 $result .= '@';
@@ -521,20 +537,20 @@
522538
523539 $result .= $urlParts['host'];
524540
525 - if ( array_key_exists( 'port', $urlParts ) ) {
 541+ if ( isset( $urlParts['port'] ) ) {
526542 $result .= ':' . $urlParts['port'];
527543 }
528544 }
529545
530 - if ( array_key_exists( 'path', $urlParts ) ) {
 546+ if ( isset( $urlParts['path'] ) ) {
531547 $result .= $urlParts['path'];
532548 }
533549
534 - if ( array_key_exists( 'query', $urlParts ) ) {
 550+ if ( isset( $urlParts['query'] ) ) {
535551 $result .= '?' . $urlParts['query'];
536552 }
537553
538 - if ( array_key_exists( 'fragment', $urlParts ) ) {
 554+ if ( isset( $urlParts['fragment'] ) ) {
539555 $result .= '#' . $urlParts['fragment'];
540556 }
541557
Index: trunk/phase3/tests/parser/parserTests.txt
@@ -1871,7 +1871,7 @@
18721872 !! input
18731873 [[MeatBall:]]
18741874 !! result
1875 -<p><a href="http://www.usemod.com/cgi-bin/mb.pl?" class="extiw" title="meatball:">MeatBall:</a>
 1875+<p><a href="http://www.usemod.com/cgi-bin/mb.pl" class="extiw" title="meatball:">MeatBall:</a>
18761876 </p>
18771877 !! end
18781878

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102587Add wfRemoveDotSegments and unit tests. This is a sane step towards fixing...gicode22:44, 9 November 2011
r103199Add wfAssembleUrl and unit tests. This is the next step towards fixing...gicode17:38, 15 November 2011

Comments

#Comment by Saper (talk | contribs)   22:46, 3 October 2013

I think that changing } else { to } elseif { on line 486 broken the case to wfExpandUrl(""), which causes bug 37868 in my opinion.

Status & tagging log