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

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

edits