From 08aa4418c30cfc18ccc69a0f0f9cb9e17be6c196 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Mon, 12 Aug 2013 09:28:15 +0200 Subject: Update to MediaWiki 1.21.1 --- includes/LinkFilter.php | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'includes/LinkFilter.php') diff --git a/includes/LinkFilter.php b/includes/LinkFilter.php index 214f4959..11b65595 100644 --- a/includes/LinkFilter.php +++ b/includes/LinkFilter.php @@ -20,10 +20,9 @@ * @file */ - /** * Some functions to help implement an external link filter for spam control. - * + * * @todo implement the filter. Currently these are just some functions to help * maintenance/cleanupSpam.php remove links to a single specified domain. The * next thing is to implement functions for checking a given page against a big @@ -34,13 +33,22 @@ class LinkFilter { /** - * Check whether $text contains a link to $filterEntry + * Check whether $content contains a link to $filterEntry * - * @param $text String: text to check - * @param $filterEntry String: domainparts, see makeRegex() for more details + * @param $content Content: content to check + * @param string $filterEntry domainparts, see makeRegex() for more details * @return Integer: 0 if no match or 1 if there's at least one match */ - static function matchEntry( $text, $filterEntry ) { + static function matchEntry( Content $content, $filterEntry ) { + if ( !( $content instanceof TextContent ) ) { + //TODO: handle other types of content too. + // Maybe create ContentHandler::matchFilter( LinkFilter ). + // Think about a common base class for LinkFilter and MagicWord. + return 0; + } + + $text = $content->getNativeData(); + $regex = LinkFilter::makeRegex( $filterEntry ); return preg_match( $regex, $text ); } @@ -48,7 +56,7 @@ class LinkFilter { /** * Builds a regex pattern for $filterEntry. * - * @param $filterEntry String: URL, if it begins with "*.", it'll be + * @param string $filterEntry URL, if it begins with "*.", it'll be * replaced to match any subdomain * @return String: regex pattern, for preg_match() */ @@ -76,11 +84,11 @@ class LinkFilter { * * Asterisks in any other location are considered invalid. * - * @param $filterEntry String: domainparts + * @param string $filterEntry domainparts * @param $prot String: protocol * @return Array to be passed to DatabaseBase::buildLike() or false on error */ - public static function makeLikeArray( $filterEntry , $prot = 'http://' ) { + public static function makeLikeArray( $filterEntry, $prot = 'http://' ) { $db = wfGetDB( DB_MASTER ); if ( substr( $filterEntry, 0, 2 ) == '*.' ) { $subdomains = true; @@ -109,18 +117,18 @@ class LinkFilter { } // Reverse the labels in the hostname, convert to lower case // For emails reverse domainpart only - if ( $prot == 'mailto:' && strpos($host, '@') ) { - // complete email adress + if ( $prot == 'mailto:' && strpos( $host, '@' ) ) { + // complete email address $mailparts = explode( '@', $host ); $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) ); $host = $domainpart . '@' . $mailparts[0]; $like = array( "$prot$host", $db->anyString() ); } elseif ( $prot == 'mailto:' ) { - // domainpart of email adress only. do not add '.' - $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); - $like = array( "$prot$host", $db->anyString() ); + // domainpart of email address only. do not add '.' + $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); + $like = array( "$prot$host", $db->anyString() ); } else { - $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); + $host = strtolower( implode( '.', array_reverse( explode( '.', $host ) ) ) ); if ( substr( $host, -1, 1 ) !== '.' ) { $host .= '.'; } @@ -140,7 +148,7 @@ class LinkFilter { /** * Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder. * - * @param $arr array: array to filter + * @param array $arr array to filter * @return array filtered array */ public static function keepOneWildcard( $arr ) { -- cgit v1.2.3-54-g00ecf