X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLinkFilter.php;h=3b03f879764d83b60df40e7d31c0df221cb06496;hb=1ee582b2a867207a95e3e4d3ff11ea814e216cdd;hp=790e2be4489e58159b1e5f11966466110f6663ec;hpb=237d3271fd313ebe09858a5c442a91216a7b61cf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/LinkFilter.php b/includes/LinkFilter.php index 790e2be448..3b03f87976 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 = self::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 );