MediaWiki
1.33.0
|
Some functions to help implement an external link filter for spam control. More...
Static Public Member Functions | |
static | getQueryConditions ( $filterEntry, array $options=[]) |
Return query conditions which will match the specified string. More... | |
static | keepOneWildcard ( $arr) |
Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder. More... | |
static | makeIndexes ( $url) |
Converts a URL into a format for el_index. More... | |
static | makeLikeArray ( $filterEntry, $protocol='http://') |
Make an array to be used for calls to Database::buildLike(), which will match the specified string. More... | |
static | matchEntry (Content $content, $filterEntry, $protocol='http://') |
Check whether $content contains a link to $filterEntry. More... | |
static | supportsIDN () |
Indicate whether LinkFilter IDN support is available. More... | |
Public Attributes | |
const | VERSION = 1 |
Increment this when makeIndexes output changes. More... | |
Static Private Member Functions | |
static | indexifyHost ( $host) |
Canonicalize a hostname for el_index. More... | |
static | makeRegex ( $filterEntry, $protocol) |
Builds a regex pattern for $filterEntry. More... | |
Some functions to help implement an external link filter for spam control.
Another cool thing to do would be a web interface for fast spam removal.
Definition at line 34 of file LinkFilter.php.
|
static |
Return query conditions which will match the specified string.
There are several kinds of filter entry:
*.domain.com - Matches domain.com and www.domain.com domain.com - Matches domain.com or domain.com/ but not www.domain.com *.domain.com/x - Matches domain.com/xy or www.domain.com/xy. Also probably matches domain.com/foobar/xy due to limitations of LIKE syntax. domain.com/x - Matches domain.com/xy but not www.domain.com/xy 192.0.2.* - Matches any IP in 192.0.2.0/24. Can also have a path appended. [2001:db8::*] - Matches any IP in 2001:db8::/112. Can also have a path appended. [2001:db8:*] - Matches any IP in 2001:db8::/32. Can also have a path appended. foo@domain.com - With protocol 'mailto:', matches the email address foo@domain.com. *@domain.com - With protocol 'mailto:', matches any email address at domain.com, but not subdomains like foo@mail.domain.com
Asterisks in any other location are considered invalid.
string | $filterEntry | Filter entry, as described above |
array | $options | Options are:
|
Definition at line 254 of file LinkFilter.php.
References $options, captcha-old\count, DB_REPLICA, keepOneWildcard(), makeLikeArray(), and wfGetDB().
Referenced by ApiQueryExternalLinks\execute(), DeleteSelfExternals\execute(), CleanupSpam\execute(), LinkSearchPage\getQueryInfo(), ApiQueryExtLinksUsage\run(), and LinkFilterTest\testGetQueryConditions().
|
staticprivate |
Canonicalize a hostname for el_index.
string | $hose |
Definition at line 97 of file LinkFilter.php.
References captcha-old\count, StringUtils\isUtf8(), IP\isValid(), and IP\sanitizeIP().
Referenced by makeIndexes(), and makeLikeArray().
|
static |
Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder.
array | $arr | Array to filter |
Definition at line 385 of file LinkFilter.php.
Referenced by getQueryConditions(), and ApiQueryBase\prepareUrlQuerySearchString().
|
static |
Converts a URL into a format for el_index.
string | $url |
Definition at line 171 of file LinkFilter.php.
References captcha-old\count, indexifyHost(), and wfParseUrl().
Referenced by RefreshExternallinksIndex\doDBUpdates(), LinksUpdate\getExternalInsertions(), LinkFilterTest\testMakeIndexes(), LinkFilterTest\testMakeLikeArrayWithValidPatterns(), and wfMakeUrlIndexes().
|
static |
Make an array to be used for calls to Database::buildLike(), which will match the specified string.
This function does the same as LinkFilter::makeIndexes(), except it also takes care of adding wildcards
string | $filterEntry | Filter entry, |
string | $protocol | Protocol (default http://) |
Definition at line 312 of file LinkFilter.php.
References as, captcha-old\count, DB_REPLICA, indexifyHost(), wfGetDB(), and wfParseUrl().
Referenced by getQueryConditions(), ApiQueryBase\prepareUrlQuerySearchString(), LinkFilterTest\testMakeLikeArrayWithInvalidPatterns(), and LinkFilterTest\testMakeLikeArrayWithValidPatterns().
|
staticprivate |
Builds a regex pattern for $filterEntry.
string | $filterEntry | URL, if it begins with "*.", it'll be replaced to match any subdomain |
string | $protocol | 'http://' or 'https://' |
Definition at line 73 of file LinkFilter.php.
Referenced by matchEntry().
|
static |
Check whether $content contains a link to $filterEntry.
Content | $content | Content to check |
string | $filterEntry | Domainparts, see makeRegex() for more details |
string | $protocol | 'http://' or 'https://' |
Definition at line 49 of file LinkFilter.php.
References $content, and makeRegex().
Referenced by CleanupSpam\cleanupArticle().
|
static |
Indicate whether LinkFilter IDN support is available.
Definition at line 88 of file LinkFilter.php.
Referenced by RefreshExternallinksIndex\getUpdateKey(), and LinkFilterTest\testMakeLikeArrayWithValidPatterns().
const LinkFilter::VERSION = 1 |
Increment this when makeIndexes output changes.
It'll cause maintenance/refreshExternallinksIndex.php to run from update.php.
Definition at line 39 of file LinkFilter.php.
Referenced by RefreshExternallinksIndex\getUpdateKey().