37 if ( self::$instance ===
null ) {
38 self::$instance =
new self;
50 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
52 'Can not invoke ' . __METHOD__ .
'() ' .
53 'out of tests (MW_PHPUNIT_TEST not set).'
57 self::$instance =
null;
64 global $wgTitleBlacklistSources, $wgTitleBlacklistCaching;
66 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
68 $cachedBlacklist =
$cache->get(
$cache->makeKey(
'title_blacklist_entries' ) );
69 if ( is_array( $cachedBlacklist ) && count( $cachedBlacklist ) > 0
70 && ( $cachedBlacklist[0]->getFormatVersion() == self::VERSION )
72 $this->mBlacklist = $cachedBlacklist;
76 $sources = $wgTitleBlacklistSources;
77 $sources[
'local'] = [
'type' =>
'message' ];
78 $this->mBlacklist = [];
79 foreach ( $sources as $sourceName =>
$source ) {
80 $this->mBlacklist = array_merge(
82 self::parseBlacklist( self::getBlacklistText(
$source ), $sourceName )
85 $cache->set(
$cache->makeKey(
'title_blacklist_entries' ),
86 $this->mBlacklist, $wgTitleBlacklistCaching[
'expiry'] );
87 wfDebugLog(
'TitleBlacklist-cache',
'Updated ' .
$cache->makeKey(
'title_blacklist_entries' )
88 .
' with ' . count( $this->mBlacklist ) .
' entries.' );
95 global $wgTitleBlacklistCaching;
97 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
98 $cachedWhitelist =
$cache->get(
$cache->makeKey(
'title_whitelist_entries' ) );
99 if ( is_array( $cachedWhitelist ) && count( $cachedWhitelist ) > 0
100 && ( $cachedWhitelist[0]->getFormatVersion() != self::VERSION )
102 $this->mWhitelist = $cachedWhitelist;
106 ->inContentLanguage()->text(),
'whitelist' );
107 $cache->set(
$cache->makeKey(
'title_whitelist_entries' ),
108 $this->mWhitelist, $wgTitleBlacklistCaching[
'expiry'] );
122 if (
$source[
'type'] ==
'message' ) {
123 return wfMessage(
'titleblacklist' )->inContentLanguage()->text();
124 } elseif (
$source[
'type'] ==
'localpage' && count(
$source ) >= 2 ) {
126 if ( is_null(
$title ) ) {
131 if ( !$msg->isDisabled() ) {
137 $page = WikiPage::factory(
$title );
138 if ( $page->exists() ) {
139 return ContentHandler::getContentText( $page->getContent() );
145 if ( file_exists(
$source[
'src'] ) ) {
146 return file_get_contents(
$source[
'src'] );
163 $lines = preg_split(
"/\r?\n/", $list );
191 $params = $entry->getParams();
192 if ( isset( $params[
'autoconfirmed'] ) && $user->isAllowed(
'autoconfirmed' ) ) {
195 if ( $override && self::userCanOverride( $user, $action ) ) {
220 $autoconfirmedItem =
false;
221 foreach ( $blacklist as $item ) {
222 if ( $item->matches(
$title->getFullText(), $action ) ) {
226 $params = $item->getParams();
227 if ( !isset( $params[
'autoconfirmed'] ) ) {
230 if ( !$autoconfirmedItem ) {
231 $autoconfirmedItem = $item;
235 return $autoconfirmedItem;
251 foreach ( $whitelist as $item ) {
252 if ( $item->matches(
$title->getFullText(), $action ) ) {
265 if ( is_null( $this->mBlacklist ) ) {
277 if ( is_null( $this->mWhitelist ) ) {
292 $key =
'title_blacklist_source:' . md5( $url );
293 $warnkey =
$messageMemc->makeKey(
'titleblacklistwarning', md5( $url ) );
297 if ( !is_string( $result )
298 || ( !$warn && !mt_rand( 0, $wgTitleBlacklistCaching[
'warningchance'] ) )
300 $result = Http::get( $url );
301 $messageMemc->set( $warnkey, 1, $wgTitleBlacklistCaching[
'warningexpiry'] );
302 $messageMemc->set( $key, $result, $wgTitleBlacklistCaching[
'expiry'] );
312 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
313 $cache->delete(
$cache->makeKey(
'title_blacklist_entries' ) );
325 foreach ( $blacklist as $e ) {
326 Wikimedia\suppressWarnings();
327 $regex = $e->getRegex();
328 if ( preg_match(
"/{$regex}/u",
'' ) ===
false ) {
329 $badEntries[] = $e->getRaw();
331 Wikimedia\restoreWarnings();
345 return $user->isAllowed(
'tboverride' ) ||
346 ( $action ==
'new-account' && $user->isAllowed(
'tboverride-account' ) );
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Represents a title blacklist entry.
static newFromString( $line, $source)
Create a new TitleBlacklistEntry from a line of text.
Implements a title blacklist for MediaWiki.
static destroySingleton()
Destroy/reset the current singleton instance.
TitleBlacklistEntry[] $mWhitelist
getBlacklist()
Get the current blacklist.
getWhitelist()
Get the current whitelist.
invalidate()
Invalidate the blacklist cache.
static singleton()
Get an instance of this class.
userCannot( $title, $user, $action='edit', $override=true)
Check whether the blacklist restricts given user performing a specific action on the given Title.
static userCanOverride( $user, $action)
Inidcates whether user can override blacklist on certain action.
static parseBlacklist( $list, $sourceName)
Parse blacklist from a string.
static getHttp( $url)
Get the text of a blacklist source via HTTP.
load()
Load all configured blacklist sources.
TitleBlacklistEntry[] $mBlacklist
static TitleBlacklist $instance
validate(array $blacklist)
Validate a new blacklist.
isWhitelisted( $title, $action='edit')
Check whether it has been explicitly whitelisted that the current User may perform a specific action ...
loadWhitelist()
Load local whitelist.
isBlacklisted( $title, $action='edit')
Check whether the blacklist restricts performing a specific action on the given Title.
static getBlacklistText( $source)
Get the text of a blacklist from a specified source.
Represents a title within MediaWiki.