From: Raimond Spekking Date: Mon, 19 Mar 2007 16:19:13 +0000 (+0000) Subject: * (bug 8324) LinkSearch: search for all protocols defined in wgUrlProtocols incl... X-Git-Tag: 1.31.0-rc.0~53669 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=7a693662883ae93728a21176b12b1173ff7c3e45;p=lhc%2Fweb%2Fwiklou.git * (bug 8324) LinkSearch: search for all protocols defined in wgUrlProtocols incl. email Make LinkFilter and GlobalFunctions more flexible --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 586a549957..23a1ec01d3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -274,12 +274,11 @@ lighter making things easier to read. * (bug 5546) Watchlist reflects logged actions like move, protection, undelete * (bug 9019) No warning during upload if image description page exists, but no image +* Support protocols other than HTTP in LinkFilter, use $wgUrlProtocols * (bug 8582) Allow thumbnailing when imagesize has a space. * (bug 8716) Change math_inputhash and math_outputhash to byte for Postgres * (bug 8558) Correct display of timestamps on some pages when using Postgres -Support protocols other than HTTP in LinkFilter - == Languages updated == * Arabic (ar) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 8a39524bea..dedd361913 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1932,22 +1932,45 @@ function wfRelativePath( $path, $from ) { * Make a URL index, appropriate for the el_index field of externallinks. */ function wfMakeUrlIndex( $url ) { - wfSuppressWarnings(); + global $wgUrlProtocols; // Allow all protocols defined in DefaultSettings/LocalSettings.php $bits = parse_url( $url ); - $prots = array( 'http', 'https', 'ftp', 'irc', 'news' ); + wfSuppressWarnings(); wfRestoreWarnings(); - if ( !$bits || !in_array( $bits['scheme'], $prots ) ) { + if ( !$bits ) { return false; } + // most of the protocols are followed by ://, but mailto: and sometimes news: not, check for it + $delimiter = ''; + if ( in_array( $bits['scheme'] . '://' , $wgUrlProtocols ) ) { + $delimiter = '://'; + } elseif ( in_array( $bits['scheme'] .':' , $wgUrlProtocols ) ) { + $delimiter = ':'; + // parse_url detects for news: and mailto: the host part of an url as path + // We have to correct this wrong detection + if ( isset ( $bits['path'] ) ) { + $bits['host'] = $bits['path']; + $bits['path'] = ''; + } + } else { + return false; + } + // Reverse the labels in the hostname, convert to lower case - $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) ); + // For emails reverse domainpart only + if ( $bits['scheme'] == 'mailto' ) { + $mailparts = explode( '@', $bits['host'] ); + $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) ); + $reversedHost = $domainpart . '@' . $mailparts[0]; + } else { + $reversedHost = strtolower( implode( '.', array_reverse( explode( '.', $bits['host'] ) ) ) ); + } // Add an extra dot to the end if ( substr( $reversedHost, -1, 1 ) !== '.' ) { $reversedHost .= '.'; } // Reconstruct the pseudo-URL $prot = $bits['scheme']; - $index = "$prot://$reversedHost"; + $index = "$prot$delimiter$reversedHost"; // Leave out user and password. Add the port, path, query and fragment if ( isset( $bits['port'] ) ) $index .= ':' . $bits['port']; if ( isset( $bits['path'] ) ) { diff --git a/includes/LinkFilter.php b/includes/LinkFilter.php index 5010009501..85bafcaef6 100644 --- a/includes/LinkFilter.php +++ b/includes/LinkFilter.php @@ -50,7 +50,7 @@ class LinkFilter { * @param $filterEntry String: domainparts * @param $prot String: protocol */ - function makeLike( $filterEntry , $prot = 'http' ) { + function makeLike( $filterEntry , $prot = 'http://' ) { if ( substr( $filterEntry, 0, 2 ) == '*.' ) { $subdomains = true; $filterEntry = substr( $filterEntry, 2 ); @@ -76,17 +76,31 @@ class LinkFilter { $path = '/'; $host = $filterEntry; } - $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); - if ( substr( $host, -1, 1 ) !== '.' ) { - $host .= '.'; - } - $like = "$prot://$host"; - - if ( $subdomains ) { - $like .= '%'; - } - if ( !$subdomains || $path !== '/' ) { - $like .= $path . '%'; + // Reverse the labels in the hostname, convert to lower case + // For emails reverse domainpart only + if ( $prot == 'mailto:' && strpos($host, '@') ) { + // complete email adress + $mailparts = explode( '@', $host ); + $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) ); + $host = $domainpart . '@' . $mailparts[0]; + $like = "$prot$host%"; + } elseif ( $prot == 'mailto:' ) { + // domainpart of email adress only. do not add '.' + $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); + $like = "$prot$host%"; + } else { + $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); + if ( substr( $host, -1, 1 ) !== '.' ) { + $host .= '.'; + } + $like = "$prot$host"; + + if ( $subdomains ) { + $like .= '%'; + } + if ( !$subdomains || $path !== '/' ) { + $like .= $path . '%'; + } } return $like; }