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>


==Arrays==

==Arrays==


<!--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> — <translate><!--T:25--> Subtract the right-hand operand from the left-hand operand.</translate>
* <code>-</code> — Subtract the right-hand operand from the left-hand operand.
* <code>+</code> — <translate><!--T:26--> Add the right-hand operand to the left-hand operand.</translate>
* <code>+</code> — Add the right-hand operand to the left-hand operand.
* <code>*</code> — <translate><!--T:27--> Multiply the left-hand operand by the right-hand operand.</translate>
* <code>*</code> — Multiply the left-hand operand by the right-hand operand.
* <code>/</code> — <translate><!--T:28--> Divide the left-hand operand by the right-hand operand.</translate>
* <code>/</code> — Divide the left-hand operand by the right-hand operand.
* <code>**</code> — <translate><!--T:29--> Raise the left-hand operand to the exponential power specified by the right-hand operand.</translate>
* <code>**</code> — Raise the left-hand operand to the exponential power specified by the right-hand operand.
* <code>%</code> — <translate><!--T:30--> Return the remainder given when the left-hand operand is divided by the right-hand operand.</translate>
* <code>%</code> — 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 [https://php.net/language.operators.arithmetic online].
<translate>

<!--T:31-->
More exhaustive examples may be found in [https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/arith.t this AF parser test].
The type of the returned result is the same that would be returned by PHP, for which a lot of documentation may be found [<tvar|url>https://php.net/language.operators.arithmetic</> online].</translate>
<translate>
<!--T:32-->
More exhaustive examples may be found in [<tvar|url>https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/arith.t</> this AF parser test].
</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%;"|<translate><!--T:33--> Example</translate>
!style="width: 50%;"|Example
!Result
!<translate><!--T:34--> Result</translate>
|-
|-
| <code>1 + 1</code> || 2
| <code>1 + 1</code> || 2
Line 107: Line 101:
|}
|}


== Boolean operations ==
<translate>
== Boolean operations == <!--T:35-->


<!--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.


* <code>x | y</code> &mdash; OR &ndash; returns true if one or more of the conditions is true.
<!--T:37-->
* <tvar|1><code>x | y</code> &mdash; OR</> &ndash; returns true if one or more of the conditions is true.</translate>
* <code>x & y</code> &mdash; AND &ndash; returns true if both of the conditions are true.
* <code>x ^ y</code> &mdash; XOR &ndash; returns true if one, and only one of the two conditions is true.
<translate>
* <code>!x</code> &mdash; NOT &ndash; returns true if the condition is not true.
<!--T:38-->
* <tvar|1><code>x & y</code> &mdash; AND</> &ndash; returns true if both of the conditions are true.</translate>
<translate>
<!--T:39-->
* <tvar|1><code>x ^ y</code> &mdash; XOR</> &ndash; returns true if one, and only one of the two conditions is true.</translate>
<translate>
<!--T:40-->
* <tvar|1><code>!x</code> &mdash; NOT</> &ndash; returns true if the condition is not true.
</translate>


'''<translate><!--T:41--> Examples</translate>'''
'''<translate><!--T:41--> Examples</translate>'''
Line 169: Line 153:


{{anchor|Simple comparisons}}
{{anchor|Simple comparisons}}
<translate>
== Simple comparisons == <!--T:44-->


== Simple comparisons ==
<!--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>&lt;</code>{{int|comma-separator}}<code>&gt;</code> &mdash; 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-->
* <tvar|1><code>&lt;</code>{{int|comma-separator}}<code>&gt;</code></> &mdash; Return true if the left-hand [[w:Operand|operand]] is ''less than/greater than'' the right-hand operand respectively.</translate> <translate><!--T:47--> Watch out: operands are casted to strings and, like it happens in PHP, <code><tvar|1>null <</> any number <tvar|2>=== true</></code> and <code><tvar|3>null ></> any number <tvar|4>=== false</></code>.</translate>
* <code>&lt;=</code>{{int|comma-separator}}<code>&gt;=</code> &mdash; 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-->
* <tvar|1><code>&lt;=</code>{{int|comma-separator}}<code>&gt;=</code></> &mdash; Return true if the left-hand operand is ''less than or equal to/greater than or equal to'' the right-hand operand respectively.</translate> <translate><!--T:49--> Watch out: operands are casted to strings and, like it happens in PHP, <code><tvar|1>null <=</> any number <tvar|2>=== true</></code> and <code><tvar|3>null >=</> any number <tvar|4>=== false</></code>.</translate>
<translate>
<translate>
<!--T:50-->
<!--T:50-->