2012-01-17 06:13:46 +00:00
|
|
|
<?php
|
|
|
|
|
2019-07-03 12:52:16 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-09-20 10:16:00 +00:00
|
|
|
use MediaWiki\Storage\SlotRecord;
|
2019-07-03 12:52:16 +00:00
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
/**
|
|
|
|
* Base class for different kinds of blacklists
|
|
|
|
*/
|
|
|
|
abstract class BaseBlacklist {
|
|
|
|
/**
|
|
|
|
* Array of blacklist sources
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-06-06 16:29:27 +00:00
|
|
|
public $files = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array containing regexes to test against
|
|
|
|
*
|
|
|
|
* @var bool|array
|
|
|
|
*/
|
|
|
|
protected $regexes = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Chance of receiving a warning when the filter is hit
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $warningChance = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $warningTime = 600;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public $expiryTime = 900;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array containing blacklists that extend BaseBlacklist
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-06-06 16:29:27 +00:00
|
|
|
private static $blacklistTypes = [
|
2012-01-17 06:13:46 +00:00
|
|
|
'spam' => 'SpamBlacklist',
|
2012-01-18 23:29:37 +00:00
|
|
|
'email' => 'EmailBlacklist',
|
2017-06-06 16:29:27 +00:00
|
|
|
];
|
2012-01-17 06:13:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of blacklist instances
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-06-06 16:29:27 +00:00
|
|
|
private static $instances = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param array $settings
|
|
|
|
*/
|
2018-11-02 11:54:59 +00:00
|
|
|
public function __construct( $settings = [] ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
foreach ( $settings as $name => $value ) {
|
|
|
|
$this->$name = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 20:00:28 +00:00
|
|
|
/**
|
|
|
|
* @param array $links
|
2019-11-04 19:04:48 +00:00
|
|
|
* @param ?Title $title
|
2020-01-04 12:48:07 +00:00
|
|
|
* @param User $user
|
2015-06-22 20:00:28 +00:00
|
|
|
* @param bool $preventLog
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-01-04 11:16:36 +00:00
|
|
|
abstract public function filter(
|
|
|
|
array $links,
|
|
|
|
?Title $title,
|
2020-01-04 12:48:07 +00:00
|
|
|
User $user,
|
2020-01-04 11:16:36 +00:00
|
|
|
$preventLog = false
|
|
|
|
);
|
2015-06-22 20:00:28 +00:00
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
/**
|
|
|
|
* Adds a blacklist class to the registry
|
|
|
|
*
|
2017-10-07 09:15:06 +00:00
|
|
|
* @param string $type
|
|
|
|
* @param string $class
|
2012-01-17 06:13:46 +00:00
|
|
|
*/
|
|
|
|
public static function addBlacklistType( $type, $class ) {
|
|
|
|
self::$blacklistTypes[$type] = $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the array of blacklist types currently defined
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getBlacklistTypes() {
|
|
|
|
return self::$blacklistTypes;
|
|
|
|
}
|
|
|
|
|
2018-02-25 01:25:04 +00:00
|
|
|
/**
|
|
|
|
* @return SpamBlacklist
|
|
|
|
*/
|
|
|
|
public static function getSpamBlacklist() {
|
|
|
|
return self::getInstance( 'spam' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return EmailBlacklist
|
|
|
|
*/
|
|
|
|
public static function getEmailBlacklist() {
|
|
|
|
return self::getInstance( 'email' );
|
|
|
|
}
|
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
/**
|
|
|
|
* Returns an instance of the given blacklist
|
|
|
|
*
|
2018-02-25 01:25:04 +00:00
|
|
|
* @deprecated Use getSpamBlacklist() or getEmailBlacklist() instead
|
2017-10-07 09:15:06 +00:00
|
|
|
* @param string $type Code for the blacklist
|
2012-01-17 06:13:46 +00:00
|
|
|
* @return BaseBlacklist
|
2015-01-10 03:04:35 +00:00
|
|
|
* @throws Exception
|
2012-01-17 06:13:46 +00:00
|
|
|
*/
|
|
|
|
public static function getInstance( $type ) {
|
|
|
|
if ( !isset( self::$blacklistTypes[$type] ) ) {
|
2015-01-10 03:04:35 +00:00
|
|
|
throw new Exception( "Invalid blacklist type '$type' passed to " . __METHOD__ );
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !isset( self::$instances[$type] ) ) {
|
|
|
|
global $wgBlacklistSettings;
|
|
|
|
|
|
|
|
// Prevent notices
|
|
|
|
if ( !isset( $wgBlacklistSettings[$type] ) ) {
|
2017-06-06 16:29:27 +00:00
|
|
|
$wgBlacklistSettings[$type] = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 18:41:12 +00:00
|
|
|
$class = self::$blacklistTypes[$type];
|
|
|
|
self::$instances[$type] = new $class( $wgBlacklistSettings[$type] );
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instances[$type];
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:53:36 +00:00
|
|
|
/**
|
|
|
|
* Clear instance cache. For use during testing.
|
|
|
|
*/
|
|
|
|
public static function clearInstanceCache() {
|
|
|
|
self::$instances = [];
|
|
|
|
}
|
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
/**
|
|
|
|
* Returns the code for the blacklist implementation
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract protected function getBlacklistType();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given local page title is a spam regex source.
|
|
|
|
*
|
|
|
|
* @param Title $title
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-01-18 23:29:37 +00:00
|
|
|
public static function isLocalSource( Title $title ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
global $wgDBname, $wgBlacklistSettings;
|
|
|
|
|
2019-09-12 13:48:50 +00:00
|
|
|
if ( $title->inNamespace( NS_MEDIAWIKI ) ) {
|
2017-06-06 16:29:27 +00:00
|
|
|
$sources = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
foreach ( self::$blacklistTypes as $type => $class ) {
|
2021-03-01 17:34:56 +00:00
|
|
|
// For the built in types, this results in the use of:
|
|
|
|
// spam-blacklist, spam-whitelist
|
|
|
|
// email-blacklist, email-whitelist
|
2012-01-17 06:13:46 +00:00
|
|
|
$type = ucfirst( $type );
|
2019-12-22 05:21:52 +00:00
|
|
|
$sources[] = "$type-blacklist";
|
|
|
|
$sources[] = "$type-whitelist";
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
if ( in_array( $title->getDBkey(), $sources ) ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$thisHttp = wfExpandUrl( $title->getFullUrl( 'action=raw' ), PROTO_HTTP );
|
|
|
|
$thisHttpRegex = '/^' . preg_quote( $thisHttp, '/' ) . '(?:&.*)?$/';
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
$files = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
foreach ( self::$blacklistTypes as $type => $class ) {
|
|
|
|
if ( isset( $wgBlacklistSettings[$type]['files'] ) ) {
|
|
|
|
$files += $wgBlacklistSettings[$type]['files'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 16:29:27 +00:00
|
|
|
foreach ( $files as $fileName ) {
|
|
|
|
$matches = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
if ( preg_match( '/^DB: (\w*) (.*)$/', $fileName, $matches ) ) {
|
2021-03-01 17:34:56 +00:00
|
|
|
if ( $wgDBname === $matches[1] && $matches[2] === $title->getPrefixedDbKey() ) {
|
|
|
|
// Local DB fetch of this page...
|
|
|
|
return true;
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
2017-06-06 16:29:27 +00:00
|
|
|
} elseif ( preg_match( $thisHttpRegex, $fileName ) ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
// Raw view of this page
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-18 23:29:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the type of blacklist from the given title
|
|
|
|
*
|
2017-07-06 01:13:28 +00:00
|
|
|
* @todo building a regex for this is pretty overkill
|
2012-01-18 23:29:37 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public static function getTypeFromTitle( Title $title ) {
|
2019-09-02 08:49:09 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
2017-07-06 01:13:28 +00:00
|
|
|
|
2019-09-02 08:49:09 +00:00
|
|
|
$types = array_map( [ $contLang, 'ucfirst' ], array_keys( self::$blacklistTypes ) );
|
2018-09-03 19:29:35 +00:00
|
|
|
$regex = '/(' . implode( '|', $types ) . ')-(?:blacklist|whitelist)/';
|
2012-01-18 23:29:37 +00:00
|
|
|
|
|
|
|
if ( preg_match( $regex, $title->getDBkey(), $m ) ) {
|
|
|
|
return strtolower( $m[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
/**
|
|
|
|
* Fetch local and (possibly cached) remote blacklists.
|
|
|
|
* Will be cached locally across multiple invocations.
|
|
|
|
* @return array set of regular expressions, potentially empty.
|
|
|
|
*/
|
2018-11-02 11:54:59 +00:00
|
|
|
public function getBlacklists() {
|
2017-06-06 16:29:27 +00:00
|
|
|
if ( $this->regexes === false ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
$this->regexes = array_merge(
|
|
|
|
$this->getLocalBlacklists(),
|
2019-09-12 13:48:50 +00:00
|
|
|
$this->getSharedBlacklists()
|
|
|
|
);
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
return $this->regexes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the local blacklist
|
|
|
|
*
|
|
|
|
* @return array Regular expressions
|
|
|
|
*/
|
|
|
|
public function getLocalBlacklists() {
|
2015-07-28 22:01:39 +00:00
|
|
|
$type = $this->getBlacklistType();
|
2019-07-03 12:52:16 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2015-07-28 22:01:39 +00:00
|
|
|
|
2018-06-28 13:45:40 +00:00
|
|
|
return $cache->getWithSetCallback(
|
|
|
|
$cache->makeKey( 'spamblacklist', $type, 'blacklist-regex' ),
|
2015-10-08 02:18:50 +00:00
|
|
|
$this->expiryTime,
|
2020-10-24 10:32:18 +00:00
|
|
|
function () use ( $type ) {
|
|
|
|
return SpamRegexBatch::regexesFromMessage( "{$type}-blacklist", $this );
|
2015-10-08 02:18:50 +00:00
|
|
|
}
|
2015-07-28 22:01:39 +00:00
|
|
|
);
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the (local) whitelist
|
|
|
|
*
|
|
|
|
* @return array Regular expressions
|
|
|
|
*/
|
|
|
|
public function getWhitelists() {
|
2015-07-28 22:01:39 +00:00
|
|
|
$type = $this->getBlacklistType();
|
2019-07-03 12:52:16 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2015-07-28 22:01:39 +00:00
|
|
|
|
2018-06-28 13:45:40 +00:00
|
|
|
return $cache->getWithSetCallback(
|
|
|
|
$cache->makeKey( 'spamblacklist', $type, 'whitelist-regex' ),
|
2015-10-08 02:18:50 +00:00
|
|
|
$this->expiryTime,
|
2020-10-24 10:32:18 +00:00
|
|
|
function () use ( $type ) {
|
|
|
|
return SpamRegexBatch::regexesFromMessage( "{$type}-whitelist", $this );
|
2015-10-08 02:18:50 +00:00
|
|
|
}
|
2015-07-28 22:01:39 +00:00
|
|
|
);
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch (possibly cached) remote blacklists.
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-11-02 11:54:59 +00:00
|
|
|
private function getSharedBlacklists() {
|
2012-01-17 06:13:46 +00:00
|
|
|
$listType = $this->getBlacklistType();
|
|
|
|
|
|
|
|
wfDebugLog( 'SpamBlacklist', "Loading $listType regex..." );
|
|
|
|
|
2019-09-12 13:48:50 +00:00
|
|
|
if ( !$this->files ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
# No lists
|
|
|
|
wfDebugLog( 'SpamBlacklist', "no files specified\n" );
|
2017-06-06 16:29:27 +00:00
|
|
|
return [];
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 22:01:39 +00:00
|
|
|
$miss = false;
|
2019-07-03 12:52:16 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2018-06-28 13:45:40 +00:00
|
|
|
$regexes = $cache->getWithSetCallback(
|
2015-07-28 22:01:39 +00:00
|
|
|
// This used to be cached per-site, but that could be bad on a shared
|
|
|
|
// server where not all wikis have the same configuration.
|
2018-06-28 13:45:40 +00:00
|
|
|
$cache->makeKey( 'spamblacklist', $listType, 'shared-blacklist-regex' ),
|
2015-10-08 02:18:50 +00:00
|
|
|
$this->expiryTime,
|
2020-10-24 10:32:18 +00:00
|
|
|
function () use ( &$miss ) {
|
2015-07-28 22:01:39 +00:00
|
|
|
$miss = true;
|
2020-10-24 10:32:18 +00:00
|
|
|
return $this->buildSharedBlacklists();
|
2015-10-08 02:18:50 +00:00
|
|
|
}
|
2015-07-28 22:01:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( !$miss ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "Got shared spam regexes from cache\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $regexes;
|
|
|
|
}
|
|
|
|
|
2015-07-28 22:01:39 +00:00
|
|
|
/**
|
|
|
|
* Clear all primary blacklist cache keys
|
|
|
|
*/
|
2018-11-02 11:54:59 +00:00
|
|
|
public function clearCache() {
|
2012-01-17 06:13:46 +00:00
|
|
|
$listType = $this->getBlacklistType();
|
|
|
|
|
2019-07-03 12:52:16 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2018-06-28 13:45:40 +00:00
|
|
|
$cache->delete( $cache->makeKey( 'spamblacklist', $listType, 'shared-blacklist-regex' ) );
|
|
|
|
$cache->delete( $cache->makeKey( 'spamblacklist', $listType, 'blacklist-regex' ) );
|
|
|
|
$cache->delete( $cache->makeKey( 'spamblacklist', $listType, 'whitelist-regex' ) );
|
2015-07-28 22:01:39 +00:00
|
|
|
|
2012-01-17 06:13:46 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "$listType blacklist local cache cleared.\n" );
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:59 +00:00
|
|
|
private function buildSharedBlacklists() {
|
2017-06-06 16:29:27 +00:00
|
|
|
$regexes = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
$listType = $this->getBlacklistType();
|
|
|
|
# Load lists
|
|
|
|
wfDebugLog( 'SpamBlacklist', "Constructing $listType blacklist\n" );
|
|
|
|
foreach ( $this->files as $fileName ) {
|
2017-06-06 16:29:27 +00:00
|
|
|
$matches = [];
|
2012-01-17 06:13:46 +00:00
|
|
|
if ( preg_match( '/^DB: ([\w-]*) (.*)$/', $fileName, $matches ) ) {
|
|
|
|
$text = $this->getArticleText( $matches[1], $matches[2] );
|
2015-06-15 23:33:58 +00:00
|
|
|
} elseif ( preg_match( '/^(https?:)?\/\//', $fileName ) ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
$text = $this->getHttpText( $fileName );
|
|
|
|
} else {
|
|
|
|
$text = file_get_contents( $fileName );
|
|
|
|
wfDebugLog( 'SpamBlacklist', "got from file $fileName\n" );
|
|
|
|
}
|
|
|
|
|
2019-12-22 05:21:52 +00:00
|
|
|
if ( $text ) {
|
|
|
|
// Build a separate batch of regexes from each source.
|
|
|
|
// While in theory we could squeeze a little efficiency
|
|
|
|
// out of combining multiple sources in one regex, if
|
|
|
|
// there's a bad line in one of them we'll gain more
|
|
|
|
// from only having to break that set into smaller pieces.
|
|
|
|
$regexes = array_merge(
|
|
|
|
$regexes,
|
|
|
|
SpamRegexBatch::regexesFromText( $text, $this, $fileName )
|
|
|
|
);
|
|
|
|
}
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $regexes;
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:54:59 +00:00
|
|
|
private function getHttpText( $fileName ) {
|
2019-08-31 14:40:08 +00:00
|
|
|
global $wgMessageCacheType;
|
|
|
|
// FIXME: This is a hack to use Memcached where possible (incl. WMF),
|
|
|
|
// but have CACHE_DB as fallback (instead of no cache).
|
|
|
|
// This might be a good candidate for T248005.
|
|
|
|
$cache = ObjectCache::getInstance( $wgMessageCacheType );
|
2012-01-17 06:13:46 +00:00
|
|
|
|
2019-08-31 14:40:08 +00:00
|
|
|
$listType = $this->getBlacklistType();
|
|
|
|
// There are two keys, when the warning key expires, a random thread will refresh
|
|
|
|
// the real key. This reduces the chance of multiple requests under high traffic
|
|
|
|
// conditions.
|
|
|
|
$key = $cache->makeGlobalKey( "blacklist_file_{$listType}", $fileName );
|
|
|
|
$warningKey = $cache->makeKey( "filewarning_{$listType}", $fileName );
|
|
|
|
$httpText = $cache->get( $key );
|
|
|
|
$warning = $cache->get( $warningKey );
|
2012-01-17 06:13:46 +00:00
|
|
|
|
|
|
|
if ( !is_string( $httpText ) || ( !$warning && !mt_rand( 0, $this->warningChance ) ) ) {
|
|
|
|
wfDebugLog( 'SpamBlacklist', "Loading $listType blacklist from $fileName\n" );
|
2020-06-07 11:04:51 +00:00
|
|
|
$httpText = MediaWikiServices::getInstance()->getHttpRequestFactory()
|
|
|
|
->get( $fileName, [], __METHOD__ );
|
2017-06-06 16:29:27 +00:00
|
|
|
if ( $httpText === false ) {
|
2012-01-17 06:13:46 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "Error loading $listType blacklist from $fileName\n" );
|
|
|
|
}
|
2019-08-31 14:40:08 +00:00
|
|
|
$cache->set( $warningKey, 1, $this->warningTime );
|
|
|
|
$cache->set( $key, $httpText, $this->expiryTime );
|
2012-01-17 06:13:46 +00:00
|
|
|
} else {
|
|
|
|
wfDebugLog( 'SpamBlacklist', "Got $listType blacklist from HTTP cache for $fileName\n" );
|
|
|
|
}
|
|
|
|
return $httpText;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch an article from this or another local MediaWiki database.
|
|
|
|
*
|
2015-07-28 21:20:19 +00:00
|
|
|
* @param string $wiki
|
2019-09-12 13:48:50 +00:00
|
|
|
* @param string $pagename
|
2019-09-20 10:16:00 +00:00
|
|
|
* @return bool|string|null
|
2012-01-17 06:13:46 +00:00
|
|
|
*/
|
2019-09-12 13:48:50 +00:00
|
|
|
private function getArticleText( $wiki, $pagename ) {
|
2015-07-28 21:20:19 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist',
|
2019-09-12 13:48:50 +00:00
|
|
|
"Fetching {$this->getBlacklistType()} blacklist from '$pagename' on '$wiki'...\n" );
|
2015-07-28 21:20:19 +00:00
|
|
|
|
2019-09-20 10:16:00 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
// XXX: We do not know about custom namespaces on the target wiki here!
|
|
|
|
$title = $services->getTitleParser()->parseTitle( $pagename );
|
|
|
|
$store = $services->getRevisionStoreFactory()->getRevisionStore( $wiki );
|
|
|
|
$rev = $store->getRevisionByTitle( $title );
|
|
|
|
|
|
|
|
$content = $rev ? $rev->getContent( SlotRecord::MAIN ) : null;
|
|
|
|
|
|
|
|
if ( !( $content instanceof TextContent ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $content->getText();
|
|
|
|
}
|
|
|
|
|
2012-01-18 23:29:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the start of the regex for matches
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRegexStart() {
|
|
|
|
return '/[a-z0-9_\-.]*';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the end of the regex for matches
|
|
|
|
*
|
2017-10-07 09:15:06 +00:00
|
|
|
* @param int $batchSize
|
2012-01-18 23:29:37 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRegexEnd( $batchSize ) {
|
2017-06-06 16:29:27 +00:00
|
|
|
return ( $batchSize > 0 ) ? '/Sim' : '/im';
|
2012-01-18 23:29:37 +00:00
|
|
|
}
|
2016-02-16 21:39:06 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-30 21:26:36 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param string[] $entries
|
2020-01-04 11:16:36 +00:00
|
|
|
* @param User $user
|
2016-02-16 21:39:06 +00:00
|
|
|
*/
|
2020-01-04 11:16:36 +00:00
|
|
|
public function warmCachesForFilter( Title $title, array $entries, User $user ) {
|
2016-02-16 21:39:06 +00:00
|
|
|
// subclass this
|
|
|
|
}
|
2012-01-17 06:13:46 +00:00
|
|
|
}
|