Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -136,6 +136,7 @@ |
137 | 137 | * (bug 32358) Do not display "No higher resolution available" for dimensionless |
138 | 138 | files (like audio files) |
139 | 139 | * (bug 32168) Add wfAssembleUrl for use in wfExpandUrl |
| 140 | +* (bug 32168) fixed - wfExpandUrl expands dot segments now |
140 | 141 | |
141 | 142 | === API changes in 1.19 === |
142 | 143 | * (bug 19838) siprop=interwikimap can now use the interwiki cache. |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -444,8 +444,11 @@ |
445 | 445 | * like "subdir/foo.html", etc. |
446 | 446 | * |
447 | 447 | * @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 |
450 | 453 | */ |
451 | 454 | function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) { |
452 | 455 | global $wgServer, $wgCanonicalServer, $wgInternalServer; |
— | — | @@ -478,13 +481,26 @@ |
479 | 482 | $defaultProtoWithoutSlashes = substr( $defaultProto, 0, -2 ); |
480 | 483 | |
481 | 484 | if ( substr( $url, 0, 2 ) == '//' ) { |
482 | | - return $defaultProtoWithoutSlashes . $url; |
| 485 | + $url = $defaultProtoWithoutSlashes . $url; |
483 | 486 | } elseif ( substr( $url, 0, 1 ) == '/' ) { |
484 | 487 | // 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 |
487 | 497 | return $url; |
| 498 | + } elseif ( substr( $url, 0, 1 ) != '/' ) { |
| 499 | + # URL is a relative path |
| 500 | + return wfRemoveDotSegments( $url ); |
488 | 501 | } |
| 502 | + |
| 503 | + # Expanded URL is not valid. |
| 504 | + return false; |
489 | 505 | } |
490 | 506 | |
491 | 507 | /** |
— | — | @@ -502,18 +518,18 @@ |
503 | 519 | function wfAssembleUrl( $urlParts ) { |
504 | 520 | $result = ''; |
505 | 521 | |
506 | | - if ( array_key_exists( 'delimiter', $urlParts ) ) { |
507 | | - if ( array_key_exists( 'scheme', $urlParts ) ) { |
| 522 | + if ( isset( $urlParts['delimiter'] ) ) { |
| 523 | + if ( isset( $urlParts['scheme'] ) ) { |
508 | 524 | $result .= $urlParts['scheme']; |
509 | 525 | } |
510 | 526 | |
511 | 527 | $result .= $urlParts['delimiter']; |
512 | 528 | } |
513 | 529 | |
514 | | - if ( array_key_exists( 'host', $urlParts ) ) { |
515 | | - if ( array_key_exists( 'user', $urlParts ) ) { |
| 530 | + if ( isset( $urlParts['host'] ) ) { |
| 531 | + if ( isset( $urlParts['user'] ) ) { |
516 | 532 | $result .= $urlParts['user']; |
517 | | - if ( array_key_exists( 'pass', $urlParts ) ) { |
| 533 | + if ( isset( $urlParts['pass'] ) ) { |
518 | 534 | $result .= ':' . $urlParts['pass']; |
519 | 535 | } |
520 | 536 | $result .= '@'; |
— | — | @@ -521,20 +537,20 @@ |
522 | 538 | |
523 | 539 | $result .= $urlParts['host']; |
524 | 540 | |
525 | | - if ( array_key_exists( 'port', $urlParts ) ) { |
| 541 | + if ( isset( $urlParts['port'] ) ) { |
526 | 542 | $result .= ':' . $urlParts['port']; |
527 | 543 | } |
528 | 544 | } |
529 | 545 | |
530 | | - if ( array_key_exists( 'path', $urlParts ) ) { |
| 546 | + if ( isset( $urlParts['path'] ) ) { |
531 | 547 | $result .= $urlParts['path']; |
532 | 548 | } |
533 | 549 | |
534 | | - if ( array_key_exists( 'query', $urlParts ) ) { |
| 550 | + if ( isset( $urlParts['query'] ) ) { |
535 | 551 | $result .= '?' . $urlParts['query']; |
536 | 552 | } |
537 | 553 | |
538 | | - if ( array_key_exists( 'fragment', $urlParts ) ) { |
| 554 | + if ( isset( $urlParts['fragment'] ) ) { |
539 | 555 | $result .= '#' . $urlParts['fragment']; |
540 | 556 | } |
541 | 557 | |
Index: trunk/phase3/tests/parser/parserTests.txt |
— | — | @@ -1871,7 +1871,7 @@ |
1872 | 1872 | !! input |
1873 | 1873 | [[MeatBall:]] |
1874 | 1874 | !! 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> |
1876 | 1876 | </p> |
1877 | 1877 | !! end |
1878 | 1878 | |