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

Content added Content deleted
(Translation code removal.)
(Translation code removal.)
Line 615: Line 615:
<!--T:283-->
<!--T:283-->
* Use <tvar|1><code>_pst</code></> variables when you're really sure that non-PST variables aren't enough.</translate> <translate><!--T:284--> You may also conditionally decide which one to check: if, for instance, you want to examine a signature, check first if <tvar|1><code>added_lines</code></> contains <tvar|2><code><nowiki>~~~</nowiki></code></>;</translate>
* Use <tvar|1><code>_pst</code></> variables when you're really sure that non-PST variables aren't enough.</translate> <translate><!--T:284--> You may also conditionally decide which one to check: if, for instance, you want to examine a signature, check first if <tvar|1><code>added_lines</code></> contains <tvar|2><code><nowiki>~~~</nowiki></code></>;</translate>
*In general, when dealing with these variables, it's always much better to consume further conditions but avoid computing heavy stuff.In order to achieve this, always put heavy variables as last conditions.
<translate>

<!--T:285-->
Last but not least, note that whenever a variable is computed for a given filter, it'll be saved and any other filter will immediately retrieve it.This means that one single filter computing this variable counts more or less as dozens of filters using it.
* In general, when dealing with these variables, it's always much better to consume further conditions but avoid computing heavy stuff.</translate> <translate><!--T:286--> In order to achieve this, always put heavy variables as last conditions.</translate>
<translate><!--T:287--> Last but not least, note that whenever a variable is computed for a given filter, it'll be saved and any other filter will immediately retrieve it.</translate>This means that one single filter computing this variable counts more or less as dozens of filters using it.


== Keywords ==
== Keywords ==
Line 626: Line 625:


*<code>like</code> (or <code>matches</code>) returns true if the left-hand operand matches the [[w:Glob (programming)#Syntax|glob pattern]] in the right-hand operand.
*<code>like</code> (or <code>matches</code>) returns true if the left-hand operand matches the [[w:Glob (programming)#Syntax|glob pattern]] in the right-hand operand.
* <translate><!--T:293--> <tvar|1><code>in</code></> returns true if the right-hand operand (a string) contains the left-hand operand.</translate> '''<translate><!--T:294--> Note:</translate>''' <translate><!--T:295--> empty strings are not contained in, nor contain, any other string (not even the empty string itself).</translate>
*<code>in</code> 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).
* <translate><!--T:296--> <tvar|1><code>contains</code></> works like <tvar|2><code>in</code></>, but with the left and right-hand operands switched.</translate> '''<translate><!--T:297--> Note:</translate>''' <translate><!--T:298--> empty strings are not contained in, nor contain, any other string (not even the empty string itself).</translate>
*<code>contains</code> works like <code>in</code>, 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).
* <translate><!--T:299--> <tvar|1><code>rlike</code></> (or <tvar|2><code>regex</code></>) and <tvar|3><code>irlike</code></> return true if the left-hand operand matches (contains) the [[w:Regular expression|regex]] pattern in the right-hand operand (<tvar|4><code>irlike</code></> is case '''i'''nsensitive).</translate>
*<code>rlike</code> (or <code>regex</code>) and <code>irlike</code> return true if the left-hand operand matches (contains) the [[w:Regular expression|regex]] pattern in the right-hand operand (<code>irlike</code> is case '''i'''nsensitive).


The system uses [[w:Perl Compatible Regular Expressions|PCRE]].The only PCRE option enabled is <code>PCRE_UTF8</code> (modifier <code>u</code> [https://php.net/reference.pcre.pattern.modifiers in PHP]); for <code>irlike</code> both <code>PCRE_CASELESS</code> and <code>PCRE_UTF8</code> are enabled (modifier <code>iu</code>).
The system uses [[w:Perl Compatible Regular Expressions|PCRE]].The only PCRE option enabled is <code>PCRE_UTF8</code> (modifier <code>u</code> [https://php.net/reference.pcre.pattern.modifiers in PHP]); for <code>irlike</code> both <code>PCRE_CASELESS</code> and <code>PCRE_UTF8</code> are enabled (modifier <code>iu</code>).
Line 663: Line 662:
| <code> "o" in ["foo", "bar"]</code>
| <code> "o" in ["foo", "bar"]</code>
| True
| True
| <translate><!--T:303--> Due to the string cast</translate>
| Due to the string cast
|-
|-
| <code>"foo" regex "\w+"</code>
| <code>"foo" regex "\w+"</code>
Line 671: Line 670:
| <code>"a\b" regex "a\\\\b"</code>
| <code>"a\b" regex "a\\\\b"</code>
| True
| True
| rowspan= "2" | <translate><!--T:304--> To look for the escape character backslash using regex you need to use either four backslashes or two <tvar|1><code>\x5C</code></>.</translate> <translate><!--T:305--> (Either works fine.)</translate>
| rowspan= "2" | To look for the escape character backslash using regex you need to use either four backslashes or two <code>\x5C</code>. (Either works fine.)
|-
|-
| <code>"a\b" regex "a\x5C\x5Cb"</code>
| <code>"a\b" regex "a\x5C\x5Cb"</code>