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' ),
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' ),
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() ) {
138 if ( $page->exists() ) {
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'] ) )
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' ) );