2007-12-08 21:06:21 +00:00
|
|
|
<?php
|
2008-08-05 15:57:10 +00:00
|
|
|
/**
|
2008-08-08 23:26:44 +00:00
|
|
|
* Title Blacklist class
|
2010-11-08 21:55:05 +00:00
|
|
|
* @author Victor Vasiliev
|
|
|
|
* @copyright © 2007-2010 Victor Vasiliev et al
|
2018-04-07 01:23:42 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2008-08-09 01:54:39 +00:00
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
2022-04-08 13:20:08 +00:00
|
|
|
namespace MediaWiki\Extension\TitleBlacklist;
|
|
|
|
|
2023-06-07 15:12:19 +00:00
|
|
|
use BadMethodCallException;
|
2024-10-20 11:21:48 +00:00
|
|
|
use MediaWiki\Content\TextContent;
|
2019-07-03 12:58:55 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-08-19 04:20:04 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2024-01-04 21:31:38 +00:00
|
|
|
use MediaWiki\User\User;
|
2022-02-24 21:14:12 +00:00
|
|
|
use Wikimedia\AtEase\AtEase;
|
2019-07-03 12:58:55 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
2010-06-06 15:12:22 +00:00
|
|
|
* @ingroup Extensions
|
2008-08-09 01:54:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a title blacklist for MediaWiki
|
2007-12-08 21:06:21 +00:00
|
|
|
*/
|
|
|
|
class TitleBlacklist {
|
2019-12-12 19:15:59 +00:00
|
|
|
/** @var TitleBlacklistEntry[]|null */
|
2017-06-29 17:40:05 +00:00
|
|
|
private $mBlacklist = null;
|
|
|
|
|
2019-12-12 19:15:59 +00:00
|
|
|
/** @var TitleBlacklistEntry[]|null */
|
2017-06-29 17:40:05 +00:00
|
|
|
private $mWhitelist = null;
|
2017-01-23 10:58:52 +00:00
|
|
|
|
2019-12-12 19:15:59 +00:00
|
|
|
/** @var TitleBlacklist|null */
|
2017-01-23 10:58:52 +00:00
|
|
|
protected static $instance = null;
|
|
|
|
|
2024-08-16 13:36:25 +00:00
|
|
|
/** Increase this to invalidate the cached copies of both blacklist and whitelist */
|
2022-05-03 21:22:50 +00:00
|
|
|
public const VERSION = 4;
|
2007-12-08 21:06:21 +00:00
|
|
|
|
2011-07-30 15:13:28 +00:00
|
|
|
/**
|
|
|
|
* Get an instance of this class
|
|
|
|
*/
|
2024-08-16 14:01:20 +00:00
|
|
|
public static function singleton(): self {
|
|
|
|
self::$instance ??= new self();
|
2017-01-23 10:58:52 +00:00
|
|
|
return self::$instance;
|
|
|
|
}
|
2011-07-30 15:13:28 +00:00
|
|
|
|
2017-01-23 10:58:52 +00:00
|
|
|
/**
|
|
|
|
* Destroy/reset the current singleton instance.
|
|
|
|
*
|
|
|
|
* This is solely for testing and will fail unless MW_PHPUNIT_TEST is
|
|
|
|
* defined.
|
|
|
|
*/
|
|
|
|
public static function destroySingleton() {
|
|
|
|
if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
|
2023-06-07 15:12:19 +00:00
|
|
|
throw new BadMethodCallException(
|
2017-01-23 10:58:52 +00:00
|
|
|
'Can not invoke ' . __METHOD__ . '() ' .
|
|
|
|
'out of tests (MW_PHPUNIT_TEST not set).'
|
|
|
|
);
|
2011-07-30 15:13:28 +00:00
|
|
|
}
|
2017-01-23 10:58:52 +00:00
|
|
|
|
|
|
|
self::$instance = null;
|
2011-07-30 15:13:28 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Load all configured blacklist sources
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2007-12-08 21:06:21 +00:00
|
|
|
public function load() {
|
2015-04-29 21:25:24 +00:00
|
|
|
global $wgTitleBlacklistSources, $wgTitleBlacklistCaching;
|
|
|
|
|
2019-07-03 12:58:55 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2012-08-29 13:53:38 +00:00
|
|
|
// Try to find something in the cache
|
2024-08-16 13:36:25 +00:00
|
|
|
/** @var TitleBlacklistEntry[]|false $cachedBlacklist */
|
2018-06-28 13:46:07 +00:00
|
|
|
$cachedBlacklist = $cache->get( $cache->makeKey( 'title_blacklist_entries' ) );
|
2024-08-16 13:36:25 +00:00
|
|
|
if ( $cachedBlacklist &&
|
|
|
|
is_array( $cachedBlacklist ) &&
|
|
|
|
$cachedBlacklist[0]->getFormatVersion() == self::VERSION
|
2017-06-02 15:43:58 +00:00
|
|
|
) {
|
2007-12-19 18:35:44 +00:00
|
|
|
$this->mBlacklist = $cachedBlacklist;
|
|
|
|
return;
|
|
|
|
}
|
2007-12-23 09:47:36 +00:00
|
|
|
|
2007-12-09 12:15:13 +00:00
|
|
|
$sources = $wgTitleBlacklistSources;
|
2017-06-06 16:18:36 +00:00
|
|
|
$sources['local'] = [ 'type' => 'message' ];
|
|
|
|
$this->mBlacklist = [];
|
|
|
|
foreach ( $sources as $sourceName => $source ) {
|
2017-06-02 15:43:58 +00:00
|
|
|
$this->mBlacklist = array_merge(
|
|
|
|
$this->mBlacklist,
|
2019-04-27 04:30:31 +00:00
|
|
|
self::parseBlacklist( self::getBlacklistText( $source ), $sourceName )
|
2017-06-02 15:43:58 +00:00
|
|
|
);
|
2007-12-09 12:15:13 +00:00
|
|
|
}
|
2018-06-28 13:46:07 +00:00
|
|
|
$cache->set( $cache->makeKey( 'title_blacklist_entries' ),
|
2017-06-02 15:43:58 +00:00
|
|
|
$this->mBlacklist, $wgTitleBlacklistCaching['expiry'] );
|
2018-06-28 13:46:07 +00:00
|
|
|
wfDebugLog( 'TitleBlacklist-cache', 'Updated ' . $cache->makeKey( 'title_blacklist_entries' )
|
2015-01-06 00:38:46 +00:00
|
|
|
. ' with ' . count( $this->mBlacklist ) . ' entries.' );
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
2008-01-08 18:00:59 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
2012-05-24 23:55:22 +00:00
|
|
|
* Load local whitelist
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2008-01-08 18:00:59 +00:00
|
|
|
public function loadWhitelist() {
|
2015-04-29 21:25:24 +00:00
|
|
|
global $wgTitleBlacklistCaching;
|
|
|
|
|
2019-07-03 12:58:55 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2024-08-16 13:36:25 +00:00
|
|
|
/** @var TitleBlacklistEntry[]|false $cachedWhitelist */
|
2018-06-28 13:46:07 +00:00
|
|
|
$cachedWhitelist = $cache->get( $cache->makeKey( 'title_whitelist_entries' ) );
|
2024-08-16 13:36:25 +00:00
|
|
|
if ( $cachedWhitelist &&
|
|
|
|
is_array( $cachedWhitelist ) &&
|
|
|
|
$cachedWhitelist[0]->getFormatVersion() == self::VERSION
|
2017-06-02 15:43:58 +00:00
|
|
|
) {
|
2008-01-08 18:00:59 +00:00
|
|
|
$this->mWhitelist = $cachedWhitelist;
|
|
|
|
return;
|
|
|
|
}
|
2019-04-27 04:30:31 +00:00
|
|
|
$this->mWhitelist = self::parseBlacklist( wfMessage( 'titlewhitelist' )
|
2012-05-24 23:55:22 +00:00
|
|
|
->inContentLanguage()->text(), 'whitelist' );
|
2018-06-28 13:46:07 +00:00
|
|
|
$cache->set( $cache->makeKey( 'title_whitelist_entries' ),
|
2017-06-02 15:43:58 +00:00
|
|
|
$this->mWhitelist, $wgTitleBlacklistCaching['expiry'] );
|
2008-01-08 18:00:59 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Get the text of a blacklist from a specified source
|
|
|
|
*
|
2024-08-16 14:01:20 +00:00
|
|
|
* @param array{type: string, src: ?string} $source A blacklist source from $wgTitleBlacklistSources
|
2016-10-08 12:04:58 +00:00
|
|
|
* @return string The content of the blacklist source as a string
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2008-08-09 01:54:39 +00:00
|
|
|
private static function getBlacklistText( $source ) {
|
2024-08-16 14:01:20 +00:00
|
|
|
if ( !is_array( $source ) || !isset( $source['type'] ) ) {
|
2022-04-08 13:20:55 +00:00
|
|
|
// Return empty string in error case
|
|
|
|
return '';
|
2007-12-09 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
2024-08-16 14:01:20 +00:00
|
|
|
if ( $source['type'] === 'message' ) {
|
2012-08-29 13:53:38 +00:00
|
|
|
return wfMessage( 'titleblacklist' )->inContentLanguage()->text();
|
2024-08-16 14:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$src = $source['src'] ?? null;
|
|
|
|
// All following types require the "src" element in the array
|
|
|
|
if ( !$src ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $source['type'] === 'localpage' ) {
|
|
|
|
$title = Title::newFromText( $src );
|
|
|
|
if ( !$title ) {
|
2007-12-09 12:15:13 +00:00
|
|
|
return '';
|
|
|
|
}
|
2024-08-16 14:01:20 +00:00
|
|
|
if ( $title->inNamespace( NS_MEDIAWIKI ) ) {
|
2016-02-27 18:21:20 +00:00
|
|
|
$msg = wfMessage( $title->getText() )->inContentLanguage();
|
2022-09-29 14:12:21 +00:00
|
|
|
return $msg->isDisabled() ? '' : $msg->text();
|
2007-12-09 12:15:13 +00:00
|
|
|
} else {
|
2021-12-14 11:32:13 +00:00
|
|
|
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
2016-10-08 12:04:58 +00:00
|
|
|
if ( $page->exists() ) {
|
2021-05-17 22:37:41 +00:00
|
|
|
$content = $page->getContent();
|
|
|
|
return ( $content instanceof TextContent ) ? $content->getText() : "";
|
2007-12-09 12:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-16 14:01:20 +00:00
|
|
|
} elseif ( $source['type'] === 'url' ) {
|
|
|
|
return self::getHttp( $src );
|
|
|
|
} elseif ( $source['type'] === 'file' ) {
|
|
|
|
return file_exists( $src ) ? file_get_contents( $src ) : '';
|
2007-12-09 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
2011-03-22 23:07:21 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Parse blacklist from a string
|
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param string $list Text of a blacklist source
|
|
|
|
* @param string $sourceName
|
2019-04-27 04:30:31 +00:00
|
|
|
* @return TitleBlacklistEntry[]
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2012-05-24 23:55:22 +00:00
|
|
|
public static function parseBlacklist( $list, $sourceName ) {
|
2007-12-08 21:06:21 +00:00
|
|
|
$lines = preg_split( "/\r?\n/", $list );
|
2017-06-06 16:18:36 +00:00
|
|
|
$result = [];
|
2011-03-22 23:07:21 +00:00
|
|
|
foreach ( $lines as $line ) {
|
2019-04-27 04:30:31 +00:00
|
|
|
$entry = TitleBlacklistEntry::newFromString( $line, $sourceName );
|
|
|
|
if ( $entry ) {
|
|
|
|
$result[] = $entry;
|
2007-12-10 19:02:38 +00:00
|
|
|
}
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 13:52:05 +00:00
|
|
|
return $result;
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
2015-09-10 23:48:04 +00:00
|
|
|
* Check whether the blacklist restricts given user
|
2010-11-08 21:55:05 +00:00
|
|
|
* performing a specific action on the given Title
|
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param Title $title Title to check
|
|
|
|
* @param User $user User to check
|
|
|
|
* @param string $action Action to check; 'edit' if unspecified
|
|
|
|
* @param bool $override If set to true, overrides work
|
2012-09-24 09:24:32 +00:00
|
|
|
* @return TitleBlacklistEntry|bool The corresponding TitleBlacklistEntry if
|
|
|
|
* blacklisted; otherwise false
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2010-11-08 21:55:05 +00:00
|
|
|
public function userCannot( $title, $user, $action = 'edit', $override = true ) {
|
2015-09-10 23:48:04 +00:00
|
|
|
$entry = $this->isBlacklisted( $title, $action );
|
|
|
|
if ( !$entry ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$params = $entry->getParams();
|
|
|
|
if ( isset( $params['autoconfirmed'] ) && $user->isAllowed( 'autoconfirmed' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( $override && self::userCanOverride( $user, $action ) ) {
|
2010-11-08 21:55:05 +00:00
|
|
|
return false;
|
2011-08-22 20:37:26 +00:00
|
|
|
}
|
2015-09-10 23:48:04 +00:00
|
|
|
return $entry;
|
2010-11-08 21:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-22 22:30:23 +00:00
|
|
|
* Check whether the blacklist restricts
|
2008-08-09 01:54:39 +00:00
|
|
|
* performing a specific action on the given Title
|
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param Title $title Title to check
|
|
|
|
* @param string $action Action to check; 'edit' if unspecified
|
2012-09-24 09:24:32 +00:00
|
|
|
* @return TitleBlacklistEntry|bool The corresponding TitleBlacklistEntry if blacklisted;
|
2008-08-09 01:54:39 +00:00
|
|
|
* otherwise FALSE
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2007-12-10 19:02:38 +00:00
|
|
|
public function isBlacklisted( $title, $action = 'edit' ) {
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( !( $title instanceof Title ) ) {
|
2009-05-17 14:12:38 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2024-08-16 13:58:10 +00:00
|
|
|
if ( !$title ) {
|
2014-01-07 18:08:24 +00:00
|
|
|
// The fact that the page name is invalid will stop whatever
|
|
|
|
// action is going through. No sense in doing more work here.
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
2024-08-16 13:58:10 +00:00
|
|
|
|
|
|
|
$autoconfirmedItem = null;
|
|
|
|
foreach ( $this->getBlacklist() as $item ) {
|
2013-09-08 04:24:56 +00:00
|
|
|
if ( $item->matches( $title->getFullText(), $action ) ) {
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( $this->isWhitelisted( $title, $action ) ) {
|
2008-01-08 18:00:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2024-08-16 13:58:10 +00:00
|
|
|
if ( !isset( $item->getParams()['autoconfirmed'] ) ) {
|
2014-01-07 18:08:24 +00:00
|
|
|
return $item;
|
|
|
|
}
|
2024-08-16 13:58:10 +00:00
|
|
|
$autoconfirmedItem ??= $item;
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-16 13:58:10 +00:00
|
|
|
return $autoconfirmedItem ?? false;
|
2007-12-08 21:06:21 +00:00
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
2011-03-22 22:30:23 +00:00
|
|
|
* Check whether it has been explicitly whitelisted that the
|
2008-08-09 01:54:39 +00:00
|
|
|
* current User may perform a specific action on the given Title
|
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param Title $title Title to check
|
|
|
|
* @param string $action Action to check; 'edit' if unspecified
|
2012-09-24 09:24:32 +00:00
|
|
|
* @return bool True if whitelisted; otherwise false
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2008-01-08 18:00:59 +00:00
|
|
|
public function isWhitelisted( $title, $action = 'edit' ) {
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( !( $title instanceof Title ) ) {
|
2009-05-17 14:12:38 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2024-10-07 08:16:42 +00:00
|
|
|
if ( !$title ) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-08 18:00:59 +00:00
|
|
|
}
|
|
|
|
$whitelist = $this->getWhitelist();
|
2012-08-29 13:53:38 +00:00
|
|
|
foreach ( $whitelist as $item ) {
|
2013-09-08 04:24:56 +00:00
|
|
|
if ( $item->matches( $title->getFullText(), $action ) ) {
|
2008-01-08 18:00:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Get the current blacklist
|
|
|
|
*
|
2015-09-11 00:08:09 +00:00
|
|
|
* @return TitleBlacklistEntry[]
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2007-12-08 21:06:21 +00:00
|
|
|
public function getBlacklist() {
|
2020-01-15 09:20:49 +00:00
|
|
|
if ( $this->mBlacklist === null ) {
|
2007-12-08 21:06:21 +00:00
|
|
|
$this->load();
|
|
|
|
}
|
|
|
|
return $this->mBlacklist;
|
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2011-08-22 20:37:26 +00:00
|
|
|
/**
|
2008-08-09 01:54:39 +00:00
|
|
|
* Get the current whitelist
|
|
|
|
*
|
2019-04-27 04:30:31 +00:00
|
|
|
* @return TitleBlacklistEntry[]
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2008-01-08 18:00:59 +00:00
|
|
|
public function getWhitelist() {
|
2020-01-15 09:20:49 +00:00
|
|
|
if ( $this->mWhitelist === null ) {
|
2008-01-08 18:00:59 +00:00
|
|
|
$this->loadWhitelist();
|
|
|
|
}
|
|
|
|
return $this->mWhitelist;
|
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Get the text of a blacklist source via HTTP
|
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param string $url URL of the blacklist source
|
2011-08-22 20:37:26 +00:00
|
|
|
* @return string The content of the blacklist source as a string
|
2011-03-14 23:44:41 +00:00
|
|
|
*/
|
2008-08-09 01:54:39 +00:00
|
|
|
private static function getHttp( $url ) {
|
2019-08-31 14:06:01 +00:00
|
|
|
global $wgTitleBlacklistCaching, $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.
|
2024-05-21 00:26:38 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$cache = $services->getObjectCacheFactory()->getInstance( $wgMessageCacheType );
|
2018-06-28 13:46:07 +00:00
|
|
|
|
2019-08-31 14:06:01 +00:00
|
|
|
// Globally shared
|
|
|
|
$key = $cache->makeGlobalKey( 'title_blacklist_source', md5( $url ) );
|
|
|
|
// Per-wiki
|
|
|
|
$warnkey = $cache->makeKey( 'titleblacklistwarning', md5( $url ) );
|
|
|
|
|
|
|
|
$result = $cache->get( $key );
|
|
|
|
$warn = $cache->get( $warnkey );
|
2018-06-28 13:46:07 +00:00
|
|
|
|
2017-06-02 15:43:58 +00:00
|
|
|
if ( !is_string( $result )
|
|
|
|
|| ( !$warn && !mt_rand( 0, $wgTitleBlacklistCaching['warningchance'] ) )
|
|
|
|
) {
|
2020-06-07 11:03:50 +00:00
|
|
|
$result = MediaWikiServices::getInstance()->getHttpRequestFactory()
|
|
|
|
->get( $url, [], __METHOD__ );
|
2019-08-31 14:06:01 +00:00
|
|
|
$cache->set( $warnkey, 1, $wgTitleBlacklistCaching['warningexpiry'] );
|
|
|
|
$cache->set( $key, $result, $wgTitleBlacklistCaching['expiry'] );
|
2020-06-07 11:03:50 +00:00
|
|
|
if ( !$result ) {
|
|
|
|
wfDebugLog( 'TitleBlacklist-cache', "Error loading title blacklist from $url\n" );
|
|
|
|
$result = '';
|
|
|
|
}
|
2007-12-19 18:35:44 +00:00
|
|
|
}
|
2018-06-28 13:46:07 +00:00
|
|
|
|
2007-12-19 18:35:44 +00:00
|
|
|
return $result;
|
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Invalidate the blacklist cache
|
|
|
|
*/
|
2007-12-23 09:47:36 +00:00
|
|
|
public function invalidate() {
|
2019-07-03 12:58:55 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2018-06-28 13:46:07 +00:00
|
|
|
$cache->delete( $cache->makeKey( 'title_blacklist_entries' ) );
|
2007-12-23 09:47:36 +00:00
|
|
|
}
|
2011-08-22 20:37:26 +00:00
|
|
|
|
2008-08-09 01:54:39 +00:00
|
|
|
/**
|
|
|
|
* Validate a new blacklist
|
|
|
|
*
|
2017-12-24 03:17:33 +00:00
|
|
|
* @suppress PhanParamSuspiciousOrder The preg_match() params are in the correct order
|
2019-04-27 04:30:31 +00:00
|
|
|
* @param TitleBlacklistEntry[] $blacklist
|
|
|
|
* @return string[] List of invalid entries; empty array means blacklist is valid
|
2008-08-09 01:54:39 +00:00
|
|
|
*/
|
2019-06-05 16:27:36 +00:00
|
|
|
public function validate( array $blacklist ) {
|
2017-06-06 16:18:36 +00:00
|
|
|
$badEntries = [];
|
2012-08-29 13:53:38 +00:00
|
|
|
foreach ( $blacklist as $e ) {
|
2022-02-24 21:14:12 +00:00
|
|
|
AtEase::suppressWarnings();
|
2007-12-23 09:47:36 +00:00
|
|
|
$regex = $e->getRegex();
|
2020-12-20 04:01:58 +00:00
|
|
|
// @phan-suppress-next-line SecurityCheck-ReDoS
|
2012-08-29 13:53:38 +00:00
|
|
|
if ( preg_match( "/{$regex}/u", '' ) === false ) {
|
2007-12-23 09:47:36 +00:00
|
|
|
$badEntries[] = $e->getRaw();
|
2011-03-22 23:07:21 +00:00
|
|
|
}
|
2022-02-24 21:14:12 +00:00
|
|
|
AtEase::restoreWarnings();
|
2007-12-23 09:47:36 +00:00
|
|
|
}
|
|
|
|
return $badEntries;
|
|
|
|
}
|
2011-03-22 22:30:23 +00:00
|
|
|
|
2010-11-08 21:55:05 +00:00
|
|
|
/**
|
2021-10-14 05:48:54 +00:00
|
|
|
* Indicates whether user can override blacklist on certain action.
|
2011-08-22 20:37:26 +00:00
|
|
|
*
|
2017-08-10 11:26:29 +00:00
|
|
|
* @param User $user
|
2022-09-29 14:12:21 +00:00
|
|
|
* @param string $action
|
2011-08-22 20:37:26 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2010-11-08 21:55:05 +00:00
|
|
|
*/
|
2011-09-22 06:10:45 +00:00
|
|
|
public static function userCanOverride( $user, $action ) {
|
|
|
|
return $user->isAllowed( 'tboverride' ) ||
|
|
|
|
( $action == 'new-account' && $user->isAllowed( 'tboverride-account' ) );
|
2010-11-08 21:55:05 +00:00
|
|
|
}
|
2007-12-10 19:02:38 +00:00
|
|
|
}
|