User:松/Drafts/Extension:AbuseFilter/Rules format: Difference between revisions
Content added Content deleted
(Translation code removal) |
(Translation code removal) |
||
Line 1: | Line 1: | ||
The rules are formatted much as conditionals in a C/Java/Perl-like language. |
The rules are formatted much as conditionals in a C/Java/Perl-like language. |
||
== Strings == |
== Strings == |
||
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 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). |
||
Line 22: | Line 22: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
==User-defined variables== |
==User-defined variables== |
||
You can define custom variables for ease of understanding with the assign symbol <code>:=</code> in a line (closed by <code>;</code>) within a condition. |
You can define custom variables for ease of understanding with the assign symbol <code>:=</code> in a line (closed by <code>;</code>) within a condition. |
||
Line 29: | Line 29: | ||
Example (from [[w:Special:AbuseFilter/79]]): |
Example (from [[w:Special:AbuseFilter/79]]): |
||
<syntaxhighlight lang="c"> |
<syntaxhighlight lang="c"> |
||
Line 40: | Line 39: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
⚫ | |||
⚫ | |||
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arrays.t --> |
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arrays.t --> |
||
Line 66: | Line 64: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
== Comments == |
== Comments == |
||
You can specify comments using the following syntax: |
You can specify comments using the following syntax: |
||
Line 72: | Line 70: | ||
/* This is a comment */ |
/* This is a comment */ |
||
== Arithmetic == |
== Arithmetic == |
||
You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax: |
You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax: |
||
* <code>-</code> — |
* <code>-</code> — Subtract the right-hand operand from the left-hand operand. |
||
* <code>+</code> — |
* <code>+</code> — Add the right-hand operand to the left-hand operand. |
||
* <code>*</code> — |
* <code>*</code> — Multiply the left-hand operand by the right-hand operand. |
||
* <code>/</code> — |
* <code>/</code> — Divide the left-hand operand by the right-hand operand. |
||
* <code>**</code> — |
* <code>**</code> — Raise the left-hand operand to the exponential power specified by the right-hand operand. |
||
* <code>%</code> — |
* <code>%</code> — Return the remainder given when the left-hand operand is divided by the right-hand operand. |
||
⚫ | |||
<translate> |
|||
<!--T:31--> |
|||
⚫ | |||
⚫ | |||
<translate> |
|||
<!--T:32--> |
|||
⚫ | |||
</translate> |
|||
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arithmetic.t --> |
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arithmetic.t --> |
||
{| class="wikitable" |
{| class="wikitable" |
||
!style="width: 50%;"| |
!style="width: 50%;"|Example |
||
!Result |
|||
!<translate><!--T:34--> Result</translate> |
|||
|- |
|- |
||
| <code>1 + 1</code> || 2 |
| <code>1 + 1</code> || 2 |
||
Line 107: | Line 101: | ||
|} |
|} |
||
⚫ | |||
<translate> |
|||
⚫ | |||
<!--T:36--> |
|||
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. |
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. |
||
⚫ | |||
<!--T:37--> |
|||
* |
* <code>x & y</code> — AND – returns true if both of the conditions are true. |
||
⚫ | |||
<translate> |
|||
⚫ | |||
<!--T:38--> |
|||
⚫ | |||
<translate> |
|||
<!--T:39--> |
|||
⚫ | |||
<translate> |
|||
<!--T:40--> |
|||
⚫ | |||
</translate> |
|||
'''<translate><!--T:41--> Examples</translate>''' |
'''<translate><!--T:41--> Examples</translate>''' |
||
Line 169: | Line 153: | ||
{{anchor|Simple comparisons}} |
{{anchor|Simple comparisons}} |
||
<translate> |
|||
⚫ | |||
⚫ | |||
<!--T:45--> |
|||
You can compare [[w:Variable (computer science)|variables]] with other variables and [[w:Operand|literals]] with the following [[w:syntax|syntax]]: |
You can compare [[w:Variable (computer science)|variables]] with other variables and [[w:Operand|literals]] with the following [[w:syntax|syntax]]: |
||
⚫ | * <code><</code>{{int|comma-separator}}<code>></code> — Return true if the left-hand [[w:Operand|operand]] is ''less than/greater than'' the right-hand operand respectively. Watch out: operands are casted to strings and, like it happens in PHP, <code>null < any number === true</code> and <code>null > any number === false</code>. |
||
<!--T:46--> |
|||
* |
* <code><=</code>{{int|comma-separator}}<code>>=</code> — Return true if the left-hand operand is ''less than or equal to/greater than or equal to'' the right-hand operand respectively.Watch out: operands are casted to strings and, like it happens in PHP, <code>null <= any number === true</code> and <code>null >= any number === false</code>. |
||
<translate> |
|||
<!--T:48--> |
|||
⚫ | * |
||
<translate> |
<translate> |
||
<!--T:50--> |
<!--T:50--> |