Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -478,14 +478,21 @@ |
479 | 479 | * parse_url() work-alike, but non-broken. Differences: |
480 | 480 | * |
481 | 481 | * 1) Does not raise warnings on bad URLs (just returns false) |
482 | | - * 2) Handles protocols that don't use :// (e.g., mailto: and news:) correctly |
483 | | - * 3) Adds a "delimiter" element to the array, either '://' or ':' (see (2)) |
| 482 | + * 2) Handles protocols that don't use :// (e.g., mailto: and news: , as well as protocol-relative URLs) correctly |
| 483 | + * 3) Adds a "delimiter" element to the array, either '://', ':' or '//' (see (2)) |
484 | 484 | * |
485 | 485 | * @param $url String: a URL to parse |
486 | 486 | * @return Array: bits of the URL in an associative array, per PHP docs |
487 | 487 | */ |
488 | 488 | function wfParseUrl( $url ) { |
489 | 489 | global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php |
| 490 | + |
| 491 | + // Protocol-relative URLs are handled really badly by parse_url(). It's so bad that the easiest |
| 492 | + // way to handle them is to just prepend 'http:' and strip the protocol out later |
| 493 | + $wasRelative = substr( $url, 0, 2 ) == '//'; |
| 494 | + if ( $wasRelative ) { |
| 495 | + $url = "http:$url"; |
| 496 | + } |
490 | 497 | wfSuppressWarnings(); |
491 | 498 | $bits = parse_url( $url ); |
492 | 499 | wfRestoreWarnings(); |
— | — | @@ -517,6 +524,12 @@ |
518 | 525 | $bits['path'] = '/' . $bits['path']; |
519 | 526 | } |
520 | 527 | } |
| 528 | + |
| 529 | + // If the URL was protocol-relative, fix scheme and delimiter |
| 530 | + if ( $wasRelative ) { |
| 531 | + $bits['scheme'] = ''; |
| 532 | + $bits['delimiter'] = '//'; |
| 533 | + } |
521 | 534 | return $bits; |
522 | 535 | } |
523 | 536 | |