User:松/Drafts/Extension:AbuseFilter/Rules format

The rules are formatted much as conditionals in a C/Java/Perl-like language.

Literals
You can specify a literal by placing it in single or double quotes (for strings), or by typing it in as-is (for numbers, both floating-point and integer). You can get linebreaks with \n, tab characters with \t, and you can also escape the quote character with a backslash. "This is a string" 'This is also a string' 'This string shouldn\'t fail' "This string\nHas a linebreak" 1234 1.234 -123
 * Examples:

Variables
The abuse filter passes various variables by name into the parser. These variables can be accessed by typing their name in, in a place where a literal would work. You can view the variables associated with each request in the abuse log. USER_EDITCOUNT ARTICLE_RECENT_CONTRIBUTORS
 * Examples:

Action variable can be,   or. As of May 1, 2009, uploads seem to be completely ignored by Abuse Filter.

You can define more variables for ease of understanding with the assign symbol := in a line (closed by ;) within a condition. Example (from w:en:Special:AbuseFilter/79): (line1:="(\{\{(r|R)eflist|\{\{(r|R)efs\}\}||)"; rcount(line1, removed_lines)) > (rcount(line1, added_lines))

Page/Article Namespace
See also Manual:Namespace

Simple comparisons
You can compare variables with other variables and literals with the following syntax:
 * &lt; and &gt; &mdash; Return true if the left-hand operand is less than/greater than the right-hand operand respectively.
 * &lt;= and &gt;=</tt> &mdash; Return true if the left-hand operand is less than or equal to/greater than or equal to the right-hand operand respectively.
 * ==</tt> and !=</tt> &mdash; Return true if the left-hand operand is equal to/not equal to the right-hand operand respectively.
 * ===</tt> and !==</tt> &mdash; Return true if the left-hand operand is equal to/not equal to the right-hand operand AND the left-hand operand is the same/not the same data type to the right-hand operand respectively.

Arithmetic
You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax:
 * -</tt> &mdash; Subtract the right-hand operand from the left-hand operand.
 * +</tt> &mdash; Add the right-hand operand to the left-hand operand.
 * *</tt> &mdash; Multiply the left-hand operand by the right-hand operand.
 * /</tt> &mdash; Divide the left-hand operand by the right-hand operand.
 * **</tt> &mdash; Raise the left-hand operand to the exponential power specified by the right-hand operand.
 * %</tt> &mdash; Return the remainder given when the left-hand operand is divided by the right-hand operand.

Keywords
The following special keywords are included for often-used functionality:
 * like</tt> returns true if the left-hand operand matches the glob pattern in the right-hand operand.
 * in</tt> returns true if the right-hand operand (a string) contains the left-hand operand.
 * rlike</tt> and regex</tt> return true if the left-hand operand matches (contains) the regex pattern in the right-hand operand. The system uses PCRE.

"1234" like "12?4" Result: True "1234" like "12*" Result: True "foo" in "foobar" Result: True "foo" regex "\w+" Result: True
 * Examples:

Functions
A number of built-in functions are included to ease some common issues. They are executed in the general format functionName(arg1,arg2,arg3)</tt>, and can be used in place of any literal or variable. Its arguments can be given as literals, variables, or even other functions.


 * Other:
 * <tt>convert</tt> returns the second argument converted to variant language specified by the first argument. ONLY apply on wikis with LanguageConverter class. (New func added on 49399, need support of MediaWiki after 49397)

length("Wikipedia") Result: 9 lcase("Wikipedia") Result: wikipedia ccnorm("ωɨƙɩᑭƐƉlα") Result: W1K1PED1A convert("zh-hant", "维基百科") // assume we work on a wiki with Chinese LanguageConverter class Result: 維基百科 rmdoubles( "foobybboo" ) Result: fobybo specialratio("Wikipedia!") Result: 0.1 norm( "!!ω..ɨ..ƙ..ɩ..ᑭᑭ..Ɛ.Ɖ@@l%%α!!" ) Result: W1K1PED1A count( "foo", "foofooboofoo" ) Result: 3 count( "foo,bar,baz" ) Result: 3 rmspecials( "FOOBAR!!1" ) Result: FOOBAR1
 * Examples:

Boolean operations
You can match if and only if all of a number of conditions are true, one of a number of conditions are true, or one and only one of all conditions are true.
 * <tt>x | y</tt> &mdash; OR – returns true if one or more of the conditions is true.
 * <tt>x & y</tt> &mdash; AND – returns true if both of the conditions are true.
 * <tt>x ^ y</tt> &mdash; XOR – returns true if one, and only one of the two conditions is true.
 * <tt>!x</tt> &mdash; NOT – returns true if the condition is not true.

1 | 1 Result: True 1 | 0 Result: True 0 | 0 Result: False
 * Examples:

1 & 1 Result: True 1 & 0 Result: False 0 & 0 Result: False

1 ^ 1 Result: False 1 ^ 0 Result: True 0 ^ 0 Result: False

!1 Result: False

Order of operations
Operations are generally done left-to-right, but there is an order to which they are resolved. As soon as the filter fails one of the conditions, it will stop checking the rest of them and move on to the next filter. The evaluation order is:
 * 1) Anything surrounded by parentheses (<tt>(</tt> and <tt>)</tt>) is evaluated as a single unit.
 * 2) Turning variables/literals into their respective data. (i.e., <tt>article_namespace</tt> to 0)
 * 3) Function calls (<tt>norm</tt>, <tt>lcase</tt>, etc.)
 * 4) Unary + and - (i.e. <tt>-1234</tt>, <tt>+1234</tt>)
 * 5) Keywords
 * 6) Boolean inversion (<tt>!x</tt>)
 * 7) Exponentiation (<tt>2**3 → 8</tt>)
 * 8) Multiplication-related (multiplication, division, modulo)
 * 9) Comparisons. (<tt><</tt>, <tt>></tt>, <tt>==</tt>)
 * 10) Boolean operations. (<tt>&</tt>, <tt>|</tt>, <tt>^</tt>, <tt>in</tt>)

zh:Wikipedia:防滥用过滤器/操作指引