Index: trunk/phase3/tests/phpunit/includes/GlobalTest.php |
— | — | @@ -2,19 +2,22 @@ |
3 | 3 | |
4 | 4 | class GlobalTest extends MediaWikiTestCase { |
5 | 5 | function setUp() { |
6 | | - global $wgReadOnlyFile, $wgContLang, $wgLang; |
| 6 | + global $wgReadOnlyFile, $wgContLang, $wgLang, $wgUrlProtocols; |
7 | 7 | $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile; |
| 8 | + $this->originals['wgUrlProtocols'] = $wgUrlProtocols; |
8 | 9 | $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" ); |
| 10 | + $wgUrlProtocols[] = 'file://'; |
9 | 11 | unlink( $wgReadOnlyFile ); |
10 | 12 | $wgContLang = $wgLang = Language::factory( 'en' ); |
11 | 13 | } |
12 | 14 | |
13 | 15 | function tearDown() { |
14 | | - global $wgReadOnlyFile; |
| 16 | + global $wgReadOnlyFile, $wgUrlProtocols; |
15 | 17 | if ( file_exists( $wgReadOnlyFile ) ) { |
16 | 18 | unlink( $wgReadOnlyFile ); |
17 | 19 | } |
18 | 20 | $wgReadOnlyFile = $this->originals['wgReadOnlyFile']; |
| 21 | + $wgUrlProtocols = $this->originals['wgUrlProtocols']; |
19 | 22 | } |
20 | 23 | |
21 | 24 | /** @dataProvider provideForWfArrayDiff2 */ |
— | — | @@ -815,6 +818,54 @@ |
816 | 819 | */); |
817 | 820 | } |
818 | 821 | |
| 822 | + /** |
| 823 | + * @dataProvider provideMakeUrlIndex() |
| 824 | + */ |
| 825 | + function testMakeUrlIndex( $url, $expected ) { |
| 826 | + $index = wfMakeUrlIndex( $url ); |
| 827 | + $this->assertEquals( $expected, $index, "wfMakeUrlIndex(\"$url\")" ); |
| 828 | + } |
| 829 | + |
| 830 | + function provideMakeUrlIndex() { |
| 831 | + return array( |
| 832 | + array( |
| 833 | + // just a regular :) |
| 834 | + 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627', |
| 835 | + 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' |
| 836 | + ), |
| 837 | + array( |
| 838 | + // mailtos are handled special |
| 839 | + // is this really right though? that final . probably belongs earlier? |
| 840 | + 'mailto:wiki@wikimedia.org', |
| 841 | + 'mailto:org.wikimedia@wiki.', |
| 842 | + ), |
| 843 | + |
| 844 | + // file URL cases per bug 28627... |
| 845 | + array( |
| 846 | + // three slashes: local filesystem path Unix-style |
| 847 | + 'file:///whatever/you/like.txt', |
| 848 | + 'file://./whatever/you/like.txt' |
| 849 | + ), |
| 850 | + array( |
| 851 | + // three slashes: local filesystem path Windows-style |
| 852 | + 'file:///c:/whatever/you/like.txt', |
| 853 | + 'file://./c:/whatever/you/like.txt' |
| 854 | + ), |
| 855 | + array( |
| 856 | + // two slashes: UNC filesystem path Windows-style |
| 857 | + 'file://intranet/whatever/you/like.txt', |
| 858 | + 'file://intranet./whatever/you/like.txt' |
| 859 | + ), |
| 860 | + // Multiple-slash cases that can sorta work on Mozilla |
| 861 | + // if you hack it just right are kinda pathological, |
| 862 | + // and unreliable cross-platform or on IE which means they're |
| 863 | + // unlikely to appear on intranets. |
| 864 | + // |
| 865 | + // Those will survive the algorithm but with results that |
| 866 | + // are less consistent. |
| 867 | + ); |
| 868 | + } |
| 869 | + |
819 | 870 | /* TODO: many more! */ |
820 | 871 | } |
821 | 872 | |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -2750,8 +2750,12 @@ |
2751 | 2751 | $domainpart = ''; |
2752 | 2752 | } |
2753 | 2753 | $reversedHost = $domainpart . '@' . $mailparts[0]; |
| 2754 | + } else if ( isset( $bits['host'] ) ) { |
| 2755 | + $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) ); |
2754 | 2756 | } else { |
2755 | | - $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) ); |
| 2757 | + // In file: URIs for instance it's common to have an empty host, |
| 2758 | + // which turns up as not getting a 'host' member from parse_url. |
| 2759 | + $reversedHost = '.'; |
2756 | 2760 | } |
2757 | 2761 | // Add an extra dot to the end |
2758 | 2762 | // Why? Is it in wrong place in mailto links? |
— | — | @@ -2766,6 +2770,13 @@ |
2767 | 2771 | $index .= ':' . $bits['port']; |
2768 | 2772 | } |
2769 | 2773 | if ( isset( $bits['path'] ) ) { |
| 2774 | + // parse_url() removes the initial '/' from the path |
| 2775 | + // for file: URLs with Windows-style paths, such as |
| 2776 | + // file:///c:/windows/stuff. We need to add it back |
| 2777 | + // to keep our division between host and path properly. |
| 2778 | + if ( strlen( $bits['path'] ) > 0 && substr( $bits['path'], 0, 1 ) !== '/' ) { |
| 2779 | + $index .= '/'; |
| 2780 | + } |
2770 | 2781 | $index .= $bits['path']; |
2771 | 2782 | } else { |
2772 | 2783 | $index .= '/'; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -243,6 +243,8 @@ |
244 | 244 | * (bug 28532) wfMsgExt() and wfMsgWikiHtml() use $wgOut->parse() |
245 | 245 | * (bug 16129) Transcluded special pages expose strip markers when they output parsed messages |
246 | 246 | * (bug 27249) "Installed software" table in Special:Version should always be left-to-right |
| 247 | +* (bug 28627) External link normalization now handles file: URL cases without |
| 248 | + throwing notice warnings. |
247 | 249 | |
248 | 250 | === API changes in 1.18 === |
249 | 251 | * (bug 26339) Throw warning when truncating an overlarge API result |