Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -2339,9 +2339,16 @@ |
2340 | 2340 | } |
2341 | 2341 | |
2342 | 2342 | /** |
2343 | | - * Make a URL index, appropriate for the el_index field of externallinks. |
| 2343 | + * parse_url() work-alike, but non-broken. Differences: |
| 2344 | + * |
| 2345 | + * 1) Does not raise warnings on bad URLs (just returns false) |
| 2346 | + * 2) Handles protocols that don't use :// (e.g., mailto: and news:) correctly |
| 2347 | + * 3) Adds a "delimiter" element to the array, either '://' or ':' (see (2)) |
| 2348 | + * |
| 2349 | + * @param string $url A URL to parse |
| 2350 | + * @return array Bits of the URL in an associative array, per PHP docs |
2344 | 2351 | */ |
2345 | | -function wfMakeUrlIndex( $url ) { |
| 2352 | +function wfParseUrl( $url ) { |
2346 | 2353 | global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php |
2347 | 2354 | wfSuppressWarnings(); |
2348 | 2355 | $bits = parse_url( $url ); |
— | — | @@ -2349,12 +2356,12 @@ |
2350 | 2357 | if ( !$bits ) { |
2351 | 2358 | return false; |
2352 | 2359 | } |
| 2360 | + |
2353 | 2361 | // most of the protocols are followed by ://, but mailto: and sometimes news: not, check for it |
2354 | | - $delimiter = ''; |
2355 | | - if ( in_array( $bits['scheme'] . '://' , $wgUrlProtocols ) ) { |
2356 | | - $delimiter = '://'; |
2357 | | - } elseif ( in_array( $bits['scheme'] .':' , $wgUrlProtocols ) ) { |
2358 | | - $delimiter = ':'; |
| 2362 | + if ( in_array( $bits['scheme'] . '://', $wgUrlProtocols ) ) { |
| 2363 | + $bits['delimiter'] = '://'; |
| 2364 | + } elseif ( in_array( $bits['scheme'] . ':', $wgUrlProtocols ) ) { |
| 2365 | + $bits['delimiter'] = ':'; |
2359 | 2366 | // parse_url detects for news: and mailto: the host part of an url as path |
2360 | 2367 | // We have to correct this wrong detection |
2361 | 2368 | if ( isset ( $bits['path'] ) ) { |
— | — | @@ -2365,6 +2372,15 @@ |
2366 | 2373 | return false; |
2367 | 2374 | } |
2368 | 2375 | |
| 2376 | + return $bits; |
| 2377 | +} |
| 2378 | + |
| 2379 | +/** |
| 2380 | + * Make a URL index, appropriate for the el_index field of externallinks. |
| 2381 | + */ |
| 2382 | +function wfMakeUrlIndex( $url ) { |
| 2383 | + $bits = wfParseUrl( $url ); |
| 2384 | + |
2369 | 2385 | // Reverse the labels in the hostname, convert to lower case |
2370 | 2386 | // For emails reverse domainpart only |
2371 | 2387 | if ( $bits['scheme'] == 'mailto' ) { |
— | — | @@ -2386,7 +2402,7 @@ |
2387 | 2403 | } |
2388 | 2404 | // Reconstruct the pseudo-URL |
2389 | 2405 | $prot = $bits['scheme']; |
2390 | | - $index = "$prot$delimiter$reversedHost"; |
| 2406 | + $index = $prot . $bits['delimiter'] . $reversedHost; |
2391 | 2407 | // Leave out user and password. Add the port, path, query and fragment |
2392 | 2408 | if ( isset( $bits['port'] ) ) $index .= ':' . $bits['port']; |
2393 | 2409 | if ( isset( $bits['path'] ) ) { |