X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FLinkFilter.php;h=17b4d56635d4de10edb0e7c0c085f68d03318373;hp=2f5055871acfc037acbbd0be8dc1a652dacf20ea;hb=0a1144fb2a2804c4b01e4cbae336475f92186e5b;hpb=a57af76a0f05dac6b9dde425d8e9c5fad0c1ad19 diff --git a/includes/LinkFilter.php b/includes/LinkFilter.php index 2f5055871a..17b4d56635 100644 --- a/includes/LinkFilter.php +++ b/includes/LinkFilter.php @@ -38,9 +38,10 @@ class LinkFilter { * * @param Content $content Content to check * @param string $filterEntry Domainparts, see makeRegex() for more details + * @param string $protocol 'http://' or 'https://' * @return int 0 if no match or 1 if there's at least one match */ - static function matchEntry( Content $content, $filterEntry ) { + public static function matchEntry( Content $content, $filterEntry, $protocol = 'http://' ) { if ( !( $content instanceof TextContent ) ) { // TODO: handle other types of content too. // Maybe create ContentHandler::matchFilter( LinkFilter ). @@ -50,7 +51,7 @@ class LinkFilter { $text = $content->getNativeData(); - $regex = LinkFilter::makeRegex( $filterEntry ); + $regex = self::makeRegex( $filterEntry, $protocol ); return preg_match( $regex, $text ); } @@ -59,10 +60,12 @@ class LinkFilter { * * @param string $filterEntry URL, if it begins with "*.", it'll be * replaced to match any subdomain + * @param string $protocol 'http://' or 'https://' + * * @return string Regex pattern, for preg_match() */ - private static function makeRegex( $filterEntry ) { - $regex = '!http://'; + private static function makeRegex( $filterEntry, $protocol ) { + $regex = '!' . preg_quote( $protocol ); if ( substr( $filterEntry, 0, 2 ) == '*.' ) { $regex .= '(?:[A-Za-z0-9.-]+\.|)'; $filterEntry = substr( $filterEntry, 2 );