can you tell me how abuse filters on the MediaWiki AbuseFilter extension work
- User
can you tell me how abuse filters on the MediaWiki AbuseFilter extension work
- Assistant
Here’s an overview of how AbuseFilter works in MediaWiki, step by step—plus a simple example to illustrate:
1. What AbuseFilter Is For
- Goal: Catch (or block) vandalism, spam or other unwanted edits/transitions before they’re committed.
- Scope: Edits, moves, deletions, account creations, logins, uploads, imports, etc.
2. How Filters Are Defined
Each filter is a row in the
abuse_filterDB table. The key fields are:af_description– human-readable name.af_eventtype– which action(s) to watch (e.g.edit,move,upload,login).af_filter– the criteria (a Boolean expression) that determines when the filter “fires.”af_action– what happens on a match:warning(show a soft warning, but let the user continue),disallow(block the action),tag(mark the page/watchlist),no-op(just log it).
af_tags– custom tags to add to the action, useful for logging or page categories.
3. What the Criteria Language Looks Like
Filters are written in a little DSL that MediaWiki parses and evaluates. You can mix:
- Variables:
user_editcount,user_registration,is_anon, …old_wikitext,new_wikitext,comment,title,target_title(for moves)- Numeric values like
change_size(new bytes minus old bytes)
- Operators:
=,!=,<,>,<=,>= - Regex matches:
=~and!~ - Logical connectives:
&(AND),|(OR),!(NOT), parentheses.
Example criterion:
is_anon & change_size > 2000 & comment =~ /http:\/\/\S+/This fires if an anonymous user adds more than 2 000 bytes and includes an HTTP link in the edit summary.
4. Evaluation Flow
- Event occurs (e.g. a user clicks “Save” on an edit).
- MediaWiki gathers all relevant filters for that event type (e.g. every
af_eventtype='edit'). - For each filter (in ascending
af_idorder):
a. The DSL expression is evaluated against the edit’s data.
b. If it evaluates to true, MediaWiki applies the filter’s action.- If it’s a warning, the user sees a message and can override.
- If it’s disallow, the edit is blocked outright.
- If it’s tag, the edit gets a log tag but proceeds.
- no-op just records that the filter matched, for analytics.
- Filters are cumulative; a disallowed edit short-circuits immediately, but warnings and tags can stack.
5. Common Built-In Functions & Variables
Name Description is_anontrue if the user is not logged in user_editcountthe editor’s total past edits commentthe edit summary titlethe page title being edited new_wikitextthe entire new page text old_wikitextthe entire old page text change_sizebyte-delta (new_length – old_length) count(matches())count of regex matches in supplied text namespacenumeric namespace ID (e.g. 0for main)target_titlefor moves, the destination page title You can also write custom parser-function extensions so power users can factor out common tests.
6. A Full Mini-Example
Let’s say you want to warn low-rep users who add three or more external links to an article:
# 1. Create a new filter with: af_eventtype: edit af_action: warning af_tags: "spam-links" # 2. Add this as the filter expression: is_anon = false & user_editcount < 20 & count( new_wikitext, /(https?:\/\/\S+)/ ) >= 3 # And a custom warning message: “You’re new here and linking out a lot—please make sure your links are relevant.”- When an edit comes in, MediaWiki runs this test.
- If the user has < 20 edits and their new text has ≥ 3 “http://…” URLs, they see your warning.
7. Best Practices & Tips
- Order your filters: cheap/easy ones first, to short-circuit heavy regexes.
- Test in dry-run: set
af_action=no-opuntil you’re confident. - Use tags liberally—makes logging/monitoring in RecentChanges much easier.
- Document each filter well (description + internal comments), so other admins understand your logic.
That’s the core of how MediaWiki’s AbuseFilter catches unwanted actions. You define Boolean expressions over edit/login properties, assign actions, and when an event fires MediaWiki runs each filter in turn, applying warnings or blocks as needed. Let me know if you’d like more details on any part of it!
- User
Write an example of an abuse filter that could be hypothetically deployed to a MediaWiki wiki that uses this extension
- Assistant
Here’s a self-contained example of an AbuseFilter you might add to your wiki to block spammy page creations that contain too many external links.
-- a row in the abuse_filter table -- af_id = 100 af_description = "Disallow new pages by anon users with >2 external links" af_eventtype = "create" af_filter = namespace = 0 & is_anon & count( new_wikitext, /(https?:\/\/\S+)/ ) > 2 af_action = "disallow" af_tags = "spamlink"Breakdown of the expression:
namespace = 0
Only applies to articles in the main namespace.is_anon
Only matches if the editor is not logged in.count( new_wikitext, /(https?:\/\/\S+)/ ) > 2
Counts how many “http://…” or “https://…” links appear in the new page, and fires if more than 2.
When an anonymous user tries to create a new article containing 3 or more external URLs, the filter will block (“disallow”) the save and show the standard AbuseFilter error page.
—
If you prefer to just warn (but allow) on first attempts, change
af_action = "warning"
and supply a custom notice in MediaWiki’sMediaWiki:Abusefilter-warning-100like:“Please don’t dump multiple external links onto a brand-new page. If you need to link out, make sure each link is directly relevant to the topic.”
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.