User:松/Drafts/Extension:AbuseFilter/Rules format: Difference between revisions

Content added Content deleted
m (459 revisions imported: Per request at the community portal.)
(Translation code removal)
Line 1: Line 1:
<languages/>
<translate>
<!--T: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 == <!--T:2-->
== 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).
<!--T:3-->
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).</translate>
<translate>
<!--T:4-->
You can get linebreaks with <tvar|1><code>\n</code></>, tab characters with <tvar|2><code>\t</code></>, and you can also escape the quote character with a backslash.


You can get linebreaks with <code>\n</code>, tab characters with <code>\t</code>, and you can also escape the quote character with a backslash.
<!--T:5-->
Use the <tvar|1><code>+</code></> (plus) symbol to [[w:concatenation|concatenate]] two [[w:string literal|literal strings]] or the values of two [[w:Variable (computer science)|vars]] with a string value.
</translate>



; <translate><!--T:6--> Examples</translate>:
Use the <code>+</code> (plus) symbol to [[w:concatenation|concatenate]] two [[w:string literal|literal strings]] or the values of two [[w:Variable (computer science)|vars]] with a string value.


; Examples:
<syntaxhighlight lang="perl">
<syntaxhighlight lang="perl">
"<translate><!--T:7--> This is a string</translate>"
" This is a string"
'<translate><!--T:8--> This is also a string</translate>'
' This is also a string'
'<translate><!--T:9--> This string shouldn\'t fail</translate>'
' This string shouldn\'t fail'
"<translate><!--T:10--> This string\nHas a linebreak</translate>"
" This string\nHas a linebreak"
1234
1234
1.234
1.234
Line 27: Line 22:
</syntaxhighlight>
</syntaxhighlight>


==User-defined variables==
<translate>

==User-defined variables== <!--T:11-->
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.

Such variables may use letters, underscores, and numbers (apart from the first character) and are case-insensitive.

Example (from [[w:Special:AbuseFilter/79]]):


<!--T:12-->
You can define custom variables for ease of understanding with the assign symbol <tvar|1><code>:=</code></> in a line (closed by <tvar|2><code>;</code></>) within a condition.</translate>
<translate>
<!--T:13-->
Such variables may use letters, underscores, and numbers (apart from the first character) and are case-insensitive.</translate>
<translate>
<!--T:14-->
Example (from <tvar|1>[[w:Special:AbuseFilter/79]]</>):
</translate>


<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
Line 49: Line 40:
</syntaxhighlight>
</syntaxhighlight>



<translate>
==Arrays== <!--T:15-->
==Arrays==

</translate>
<!--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 -->

<translate>
AbuseFilter has support for non-associative arrays, which can be used like in the following examples.
<!--T:16-->
AbuseFilter has support for non-associative arrays, which can be used like in the following examples.</translate>


{{Caution|1=<translate><!--T:460--> Expressions like <tvar|1><code>page_namespace in [14, 15]</code></> may not work as expected.</translate> <translate><!--T:440--> This one will evaluate to <tvar|1><samp>true</samp></> also if <tvar|2><code>page_namespace</code></> is <tvar|3><samp>1</samp></>, <tvar|4><samp>4</samp></>, or <tvar|5><samp>5</samp></>.</translate> <translate><!--T:441--> For more information and possible workarounds, please see <tvar|1>[[:phab:T181024|T181024]]</>.</translate>}}
{{Caution|1=<translate><!--T:460--> Expressions like <tvar|1><code>page_namespace in [14, 15]</code></> may not work as expected.</translate> <translate><!--T:440--> This one will evaluate to <tvar|1><samp>true</samp></> also if <tvar|2><code>page_namespace</code></> is <tvar|3><samp>1</samp></>, <tvar|4><samp>4</samp></>, or <tvar|5><samp>5</samp></>.</translate> <translate><!--T:441--> For more information and possible workarounds, please see <tvar|1>[[:phab:T181024|T181024]]</>.</translate>}}