r46076 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46075‎ | r46076 | r46077 >
Date:18:02, 23 January 2009
Author:simetrical
Status:ok
Tags:
Comment:
Break off wfParseUrl() from wfMakeUrlIndex()

Should be no functional changes.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2339,9 +2339,16 @@
23402340 }
23412341
23422342 /**
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
23442351 */
2345 -function wfMakeUrlIndex( $url ) {
 2352+function wfParseUrl( $url ) {
23462353 global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php
23472354 wfSuppressWarnings();
23482355 $bits = parse_url( $url );
@@ -2349,12 +2356,12 @@
23502357 if ( !$bits ) {
23512358 return false;
23522359 }
 2360+
23532361 // 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'] = ':';
23592366 // parse_url detects for news: and mailto: the host part of an url as path
23602367 // We have to correct this wrong detection
23612368 if ( isset ( $bits['path'] ) ) {
@@ -2365,6 +2372,15 @@
23662373 return false;
23672374 }
23682375
 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+
23692385 // Reverse the labels in the hostname, convert to lower case
23702386 // For emails reverse domainpart only
23712387 if ( $bits['scheme'] == 'mailto' ) {
@@ -2386,7 +2402,7 @@
23872403 }
23882404 // Reconstruct the pseudo-URL
23892405 $prot = $bits['scheme'];
2390 - $index = "$prot$delimiter$reversedHost";
 2406+ $index = $prot . $bits['delimiter'] . $reversedHost;
23912407 // Leave out user and password. Add the port, path, query and fragment
23922408 if ( isset( $bits['port'] ) ) $index .= ':' . $bits['port'];
23932409 if ( isset( $bits['path'] ) ) {

Status & tagging log