MediaWiki REL1_32
LinkFilter Class Reference

Some functions to help implement an external link filter for spam control. More...

Static Public Member Functions

static keepOneWildcard ( $arr)
 Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder.
 
static makeLikeArray ( $filterEntry, $protocol='http://')
 Make an array to be used for calls to Database::buildLike(), which will match the specified string.
 
static matchEntry (Content $content, $filterEntry, $protocol='http://')
 Check whether $content contains a link to $filterEntry.
 

Static Private Member Functions

static makeRegex ( $filterEntry, $protocol)
 Builds a regex pattern for $filterEntry.
 

Detailed Description

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 list of domains.

Another cool thing to do would be a web interface for fast spam removal.

Definition at line 34 of file LinkFilter.php.

Member Function Documentation

◆ keepOneWildcard()

static LinkFilter::keepOneWildcard ( $arr)
static

Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder.

Parameters
array$arrArray to filter
Returns
array Filtered array

Definition at line 181 of file LinkFilter.php.

References $value.

Referenced by LinkSearchPage\getQueryInfo(), and ApiQueryBase\prepareUrlQuerySearchString().

◆ makeLikeArray()

static LinkFilter::makeLikeArray ( $filterEntry,
$protocol = 'http://' )
static

Make an array to be used for calls to Database::buildLike(), which will match the specified string.

There are several kinds of filter entry: *.domain.com - Produces http://com.domain.%, matches domain.com and www.domain.com domain.com - Produces http://com.domain./%, matches domain.com or domain.com/ but not www.domain.com *.domain.com/x - Produces http://com.domain.%/x%, matches www.domain.com/xy domain.com/x - Produces http://com.domain./x%, matches domain.com/xy but not www.domain.com/xy

Asterisks in any other location are considered invalid.

This function does the same as wfMakeUrlIndexes(), except it also takes care of adding wildcards

Parameters
string$filterEntryDomainparts
string$protocolProtocol (default http://)
Returns
array|bool Array to be passed to Database::buildLike() or false on error

Definition at line 98 of file LinkFilter.php.

References DB_REPLICA, wfGetDB(), and wfParseUrl().

Referenced by CleanupSpam\execute(), LinkSearchPage\mungeQuery(), ApiQueryBase\prepareUrlQuerySearchString(), LinkFilterTest\testMakeLikeArrayWithInvalidPatterns(), and LinkFilterTest\testMakeLikeArrayWithValidPatterns().

◆ makeRegex()

static LinkFilter::makeRegex ( $filterEntry,
$protocol )
staticprivate

Builds a regex pattern for $filterEntry.

Parameters
string$filterEntryURL, if it begins with "*.", it'll be replaced to match any subdomain
string$protocol'http://' or 'https://'
Returns
string Regex pattern, for preg_match()

Definition at line 67 of file LinkFilter.php.

Referenced by matchEntry().

◆ matchEntry()

static LinkFilter::matchEntry ( Content $content,
$filterEntry,
$protocol = 'http://' )
static

Check whether $content contains a link to $filterEntry.

Parameters
Content$contentContent to check
string$filterEntryDomainparts, see makeRegex() for more details
string$protocol'http://' or 'https://'
Returns
int 0 if no match or 1 if there's at least one match

Definition at line 44 of file LinkFilter.php.

References $content, and makeRegex().

Referenced by CleanupSpam\cleanupArticle().


The documentation for this class was generated from the following file: