Go to the documentation of this file.
44 'spam' =>
'SpamBlacklist',
45 'email' =>
'EmailBlacklist',
81 self::$blacklistTypes[
$type] = $class;
101 if ( !isset( self::$blacklistTypes[
$type] ) ) {
102 throw new Exception(
"Invalid blacklist type '$type' passed to " . __METHOD__ );
105 if ( !isset( self::$instances[
$type] ) ) {
106 global $wgBlacklistSettings;
109 if ( !isset( $wgBlacklistSettings[
$type] ) ) {
113 $class = self::$blacklistTypes[
$type];
114 self::$instances[
$type] =
new $class( $wgBlacklistSettings[
$type] );
117 return self::$instances[
$type];
138 foreach ( self::$blacklistTypes
as $type => $class ) {
146 if( in_array(
$title->getDBkey(), $sources ) ) {
152 $thisHttpRegex =
'/^' . preg_quote( $thisHttp,
'/' ) .
'(?:&.*)?$/';
155 foreach ( self::$blacklistTypes
as $type => $class ) {
156 if ( isset( $wgBlacklistSettings[
$type][
'files'] ) ) {
163 if ( preg_match(
'/^DB: (\w*) (.*)$/', $fileName,
$matches ) ) {
170 } elseif( preg_match( $thisHttpRegex, $fileName ) ) {
186 $types = array_map(
'preg_quote', array_keys( self::$blacklistTypes ),
array(
'/' ) );
187 $regex =
'/(' . implode(
'|', $types ).
')-(?:Blacklist|Whitelist)/';
189 if ( preg_match( $regex,
$title->getDBkey(), $m ) ) {
190 return strtolower( $m[1] );
202 if( $this->regexes ===
false ) {
203 $this->regexes = array_merge(
253 wfDebugLog(
'SpamBlacklist',
"Loading $listType regex..." );
257 wfDebugLog(
'SpamBlacklist',
"no files specified\n" );
267 wfMemcKey(
'spamblacklist', $listType,
'shared-blacklist-regex' ),
269 function ()
use ( $that, &$miss ) {
271 return $that->buildSharedBlacklists();
276 wfDebugLog(
'SpamBlacklist',
"Got shared spam regexes from cache\n" );
291 $cache->delete(
wfMemcKey(
'spamblacklist', $listType,
'shared-blacklist-regex' ) );
292 $cache->delete(
wfMemcKey(
'spamblacklist', $listType,
'blacklist-regex' ) );
293 $cache->delete(
wfMemcKey(
'spamblacklist', $listType,
'whitelist-regex' ) );
295 wfDebugLog(
'SpamBlacklist',
"$listType blacklist local cache cleared.\n" );
302 wfDebugLog(
'SpamBlacklist',
"Constructing $listType blacklist\n" );
303 foreach ( $this->
files as $fileName ) {
305 if ( preg_match(
'/^DB: ([\w-]*) (.*)$/', $fileName,
$matches ) ) {
307 } elseif ( preg_match(
'/^(https?:)?\/\//', $fileName ) ) {
310 $text = file_get_contents( $fileName );
311 wfDebugLog(
'SpamBlacklist',
"got from file $fileName\n" );
331 # To keep requests to a minimum, we save results into $messageMemc, which is
332 # similar to $wgMemc except almost certain to exist. By default, it is stored
335 # There are two keys, when the warning key expires, a random thread will refresh
336 # the real key. This reduces the chance of multiple requests under high traffic
338 $key =
"{$listType}_blacklist_file:$fileName";
339 $warningKey =
"$wgDBname:{$listType}filewarning:$fileName";
343 if ( !is_string( $httpText ) || ( !$warning && !mt_rand( 0, $this->warningChance ) ) ) {
344 wfDebugLog(
'SpamBlacklist',
"Loading $listType blacklist from $fileName\n" );
346 if( $httpText ===
false ) {
347 wfDebugLog(
'SpamBlacklist',
"Error loading $listType blacklist from $fileName\n" );
349 $messageMemc->set( $warningKey, 1, $this->warningTime );
350 $messageMemc->set( $key, $httpText, $this->expiryTime );
352 wfDebugLog(
'SpamBlacklist',
"Got $listType blacklist from HTTP cache for $fileName\n" );
367 "Fetching {$this->getBlacklistType()} blacklist from '$article' on '$wiki'...\n" );
374 array(
'page',
'revision',
'text' ),
381 'page_namespace' =>
$title->getNamespace(),
382 'page_title' =>
$title->getDBkey(),
383 'rev_id=page_latest',
400 return '/[a-z0-9_\-.]*';
410 return ($batchSize > 0 ) ?
'/Sim' :
'/im';
static getBlacklistTypes()
Return the array of blacklist types currently defined.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static getInstance( $type)
Returns an instance of the given blacklist.
getRegexEnd( $batchSize)
Returns the end of the regex for matches.
getBlacklists()
Fetch local and (possibly cached) remote blacklists.
__construct( $settings=array())
Constructor.
getBlacklistType()
Returns the code for the blacklist implementation.
getArticleText( $wiki, $article)
Fetch an article from this or another local MediaWiki database.
array $files
Array of blacklist sources.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
static isLocalSource(Title $title)
Check if the given local page title is a spam regex source.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $messageMemc
static addBlacklistType( $type, $class)
Adds a blacklist class to the registry.
static getTypeFromTitle(Title $title)
Returns the type of blacklist from the given title.
Allows to change the fields on the form that will be generated $name
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static regexesFromText( $source, BaseBlacklist $blacklist, $fileName=false)
Build a set of regular expressions from the given multiline input text, with empty lines and comments...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static selectTextFields()
Return the list of text fields that should be selected to read the revision text.
static array $blacklistTypes
Array containing blacklists that extend BaseBlacklist.
wfMemcKey()
Make a cache key for the local wiki.
namespace and then decline to actually register it file or subcat img or subcat $title
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
getLocalBlacklists()
Returns the local blacklist.
Base class for different kinds of blacklists.
clearCache()
Clear all primary blacklist cache keys.
static regexesFromMessage( $message, BaseBlacklist $blacklist)
Build a set of regular expressions from a MediaWiki message.
when a variable name is used in a it is silently declared as a new masking the global
getSharedBlacklists()
Fetch (possibly cached) remote blacklists.
static selectPageFields()
Return the list of page fields that should be selected from page table.
static get( $url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
bool array $regexes
Array containing regexes to test against.
warmCachesForFilter(Title $title, array $entries)
filter(array $links, Title $title, $preventLog=false)
static array $instances
Array of blacklist instances.
Represents a title within MediaWiki.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
static getMainWANInstance()
Get the main WAN cache object.
int $warningChance
Chance of receiving a warning when the filter is hit.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
getWhitelists()
Returns the (local) whitelist.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
the array() calling protocol came about after MediaWiki 1.4rc1.
getRegexStart()
Returns the start of the regex for matches.