Extension:AbuseFilter

The AbuseFilter extension allows privileged users to set specific actions to be taken when actions by users, such as edits, match certain criteria.

For example, a filter could be created to prevent unregistered users from adding external links, or to block a user who removes more than 2000 characters.

User rights
Once you installed the extension, you'll have to set up the user rights in "LocalSettings.php".

For example, the following sample configuration would allow sysops to do everything they want with AbuseFilter, and everyone to view the log and see public filter settings:

Emergency throttling
AbuseFilter comes with a feature that automatically throttles (disable) filters that have been edited recently and match a certain threshold of the latest actions.

This is done to prevent harmful edits on the filters to block every user that performs an action on the wiki or similar.

The condition to disable the filter depend on those variables:
 * - Percent of matches over the total amount of actions in the observed period.
 * - Count of matches of the filter in the observed period.
 * - Age of the filter to take it into account. If the last edit of the filter is older than this number of seconds, the filter won't be throttled, unless it's already throttled.
 * - Maximum number of recent actions to count against the threshold. Note that each action increments a counter, and once this counter reaches this configured value, this counter and the number of recent actions that matches all filters are reset to 0.

Throttled filters can be identified in the list of filters (Special:AbuseFilter) with the state,. Throttling happens silently, and there's no way to see when a filter got throttled.

When a filter gets throttled, it doesn't perform any dangerous action (actions usually restricted to special rights like blocking the user, or removing it from groups, controlled by $wgAbuseFilterActionRestrictions ), and only "safe" actions are allowed (the ones that can warn or prevent the ongoing action). Throttled filters don't get enabled automatically. To disable the throttling, you need to edit the filter. Note that you need to actually change something from the filter: changing something from the filter's notes is sufficient.

Note that editing the filter updates its age, and can cause it to be disabled if it reaches again the conditions to be throttled in a short period since the last edit, leading to a unusable filter if your wiki has more abuse edits than legitimate ones. Filters can also get randomly throttled if the action count reaches, causing all filter matches count to reset to 0, and then someone repeatedly makes a filter to hit.

Creating and managing filters
Once the extension has been installed, filters can be created/tested/changed/deleted and the logs can be accessed from the Abuse filter management page Special:AbuseFilter.


 * Rules format - The basics of how to write a filter


 * Actions


 * Global Rules


 * Guide to optimizing condition limit usage


 * To import filters from Wikipedia: When you have installed the extension, go to w:Special:AbuseFilter, choose a filter (say w:Special:AbuseFilter/3), then click "Export this filter to another wiki", copy the text, go to "Special:AbuseFilter/import" on your wiki, paste the text.
 * m:Small wiki toolkits/Starter kit/AbuseFilter - A guide for small wiki communities on metawiki

API
AbuseFilter adds two API list modules, one for details of abuse filters ("abusefilters") and one for the abuse log, since it is separate from other MediaWiki logs ("abuselog"). It is not possible to create or modify abuse filters using the API.

list = abusefilters
List information about filters


 * Parameters :
 * - The filter id to start enumerating from
 * - The filter id to stop enumerating at
 * - The direction in which to enumerate (older, newer)
 * - Show only filters which meet these criteria (enabled|!enabled|deleted|!deleted|private|!private)
 * - The maximum number of filters to list
 * - Which properties to get (id|description|pattern|actions|hits|comments|lasteditor|lastedittime|status|private)

When filters are private, some of the properties specified with  will be missing unless you have the appropriate user rights.


 * Examples :

list = abuselog
List instances where actions triggered an abuse filter.


 * Parameters :
 * - The timestamp to start enumerating from
 * - The timestamp to stop enumerating at
 * - The direction in which to enumerate (older, newer)
 * - Show only entries where the action was attempted by a given user or IP address.
 * - Show only entries where the action involved a given page.
 * - Show only entries that triggered a given filter ID
 * - The maximum number of entries to list
 * - Which properties to get: (ids|filter|user|ip|title|action|details|result|timestamp|hidden|revid|wiki)


 * Example :

Possible errors

 * Some users might experience that creating new filters or modifying old filters fail and the user just gets redirected to the original page. If the Wiki is using SSL certificates, this error could possibly be because of the  value, which might be using "http://" instead of "https://". An indication of this error will be, the browser giving https warning for Special:AbuseFilter pages. (Topic:T23dyyih0ofjada5)

Integration with other extensions
You can integrate AbuseFilter with other extension in various ways.

Adding variables for filtering
It is possible to add new variables, to be used in abuse filters. A list of examples. To do that, you should:


 * Add a handler for the hook.  To add a variable, you should use , where  is the name of the variable, and  is the fragment of an i18n key.  The full key will be.
 * Add the i18n messages you chose at the previous point.
 * Choose a hook handler where the variable will be computed. Depending on your use case, you could:
 * Implement the hook; this is specifically thought for page-related variables;
 * Implement the hook; this is specifically thought for user-related variables;
 * Implement the hook; this is for variables not bound to a specific page or user;
 * Implement the hook; this is a bit more flexible than the other hooks, but it has a downside: your variable will not be available when examining past RecentChanges entries.  If you want to implement that feature (and it's recommended to do so), you should use one of the hooks listed above, and use its third parameter.
 * Inside the hook handler, there are two ways to add a variable:
 * The "direct" way is calling . This is ideal only when the value is easy and quick to compute: the value is computed even if no active filter will use it.
 * The "lazy" way is calling .  Here, 'method_name' is a (unique) identifier that will be used to compute the variable (it's recommended to prefix it with the name of your extension).  To register the method, you should add a handler for the  hook; therein, you should check if the $method passed matches your 'method_name', and if so, compute the variable.  Lastly, $params is an array of parameters that you'll need to compute the variable; these are passed to the computeVariable hook handler.  For an example of this, you can check out CentralAuth's.

Adding custom actions
You can add custom action handlers, so that each filter may perform further actions. To do that, you choose a name for the action ('my-action' from now on), and then:


 * Create a class named e.g. MyAction, that should extend \MediaWiki\Extension\AbuseFilter\Consequence , which can also implement HookAborterConsequence or ConsequencesDisablerConsequence
 * Add a subscriber to the AbuseFilterCustomActions hook; the subscriber should provide a callback as documented in the hook documentation, that returns an instance of the class created above, for instance:

Then you should add the following i18n messages; you can replace ' my_action ' with e.g. ' block ' to see what the messages are for:



Adding rule groups
You can also add extra rule groups, which can be used to group existing abuse filters. Note that, at the moment, each filter can only be in a single group ( T116642 ). Currently, the only known consumer of this feature is Extension:StructuredDiscussions. To do that, you should:


 * Append the name of the group to


 * Add some code to run the filters with your group. Note that AbuseFilter won't do that on its own. To do that, you should construct an object, passing in the name of your group.