Extension:AbuseFilter/Rules format/zh

zh:Wikipedia:防滥用过滤器/操作指引 防滥用过滤器的语法格式与类C／JAVA／Perl语言的条件式十分相近.

常量
你可以在单引号或双引号中填写字符串常量，亦可直接填写数字变量（包括整型与浮点型）. 你可以使用\n来换行，而且你还可以使用半角反斜杠来转义引号字符.


 * 例:

注釋
您可以使用以下語法來注釋： /* This is a comment */

变量
防滥用过滤器可以根据变量的名称将各种变量传送给解析器. 你可以输入这些变量的名称来访问它们，就像访问常量一样. 在过滤日志中，你还可以看到各请求的相关变量.

你可以定義更多的變數，只要在一行中使用賦值符號 （以 結尾）並跟隨一個條件. 這些變數可以使用字母、下劃線和數字（除第一個字符外），並且區分大小寫. 例如（來自w:en:Special:AbuseFilter/79）：

頁面或條目命名空間
參見Manual:Namespace/zh

简单的比较
你可以将变量与其他变量进行比较及運算，以下是语法规则：
 * and &mdash;Return true if the left-hand operand is less than/greater than the right-hand operand respectively.
 * and &mdash;Return true if the left-hand operand is less than or equal to/greater than or equal to the right-hand operand respectively.
 * (or ) and  &mdash;Return true if the left-hand operand is equal to/not equal to the right-hand operand respectively.
 * and &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:
 * — Subtract the right-hand operand from the left-hand operand.
 * — Add the right-hand operand to the left-hand operand.
 * — Multiply the left-hand operand by the right-hand operand.
 * — Divide the left-hand operand by the right-hand operand.
 * — Raise the left-hand operand to the exponential power specified by the right-hand operand.
 * — Return the remainder given when the left-hand operand is divided by the right-hand operand.

The type of the returned result is the same that would be returned by PHP, for which a lot of documentation may be found online. More exhaustive examples may be found in this AF parser test.

String concatenation
Use the  (plus) symbol to concatenate two literal strings or the values of two vars with a string value.

Keywords
The following special keywords are included for often-used functionality:
 * (or ) returns true if the left-hand operand matches the glob pattern in the right-hand operand.
 * returns true if the right-hand operand (a string) contains the left-hand operand. Note: empty strings are not contained in, nor contain, any other string (not even the empty string itself).
 * works like, but with the left and right-hand operands switched. Note: empty strings are not contained in, nor contain, any other string (not even the empty string itself).
 * (or ) and   return true if the left-hand operand matches (contains) the regex pattern in the right-hand operand (  is case insensitive). The system uses PCRE. The only PCRE option enabled is   (modifier   [//php.net/manual/en/reference.pcre.pattern.modifiers.php in PHP]); for   both   and   are enabled (modifier  ).
 * ,  and
 * ,  and
 * ,  and

Examples

Functions
A number of built-in functions are included to ease some common issues. They are executed in the general format, and can be used in place of any literal or variable. Its arguments can be given as literals, variables, or even other functions.

Other
 * 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)

布尔 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.
 * &mdash; OR – returns true if one or more of the conditions is true.
 * &mdash; AND – returns true if both of the conditions are true.
 * &mdash; XOR – returns true if one, and only one of the two conditions is true.
 * &mdash; NOT – returns true if the condition is not true.

Examples

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 (due to short-circuit evaluation) and move on to the next filter (except for T43693). The evaluation order is:
 * 1) Anything surrounded by parentheses (  and  ) is evaluated as a single unit.
 * 2) Turning variables/literals into their respective data. (i.e.,   to 0)
 * 3) Function calls (,  , etc.)
 * 4) Unary   and   (defining positive or negative value, e.g. ,  )
 * 5) Keywords
 * 6) 布尔 inversion
 * 7) Exponentiation
 * 8) Multiplication-related (multiplication, division, modulo)
 * 9) Addition and subtraction
 * 10) Comparisons.
 * 11) 布尔 operations.

Examples

 * is equivalent to, not to  . In particular, both   and   evaluates to.
 * is equivalent to, not to  . In particular, both   and   evaluates to.

Condition counting
The condition limit is (more or less) tracking the number of comparison operators + number of function calls entered.

Further explanation on how to reduce conditions used can be found at Extension:AbuseFilter/Conditions.

Useful links

 * PCRE pattern syntax
 * meta:Edit filters benefiting to various local Wikiprojects
 * Extension:AbuseFilter/Conditions