MediaWiki master
MediaWiki\ExternalLinks\LinkFilter Class Reference

Utilities for formatting and querying the externallinks table. More...

Static Public Member Functions

static getIndexedUrlsNonReversed ( $urls)
 Converts a set of URLs to be able to compare them with existing indexes.
 
static getProtocolPrefix ( $protocol)
 
static getQueryConditions ( $filterEntry, array $options=[])
 Return conditions for the externallinks table from a given filter entry.
 
static keepOneWildcard ( $arr)
 Filters an array returned by makeLikeArray(), removing everything past first pattern placeholder.
 
static makeIndexes ( $url, $reverseDomain=true)
 Convert given URL to format for the externallinks table.
 
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 prepareProtocols ()
 
static reverseIndexes ( $domainIndex)
 

Detailed Description

Utilities for formatting and querying the externallinks table.

This is primarily used by \MediaWiki\Deferred\LinksUpdate\ExternalLinksTable for managing the storage layer, and by SpecialLinkSearch and ApiQueryExtLinksUsage as query interface.

For spam removal and anti-spam meausures based on this, see also:

Definition at line 45 of file LinkFilter.php.

Member Function Documentation

◆ getIndexedUrlsNonReversed()

static MediaWiki\ExternalLinks\LinkFilter::getIndexedUrlsNonReversed ( $urls)
static

Converts a set of URLs to be able to compare them with existing indexes.

Since
1.41
Parameters
string[]$urlsList of URLs to be indexed
Returns
string[]

Definition at line 248 of file LinkFilter.php.

References $url, and MediaWiki\ExternalLinks\LinkFilter\makeIndexes().

◆ getProtocolPrefix()

static MediaWiki\ExternalLinks\LinkFilter::getProtocolPrefix ( $protocol)
static

◆ getQueryConditions()

static MediaWiki\ExternalLinks\LinkFilter::getQueryConditions ( $filterEntry,
array $options = [] )
static

Return conditions for the externallinks table from a given filter entry.

There are several ways you can query:

*.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.

Since
1.33
Parameters
string$filterEntryFilter entry, as described above
array$optionsOptions are:
  • protocol: (null, string, array) Protocol to query (default: http:// and https://)
  • oneWildcard: (bool) Stop at the first wildcard (default: false)
  • db: (IReadableDatabase|null) Database for building SQL text.
Returns
array|false Query conditions (to be ANDed) or false on error.

Definition at line 332 of file LinkFilter.php.

References MediaWiki\MainConfigNames\ExternalLinksDomainGaps, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\ExternalLinks\LinkFilter\keepOneWildcard(), and MediaWiki\ExternalLinks\LinkFilter\makeLikeArray().

◆ keepOneWildcard()

static MediaWiki\ExternalLinks\LinkFilter::keepOneWildcard ( $arr)
static

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

Note
You probably want self::getQueryConditions() instead
Parameters
array$arrArray to filter
Returns
array Filtered array

Definition at line 517 of file LinkFilter.php.

Referenced by MediaWiki\ExternalLinks\LinkFilter\getQueryConditions().

◆ makeIndexes()

static MediaWiki\ExternalLinks\LinkFilter::makeIndexes ( $url,
$reverseDomain = true )
static

Convert given URL to format for the externallinks table.

Since
1.33
Parameters
string$url
bool$reverseDomain
Returns
string[][] One entry. Empty array on error. Each entry is an array in form of <host,path>

Definition at line 180 of file LinkFilter.php.

References $url, and MediaWiki\MediaWikiServices\getInstance().

Referenced by MediaWiki\ExternalLinks\LinkFilter\getIndexedUrlsNonReversed().

◆ makeLikeArray()

static MediaWiki\ExternalLinks\LinkFilter::makeLikeArray ( $filterEntry,
$protocol = 'http://' )
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

Note
You probably want self::getQueryConditions() instead
Parameters
string$filterEntryFilter entry,
See also
self::getQueryConditions()
Parameters
string$protocolProtocol (default http://)
Returns
array|false Array to be passed to Database::buildLike() or false on error

Definition at line 434 of file LinkFilter.php.

References MediaWiki\MediaWikiServices\getInstance().

Referenced by MediaWiki\ExternalLinks\LinkFilter\getQueryConditions().

◆ matchEntry()

static MediaWiki\ExternalLinks\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 54 of file LinkFilter.php.

◆ prepareProtocols()

static MediaWiki\ExternalLinks\LinkFilter::prepareProtocols ( )
static

◆ reverseIndexes()

static MediaWiki\ExternalLinks\LinkFilter::reverseIndexes ( $domainIndex)
static

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