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

Content added Content deleted
(→‎Functions: Translation code removal.)
Line 729: Line 729:
| <code>get_matches</code> || {{MW version-inline|MW 1.31+}} Looks for matches of the regex needle (first string) in the haystack (second string).Returns an array where the 0 element is the whole match and every <code>[n]</code> element is the match of the n'th capturing group of the needle.Can be made case-insensitive by letting the regular expression start with "(?i)".If a capturing group didn't match, that array position will take value of ''false''.
| <code>get_matches</code> || {{MW version-inline|MW 1.31+}} Looks for matches of the regex needle (first string) in the haystack (second string).Returns an array where the 0 element is the whole match and every <code>[n]</code> element is the match of the n'th capturing group of the needle.Can be made case-insensitive by letting the regular expression start with "(?i)".If a capturing group didn't match, that array position will take value of ''false''.
|-
|-
| <code>ip_in_range</code> || Returns true if user's IP (first string) matches the specified IP range (second string, in [[:en:CIDR notation|CIDR notation]]).Only works for anonymous users. <translate><!--T:346--> Supports both IPv4 and IPv6 addresses.</translate>
| <code>ip_in_range</code> || Returns true if user's IP (first string) matches the specified IP range (second string, in [[:en:CIDR notation|CIDR notation]]).Only works for anonymous users.Supports both IPv4 and IPv6 addresses.
|-
|-
| <code>contains_any</code> || <translate><!--T:347--> Returns true if the first string contains '''any''' string from the following arguments (unlimited number of arguments in logic OR mode).</translate> <translate><!--T:348--> If the first argument is an array, it gets casted to string.</translate>
| <code>contains_any</code> || Returns true if the first string contains '''any''' string from the following arguments (unlimited number of arguments in logic OR mode).If the first argument is an array, it gets casted to string.
|-
|-
| <code>contains_all</code> || <translate><!--T:349--> Returns true if the first string contains '''every''' string from the following arguments (unlimited number of arguments in logic AND mode).</translate> <translate><!--T:350--> If the first argument is an array, it gets casted to string.</translate>
| <code>contains_all</code> || Returns true if the first string contains '''every''' string from the following arguments (unlimited number of arguments in logic AND mode).If the first argument is an array, it gets casted to string.
|-
|-
| <code>equals_to_any</code> || <translate><!--T:351--> Returns true if the first argument is identical (<tvar|1><code>===</code></>) to any of the following ones (unlimited number of arguments).</translate> <translate><!--T:352--> Basically, <tvar|1><code>equals_to_any(a, b, c)</code></> is the same as <tvar|2><code><nowiki>a===b | a===c</nowiki></code></>, but more compact and saves conditions.</translate>
| <code>equals_to_any</code> || Returns true if the first argument is identical (<code>===</code>) to any of the following ones (unlimited number of arguments).Basically, <code>equals_to_any(a, b, c)</code> is the same as <code><nowiki>a===b | a===c</nowiki></code>, but more compact and saves conditions.
|-
|-
| <code>substr</code> || <translate><!--T:353--> Returns the portion of the first string, by offset from the second argument (starts at 0) and maximum length from the third argument (optional).</translate>
| <code>substr</code> || Returns the portion of the first string, by offset from the second argument (starts at 0) and maximum length from the third argument (optional).
|-
|-
| <code>strlen</code> || <translate><!--T:354--> Same as <tvar|1><code>length</code></>.</translate>
| <code>strlen</code> || Same as <code>length</code>.
|-
|-
| <code>strpos</code> || <translate><!--T:355--> Returns the numeric position of the first occurrence of needle (second string) in the haystack (first string), starting from offset from the third argument (optional, default is 0).</translate> <translate><!--T:356--> This function may return 0 when the needle is found at the begining of the haystack, so it might be misinterpreted as ''false'' value by another comparative operator.</translate> <translate><!--T:357--> The better way is to use <tvar|1><code>===</code></> or <tvar|2><code>!==</code></> for testing whether it is found.</translate>
| <code>strpos</code> || Returns the numeric position of the first occurrence of needle (second string) in the haystack (first string), starting from offset from the third argument (optional, default is 0).This function may return 0 when the needle is found at the begining of the haystack, so it might be misinterpreted as ''false'' value by another comparative operator.The better way is to use <code>===</code> or <code>!==</code> for testing whether it is found.
|-
|-
| <code>str_replace</code> || <translate><!--T:358--> Replaces all occurrences of the search string with the replacement string.</translate> <translate><!--T:359--> The function takes 3 arguments in the following order: text to perform the search on, text to find, replacement text.</translate>
| <code>str_replace</code> || Replaces all occurrences of the search string with the replacement string.The function takes 3 arguments in the following order: text to perform the search on, text to find, replacement text.
|-
|-
| <code>rescape</code> || <translate><!--T:360--> Returns the argument with some characters preceded with the escape character <tvar|1>"\"</>, so that the string can be used in a regular expression without those characters having a special meaning.</translate>
| <code>rescape</code> || Returns the argument with some characters preceded with the escape character "\", so that the string can be used in a regular expression without those characters having a special meaning.
|-
|-
| <code>set</code> || <translate><!--T:361--> Sets a variable (first string) with a given value (second argument) for further use in the filter.</translate> <translate><!--T:362--> Another syntax: <tvar|1><code>''name'' := ''value''</code></>.</translate>
| <code>set</code> || Sets a variable (first string) with a given value (second argument) for further use in the filter.Another syntax: <code>''name'' := ''value''</code>.
|-
|-
| <code>set_var</code> || <translate><!--T:363--> Same as <tvar|1><code>set</code></>.</translate>
| <code>set_var</code> || Same as <code>set</code>.
|}
|}


Line 756: Line 756:
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-functions.t -->
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-functions.t -->
{| class="wikitable"
{| class="wikitable"
! Code
!<translate><!--T:365--> Code</translate>
! Result
!<translate><!--T:366--> Result</translate>
!<translate><!--T:367--> Comment</translate>
! Comment
|-
|-
| <code>length( "Wikipedia" )</code>
| <code>length( "Wikipedia" )</code>
Line 770: Line 770:
| <code>ccnorm( "w1k1p3d14" )</code>
| <code>ccnorm( "w1k1p3d14" )</code>
| WIKIPEDIA
| WIKIPEDIA
|<translate><!--T:368--> <tvar|1><code>ccnorm</code></> output is always uppercase</translate>
| <code>ccnorm</code> output is always uppercase
|-
|-
| <code>ccnorm( "ωɨƙɩᑭƐƉ1α" )</code>
| <code>ccnorm( "ωɨƙɩᑭƐƉ1α" )</code>
Line 798: Line 798:
|<code>norm( "F00 B@rr" )</code>
|<code>norm( "F00 B@rr" )</code>
|FOBAR
|FOBAR
|<translate><!--T:369--> <tvar|1><code>norm</code></> removes whitespace, special characters and duplicates, then uses <tvar|2><code>ccnorm</code></></translate><!--
| <code>norm</code> removes whitespace, special characters and duplicates, then uses <code>ccnorm</code><!--
|-
|-
| <code>convert( "zh-hant", "维基百科" )</code><br />// assume we work on a wiki with Chinese LanguageConverter class
| <code>convert( "zh-hant", "维基百科" )</code><br />// assume we work on a wiki with Chinese LanguageConverter class