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

(see Special:ListGroupRights)
 
(152 intermediate revisions by 16 users not shown)
Line 1:
{{languages|Extension:AbuseFilter/Rules format}}[[zh:Wikipedia:防滥用过滤器/操作指引]]
The rules are formatted much as conditionals in a C/Java/Perl-like language.
 
== 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 get linebreaks with <code>\n</code>, tab characters with <code>\t</code>, and you can also escape the quote character with a backslash.
 
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).
Use the <code>+</code> (plus) symbol to [[:en:concatenation|concatenate]] two [[:en:string literal|literal strings]] or the values of two [[:en:Variable (computer science)|vars]] with a string value.
 
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.
;Examples
 
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">
" This is a string"
' This is also a string'
' This string shouldn\'t fail'
" This string\nHas a linebreak"
1234
1.234
Line 19 ⟶ 21:
 
==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. Such variables may use letters, underscores, and numbers (apart from the first character) and are case sensitive. Example (from [[w:en:Special:AbuseFilter/79]]):
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]]):
 
<syntaxhighlight lang="c">
Line 31 ⟶ 38:
 
==Arrays==
 
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arrays.t -->
 
AbuseFilter has support for non-associative arrays, which can be used like in the following examples.
 
{{Caution|1=Expressions like <code>page_namespace in [14, 15]</code> may not work as expected. This one will evaluate to <samp>true</samp> also if <code>page_namespace</code> is <samp>1</samp>, <samp>4</samp>, or <samp>5</samp>. For more information and possible workarounds, please see [[:phab:T181024|T181024]].}}
 
<syntaxhighlight lang="c">
my_array := [ 5, 6, 7, 10];
my_array[0] == 5
length(my_array) == 4
stringint( my_array ) === "5\n6\n7\n10\n"4 //Note: the last linebreak could be removed inSame theas futurelength
float( my_array ) === 4.0 // Counts the elements
string(my_array) == "5\n6\n7\n10\n" // Note: the last linebreak could be removed in the future
5 in my_array == true
'5' in my_array == true
'5\n6' in my_array == true // Note: this is due to how arrays are casted to string, i.e. by imploding them with linebreaks
1 in my_array == true // Note: this happens because 'in' casts arguments to strings, so the 1 is catchedcaught in '10' and returns true.
my_array[] := 57 // This appends an element at the end of the array
my_array === [ 5, 6, 7, 10, 57 ]
my_array[2] := 42 // And this is for changing an element in the array
my_array === [ 5, 6, 42, 10, 57 ]
</syntaxhighlight>
 
== Comments ==
 
You can specify comments using the following syntax:
 
/* This is a comment */
 
== Arithmetic ==
 
You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax:
* <code>-</code> — Subtract the right-hand operand from the left-hand operand.
* <code>+</code> — Add the right-hand operand to the left-hand operand.
* <code>*</code> — Multiply the left-hand operand by the right-hand operand.
* <code>/</code> — Divide the left-hand operand by the right-hand operand.
* <code>**</code> — Raise the left-hand operand to the exponential power specified by the right-hand operand.
* <code>%</code> — Return the remainder given when the left-hand operand is divided by the right-hand operand.
 
*<code>-</code> — Subtract the right-hand operand from the left-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://secure.php.net/manual/en/language.operators.arithmetic.php online]. More exhaustive examples may be found in [https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/arith.t this AF parser test].
*<code>+</code> — Add the right-hand operand to the left-hand operand.
*<code>*</code> — Multiply the left-hand operand by the right-hand operand.
*<code>/</code> — Divide the left-hand operand by the right-hand operand.
*<code>**</code> — Raise the left-hand operand to the exponential power specified by the right-hand operand.
*<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].
 
More exhaustive examples may be found in [https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/arith.t this AF parser test].
 
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arithmetic.t -->
{| class="wikitable"
!style="width: 50%;"|Example!!|Result
!Result
|-
| <code>1 + 1</code> || 2
Line 75 ⟶ 100:
 
== Boolean operations ==
 
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.
* <code>x &| y</code> &mdash; ANDOR &ndash; returns true if bothone or more of the conditions areis true.
* <code>x ^& y</code> &mdash; XORAND &ndash; returns true if one, and only oneboth of the two conditions isare true.
* <code>!x ^ y</code> &mdash; NOTXOR &ndash; returns true if one, and only one of the conditiontwo isconditions notis true.
*<code>!x</code> &mdash; NOT &ndash; returns true if the condition is not true.
 
'''Examples'''
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-bools.t -->
 
{| class="wikitable"
|-
! Code
! Result
|-
| <code>1 <nowiki>|</nowiki> 1</code>
Line 117 ⟶ 145:
| <code>!1</code>
| false
|-
| <code>!0</code>
| true
|}
 
{{anchor|Simple comparisons}}
 
== Simple comparisons ==
 
You can compare [[:en:Variable (computer science)|variables]] with other variables and [[:en:Operand|literals]] with the following [[:en: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> and <code>&gt;</code>&mdash;Return true if the left-hand [[:en: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>.
 
* <code>&lt;=</code> and <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>.
* <code>==&lt;</code> (or {{int|comma-separator}}<code>=&gt;</code>) and <code>!=</code>&mdash; Return true if the left-hand [[w:Operand|operand]] is ''equalless tothan/notgreater equal tothan'' 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>.
* <code>==&lt;=</code> and {{int|comma-separator}}<code>!=&gt;=</code> &mdash; Return true if the left-hand operand is ''less than or equal to/notgreater than or equal to'' the right-hand operand ANDrespectively.Watch theout: left-handoperands operandare iscasted ''theto same/notstrings theand, same''like datait typehappens toin thePHP, right-hand<code>null operand<= respectivelyany number === true</code> and <code>null >= any number === false</code>.
*<code>==</code> (or<code>=</code>), <code>!=</code> &mdash; Return true if the left-hand operand is ''equal to/not equal to'' the right-hand operand respectively.
*<code>===</code>{{int|comma-separator}}<code>!==</code> &mdash; Return true if the left-hand operand is ''equal to/not equal to'' the right-hand operand AND the left-hand operand is ''the same/not the same'' data type to the right-hand operand respectively.
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-comparisons.t -->
 
{| class="wikitable"
! style="width: 50%;"| Example
Line 178 ⟶ 214:
|}
 
== Built-in variables  ==
 
The abuse filter passes various variables by name into the parser. These variables can be accessed by typing their name in, in a place where a literal would work. You can view the variables associated with each request in the abuse log.
The abuse filter passes various variables by name into the parser.These variables can be accessed by typing their name in, in a place where a literal would work.You can view the variables associated with each request in the abuse log.
 
===Variables from AbuseFilter===
 
====Variables always available====
 
{{Caution|1=User-related variables are always available, except for one case: account creation when the creator is not logged in.All variables starting with =<code>user_</code> are affected.}}
 
===Variables from AbuseFilter===
{| class="wikitable sortable"
! Description
|+ Variables available
! Name
! Description !! Name !! Data type !! Notes
! Data type
! Notes
|-
| Action || <code>action</code> || string || One of the following:edit, move, createaccount, autocreateaccount, delete, upload<ref name="upload"> The only variables currently available for file uploads (action='upload') are user_*, page_*, file_sha1, file_size, file_mime, file_mediatype, file_width, file_height, file_bits_per_channel (the last five were only added since the release for MediaWiki 1.27 [[mw:gerrit:281503|gerrit:281503]]).All the file_* variables are unavailable for other actions (including action='edit').</ref>, stashupload<ref>Since MediaWiki 1.28 ([[mw:gerrit:295254|gerrit:295254]])</ref>
|-
| Unix timestamp of change || <code>timestamp</code> || string || int(timestamp) gives you a number with which you can calculate the date, time, day of week, etc.
|-
| {{int|abusefilter-edit-builder-vars-wiki-name}} || <code>wiki_name</code> || string || For instance, this is "enwiki" on the English Wikipedia, and "itwikiquote" on the Italian Wikiquote.
|-
| {{int|abusefilter-edit-builder-vars-wiki-language}} || <code>wiki_language</code> || string || For instance, this is "en" on the English Wikipedia, and "it" on the Italian Wikiquote. Multi-lingual wikis like Commons, Meta, and Wikidata will also report as "en".
| Action || <code>action</code> || string || One of: edit, move, createaccount, autocreateaccount, delete, upload<ref name="upload">The only variables currently available for file uploads (action='upload') are user_*, page_*, file_sha1, file_size, file_mime, file_mediatype, file_width, file_height, file_bits_per_channel (the last five were only added since the release for MediaWiki 1.27, [[gerrit:281503]]). All the file_* variables are unavailable for other actions (including action='edit').</ref>, stashupload<ref>Since MediaWiki 1.28 (https://gerrit.wikimedia.org/r/#/c/295254/)</ref>
|-
| {{int|abusefilter-edit-builder-vars-user-editcount}} || <code>user_editcount</code> || integer/null || Null only for unregistered users.
|-
| {{int|abusefilter-edit-builder-vars-user-name}} || <code>user_name</code> || string || '''Note''':{{note|1=For this is"createaccount" empty forand "createaccountautocreateaccount" actionactions, use <code>accountname</code> insteadif you want the name of the account being created.}}
|-
| {{int|abusefilter-edit-builder-vars-user-emailconfirm}} || <code>user_emailconfirm</code> || string/null || In the format: YYYYMMDDHHMMSS. Null if the email wasn't confirmed.
|-
| {{int|abusefilter-edit-builder-vars-user-age}} || <code>user_age</code> || integer || In seconds; .0 for unregistered users.
|-
| {{int|abusefilter-edit-builder-vars-user-blocked}} || <code>user_blocked</code> || boolean || trueTrue for blocked registered users,.Also falsetrue for unregisterededits usersfrom blocked IP addresses, even if the editor is a registered user who is not blocked.False '''Note''':otherwise. this{{note|1=This doesn't differentiate between partial and total blocks.}}
|-
| {{int|abusefilter-edit-builder-vars-user-groups}} || <code>user_groups</code> || array of strings || see [[Special:ListGroupRights]]
|-
| {{int|abusefilter-edit-builder-vars-user-rights}} || <code>user_rights</code> || array of strings || see [[Special:ListGroupRights]]
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-page-id}}</span> || <span style="opacity:0.5"><code>article_articleid</code></span> || <span style="opacity:0.5"> integer</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_id</code> instead.
|-
| [[{{ll|Manual:Page_table#page_id|{{int|abusefilter-edit-builder-vars-page-id}}]]}} (found in the page's HTML source - search for wgArticleId) || <code>page_id</code> || integer || In theory this is 0 for new pages, but this is unreliable.If Insteadyou need an exact result, use "page_age == 0" to identify new page creation. (note that it is slower, though.)
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-page-ns}}</span> || <span style="opacity:0.5"><code>article_namespace</code></span> || <span style="opacity:0.5"> integer</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_namespace</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-page-ns}} || <code>page_namespace</code> || integer || refers to [[{{ll|Manual:Namespace#Built-in_namespaces|namespace index]]}}
|-
| {{int|abusefilter-edit-builder-vars-page-age}} || <code>page_age</code> || integer || the number of seconds since the first edit (or 0 for new pages).This is reliable, but it tends to be slow; consider using <code>page_id</code> if you don't need much precision.
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-page-title}}</span> || <span style="opacity:0.5"><code>article_text</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_title</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-page-title}} || <code>page_title</code> || string ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-page-prefixedtitle}}</span> || <span style="opacity:0.5"><code>article_prefixedtext</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_prefixedtitle</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-page-prefixedtitle}} || <code>page_prefixedtitle</code> || string ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-restrictions-edit}}</span> || <span style="opacity:0.5"><code>article_restrictions_edit</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_restrictions_edit</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-restrictions-edit}} || <code>page_restrictions_edit</code> || array of strings ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-restrictions-move}}</span> || <span style="opacity:0.5"><code>article_restrictions_move</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_restrictions_move</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-restrictions-move}} || <code>page_restrictions_move</code> || array of strings ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-restrictions-upload}}</span> || <span style="opacity:0.5"><code>article_restrictions_upload</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_restrictions_upload</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-restrictions-upload}} || <code>page_restrictions_upload</code> || array of strings ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-restrictions-create}}</span> || <span style="opacity:0.5"><code>article_restrictions_create</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_restrictions_create</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-restrictions-create}} || <code>page_restrictions_create</code> || array of strings ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-recent-contributors}}</span> || <span style="opacity:0.5"><code>article_recent_contributors</code></span> || <span style="opacity:0.5">array of strings</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_recent_contributors</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-recent-contributors}} || <code>page_recent_contributors</code> || array of strings || This tends to be '''slow''' (see [[#Performance]]). Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query. This value is empty if the user is the only contributor to the page(?), and only scans the last 100 revisions
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-first-contributor}}</span> || <span style="opacity:0.5"><code>article_first_contributor</code></span> || <span style="opacity:0.5"> string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>page_first_contributor</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-first-contributor}} || <code>page_first_contributor</code> || string || This tends to be '''slow''' (see [[#Performance]]).<ref>Several filters ([https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2017.11.22/mediawiki?id=AV_k0nzBSUnOz-leiQ1Q 1][https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2017.11.22/mediawiki?id=AV_kvnragaOKEclNGlrc 2]) that use this variable have showed up in the [https://logstash.wikimedia.org/app/kibana#/dashboard/941a0560-b9b2-11e7-a3f7-cb9288bcae84 AbuseFilterSlow Grafana dashboard] (requires logstash access to view). Moving this variable to towards the end of the filter seemed to help.</ref> Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query.
|}
 
==== Variables available for some actions ====
{{Caution|1=Always check that the variables you want to use are available for the current action being filtered, e.g. by using the <code>action</code> variable.Failing to do so (for instance using <code>accountname</code> for an edit, or <code>edit_delta</code> for a deletion) will make any code using the variable in question return false.}}
 
{| class="wikitable sortable"
! Description
|+ Variables available for some actions
! Name
! Description !! Name !! Data type !! Notes
! Data type
! Notes
|-
| {{int|abusefilter-edit-builder-vars-summary}} || <code>summary</code> || string || Summaries automatically created by MediaWiki ("New section", "Blanked the page", etc.) are created ''after'' the filter checks the edit, so they will never actually catch, even if the debugger shows that they should.<ref>See [[phabricator:T191722]]</ref>
|-
| <s>{{int|abusefilter-edit-builder-vars-minor-edit}}</s> || <s><code>minor_edit</code></s> || <s>string</s> || Disabled, and set to false for all entries between 2016 and 2018.<ref>Deprecated with [https[mw://gerrit.wikimedia.org/r/#/c/:296268/ |this commit]] and disabled with [https[mw://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/AbuseFilter/+/:481544/ |this one]].</ref>
|-
| {{int|abusefilter-edit-builder-vars-old-textwikitext}} || <code>old_wikitext</code> || string || This variable can be very large. Consider using <code>removed_lines</code> if possible to improve performance.
|-
| {{int|abusefilter-edit-builder-vars-new-textwikitext}} || <code>new_wikitext</code> || string || This variable can be very large. Consider using <code>added_lines</code> if possible to improve performance.
|-
| {{int|abusefilter-edit-builder-vars-diff}} || <code>edit_diff</code> || string ||
|-
| {{int|abusefilter-edit-builder-vars-diff-pst}} || <code>edit_diff_pst</code> || string || This tends to be '''slow''' (see [[#Performance]]). Checking both <code>added_lines</code> and <code>removed_lines</code> is probably more efficient.<ref> Some filters using this variable have showed up in the AbuseFilterSlow Grafana dashboard ([https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2017.11.22/mediawiki?id=AV_j4TTs-DyidI0FMJNq example], requires logstash access). For instance, instead of using <code>"text" in edit_diff_pst</code> (or even <code>edit_diff</code>), consider something like <code>"text" in added_lines & !("text" in removed_lines)</code></ref>
|-
| {{int|abusefilter-edit-builder-vars-newsize}} || <code>new_size</code> || integer ||
|-
| {{int|abusefilter-edit-builder-vars-oldsize}} || <code>old_size</code> || integer ||
|-
| {{int|abusefilter-edit-builder-vars-delta}} || <code>edit_delta</code> || integer || Tip: ensure that the action being filtered is an edit, either by checking for <code>action === 'edit'</code> or checking other edit-specific variables. Otherwise, <code>edit_delta</code> will be <code>null</code>, thus being considered less than every other number (see [[#Simple comparisons]]).
|-
| {{int|abusefilter-edit-builder-vars-addedlines-pst}} || <code>added_lines_pst</code> || array of strings || Use <code>added_lines</code> if possible, which is more efficient.
|-
| {{int|abusefilter-edit-builder-vars-addedlines}} || <code>added_lines</code> || array of strings || includes all lines in the final diff that begin with +
Line 273 ⟶ 328:
| {{int|abusefilter-edit-builder-vars-removedlines}} || <code>removed_lines</code> || array of strings ||
|-
| {{int|abusefilter-edit-builder-vars-all-links}} || <code>all_links</code> || array of strings ||
|-
| {{int|abusefilter-edit-builder-vars-old-links}} || <code>old_links</code> || array of strings ||
|-
| {{int|abusefilter-edit-builder-vars-added-links}} || <code>added_links</code> || array of strings || This tends to be '''slow''' (see [[#Performance]]). Consider checking against <code>added_lines</code> first, then check <code>added_links</code> so that fewer edits are slowed down. This follows [[{{ll|Help:Links#External_links|MediaWiki's rules for external links]]}}. Only unique links are added to the array. Changing a link will count as 1 added and 1 removed link.
|-
| {{int|abusefilter-edit-builder-vars-removed-links}} || <code>removed_links</code> || array of strings || This tends to be '''slow''' (see [[#Performance]]). Consider checking against <code>removed_lines</code> first, then check <code>removed_links</code> so that fewer edits are slowed down. This follows [[{{ll|Help:Links#External_links|MediaWiki's rules for external links]]}}. Only unique links are added to the array. Changing a link will count as 1 added and 1 removed link.
|-
| {{int|abusefilter-edit-builder-vars-new-pst}} || <code>new_pst</code> || string ||
|-
| {{int|abusefilter-edit-builder-vars-new-html}} || <code>new_html</code> || string || This variable can be very large. Consider using <code>added_lines</code> if possible to improve performance.
|-
| {{int|abusefilter-edit-builder-vars-new-text}} || <code>new_text</code> || string || This variable can be very large. Consider using <code>added_lines</code> if possible to improve performance.
|-
| <s>{{int|abusefilter-edit-builder-vars-old-html}}</s> || <s><code>old_html</code></s> || <s>string</s> || Disabled for performance reasons.
|-
| <s>{{int|abusefilter-edit-builder-vars-old-text}}</s> || <s><code>old_text</code></s> || <s>string</s> || Disabled for performance reasons.
|-
| Unix timestamp of change || <code>timestamp</code> || string || int(timestamp) gives you a number with which you can calculate the date, time, day of week, etc.
|-
| {{int|abusefilter-edit-builder-vars-file-sha1}} || <code>file_sha1</code> || string || <ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-size}} || <code>file_size</code> || integer || The file size in bytes<ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-width}} || <code>file_width</code> || integer || The width in pixels<ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-height}} || <code>file_height</code> || integer || The height in pixels<ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-bits-per-channel}} || <code>file_bits_per_channel</code> || integer || The amount of bits per color channel<ref name=upload/>
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedtofile-idmime}}</span> || <span style="opacity:0.5"><code>moved_to_articleidfile_mime</code></span> || <span style="opacity:0.5">integer</span>string || '''Deprecated'''.The Usefile [[w:MIME|MIME]] type.<code>moved_to_id<ref name=upload/code> instead.
|-
| {{int|abusefilter-edit-builder-vars-file-mediatype}} || <code>file_mediatype</code> || string || The file media type.<ref> See [https://gerrit.wikimedia.org/g/mediawiki/core/+/d887b9ff37a4956f6db15ddeea68e6d933e108c7/includes/libs/mime/defines.php the source code] for a list of types.</ref><ref name=upload/>
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedto-id}}</span> || <span style="opacity:0.5"><code>moved_to_articleid</code></span> || <span style="opacity:0.5">integer</span> || {{deprecated-inline}} Use <code>moved_to_id</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedto-id}} || <code>moved_to_id</code> || integer ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedto-title}}</span> || <span style="opacity:0.5"><code>moved_to_text</code></span> || <span style="opacity:0.5">string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>moved_to_title</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedto-title}} || <code>moved_to_title</code> || string ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedto-prefixedtitle}}</span> || <span style="opacity:0.5"><code>moved_to_prefixedtext</code></span> || <span style="opacity:0.5">string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>moved_to_prefixedtitle</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedto-prefixedtitle}} || <code>moved_to_prefixedtitle</code> || string ||
|-
| {{int|abusefilter-edit-builder-vars-movedto-ns}} || <code>moved_to_namespace</code> || stringinteger ||
|-
| {{int|abusefilter-edit-builder-vars-movedto-age}} || <code>moved_to_age</code> || integer ||
|-
| {{int|abusefilter-edit-builder-vars-movedfrommovedto-nsrestrictions-edit}} || <code>moved_from_namespacemoved_to_restrictions_edit</code> || array of string || Same as <code>page_restrictions_edit</code>, but for the target of the move.
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedfrommovedto-titlerestrictions-move}}</span> || <span style="opacity:0.5"><code>moved_from_textmoved_to_restrictions_move</code></span> || <spanarray of style="opacity:0.5">string</span> || '''Deprecated'''.Same Useas <code>moved_from_titlepage_restrictions_move</code>, but for the target of the insteadmove.
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-upload}} || <code>moved_to_restrictions_upload</code> || array of string || Same as <code>page_restrictions_upload</code>, but for the target of the move.
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-create}} || <code>moved_to_restrictions_create</code> || array of string || Same as <code>page_restrictions_create</code>, but for the target of the move.
|-
| {{int|abusefilter-edit-builder-vars-movedto-recent-contributors}} || <code>moved_to_recent_contributors</code> || array of strings || Same as <code>page_recent_contributors</code>, but for the target of the move.
|-
| {{int|abusefilter-edit-builder-vars-movedto-first-contributor}} || <code>moved_to_first_contributor</code> || string || Same as <code>page_first_contributor</code>, but for the target of the move.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-ns}} || <code>moved_from_namespace</code> || integer ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedfrom-title}}</span> || <span style="opacity:0.5"><code>moved_from_text</code></span> || <span style="opacity:0.5">string</span> || {{deprecated-inline}} Use <code>moved_from_title</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-title}} || <code>moved_from_title</code> || string ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedfrom-prefixedtitle}}</span> || <span style="opacity:0.5"><code>moved_from_prefixedtext</code></span> || <span style="opacity:0.5">string</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>moved_from_prefixedtitle</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-prefixedtitle}} || <code>moved_from_prefixedtitle</code> || string ||
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-movedfrom-id}}</span> || <span style="opacity:0.5"><code>moved_from_articleid</code></span> || <span style="opacity:0.5">integer</span> || '''Deprecated'''.{{deprecated-inline}} Use <code>moved_from_id</code> instead.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-id}} || <code>moved_from_id</code> || integer ||
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-age}} || <code>moved_from_age</code> || integer ||
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-edit}} || <code>moved_from_restrictions_edit</code> || array of string || Same as <code>page_restrictions_edit</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-move}} || <code>moved_from_restrictions_move</code> || array of string || Same as <code>page_restrictions_move</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-upload}} || <code>moved_from_restrictions_upload</code> || array of string || Same as <code>page_restrictions_upload</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-create}} || <code>moved_from_restrictions_create</code> || array of string || Same as <code>page_restrictions_create</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-recent-contributors}} || <code>moved_from_recent_contributors</code> || array of strings || Same as <code>page_recent_contributors</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-first-contributor}} || <code>moved_from_first_contributor</code> || string || Same as <code>page_first_contributor</code>, but for the page being moved.
|-
| {{int|abusefilter-edit-builder-vars-accountname}} || <code>accountname</code> || string ||
|-
| Content model of the old revision
|<code>old_content_model</code>
| string
| See [[{{ll|Help:ChangeContentModel]]}} for information about content model changes
|-
| Content model of the new revision
|<code>new_content_model</code>
| string
| See [[{{ll|Help:ChangeContentModel]]}} for information about content model changes
|-
|}
 
===Variables from other extensions===
 
{{Note|1=Most of these variables are always set to false when examinating past edits, and may not reflect their actual value at the time the edit was made.See [[:phab:T102944|T102944]].|2=warn}}
 
{| class="wikitable sortable"
|+
! Description !! Name !! Data type !! Values !! Added by
! Name
! Data type
! Values
! Added by
|-
| {{int|abusefilter-edit-builder-vars-global-user-groups}}
|<code>global_user_groups</code>
| array
|
|[[{{ll|Extension:CentralAuth|CentralAuth]]nsp=0}}
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-board-id}}</span>
| <span style="opacity:0.5"><code>board_articleid</code></span>
| <span style="opacity:0.5">integer</span>
| '''Deprecated'''.{{deprecated-inline}} Use <code>board_id</code> instead.
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-id}}
|<code>board_id</code>
| integer
|
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-namespace}}
|<code>board_namespace</code>
| integer
| refers to [[{{ll|Manual:Namespace#Built-in_namespaces|namespace index]]}}
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-board-title}}</span>
| <span style="opacity:0.5"><code>board_text</code></span>
| <span style="opacity:0.5">Stringstring</span>
| '''Deprecated'''.{{deprecated-inline}} Use <code>board_title</code> instead.
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-title}}
|<code>board_title</code>
| string
|
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
| <span style="opacity:0.5">{{int|abusefilter-edit-builder-vars-board-prefixedtitle}}</span>
| <span style="opacity:0.5"><code>board_prefixedtext</code></span>
| <span style="opacity:0.5">Stringstring</span>
| '''Deprecated'''.{{deprecated-inline}} Use <code>board_prefixedtitle</code> instead.
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-prefixedtitle}}
|<code>board_prefixedtitle</code>
| string
|
|[[{{ll|Extension:StructuredDiscussions|StructuredDiscussions]]nsp=0}}
|-
| {{int|abusefilter-edit-builder-vars-translate-source-text}}
|<code>translate_source_text</code>
| string
|
|[[{{ll|Extension:Translate|Translate]]nsp=0}}
|-
| {{int|abusefilter-edit-builder-vars-translate-target-language}}
|<code>translate_target_language</code>
| string
| This is the language code, like <code>en</code> for English.
|{{ll|Extension:Translate|nsp=0}}
|-
| {{int|abusefilter-edit-builder-vars-tor-exit-node}}
Line 412 ⟶ 506:
| boolean
| true if the action comes from a tor exit node.
|[[{{ll|Extension:TorBlock|TorBlock]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-user-mobile}}
Line 418 ⟶ 512:
| boolean
| true for mobile users, false otherwise.
|[[{{ll|Extension:MobileFrontend|MobileFrontend]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-user-app}}
| <code>user_app</code>
| boolean
| true if the user is editing from the mobile app, false otherwise.
|[[{{ll|Extension:MobileApp|MobileApp]]nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-user-wpzero}}
| <code>user_wpzero</code>
| boolean
| '''Note''': This variable is only valid when filtering an action. When examining a past edit or batch testing, it'll always be null.
|[[Extension:WikimediaEvents|WikimediaEvents]]
|-
| <span style="opacity:0.5">{{int|Page views[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-page-views}}/&namespace=0]</span>
| <span style="opacity:0.5"><code>article_views</code></span>
| <span style="opacity:0.5">integer</span>
| '''Deprecated'''.{{deprecated-inline}} Use <code>page_views</code> instead.
|[[{{ll|Extension:HitCounters|HitCounters]]nsp=0}}
|-
|{{int| Page views[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-page-views}}/&namespace=0]
| <code>page_views</code>
| integer
| the amount of page views
|[[{{ll|Extension:HitCounters|HitCounters]]nsp=0}}
|-
|{{int| Source page views[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-movedfrom-views}}/&namespace=0]
| <code>moved_from_views</code>
| integer
| the amount of page views of the source page
|[[{{ll|Extension:HitCounters|HitCounters]]nsp=0}}
|-
|{{int| Target page views[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-movedto-views}}/&namespace=0]
| <code>moved_to_views</code>
| integer
| the amount of page views of the target page
|[[{{ll|Extension:HitCounters|HitCounters]]nsp=0}}
|-
| {{int|True if this action was performed through a proxy[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-is-proxy}}/&namespace=0]
| <code>is_proxy</code>
| integer
| Whether this action was performed through a proxy
| [[{{ll|Extension:AutoProxyBlock|AutoProxyBlock]]nsp=0}}
|-
|{{int| Whether the IP address is blocked using the stopforumspam.com list[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-sfs-blocked}}/&namespace=0]
| <code>sfs_blocked</code>
| boolean
| Whether the IP address is blocked using the stopforumspam.com list
| [[{{ll|Extension:StopForumSpam|StopForumSpam]]nsp=0}}
|}
 
=== Notes ===
 
When <code>action='move'</code>, only the <code>summary</code>, <code>action</code>, <code>timestamp</code> and <code>user_*</code> variables are available. The <code>page_*</code> variables are also available, but the prefix is replaced by <code>moved_from_</code> and <code>moved_to_</code>, that represent the values of the original article name and the destination one, respectively. For example, <code>moved_from_title</code> and <code>moved_to_title</code> instead of <code>page_title</code>.
 
Since MediaWiki 1.28 (https[[mw://gerrit.wikimedia.org/r/#/c/:295254/|gerrit:295254]]), <code>action='upload'</code> is only used when publishing an upload, and not for uploads to stash. A new <code>action='stashupload'</code> is introduced, which is used for all uploads, including uploads to stash. This behaves like <code>action='upload'</code> used to, and only provides file metadata variables (<code>file_*</code>). Variables related to the page edit, including <code>summary</code>, <code>new_wikitext</code> and several others, are now available for <code>action='upload'</code>. For every file upload, filters may be called with <code>action='stashupload'</code> (for uploads to stash), and are always called with <code>action='upload'</code>; they are not called with <code>action='edit'</code>.
 
Filter authors should use <code>action='stashupload' | action='upload'</code> in filter code when a file can be checked based only on the file contents – for example, to reject low-resolution files – and <code>action='upload'</code> only when the wikitext parts of the edit need to be examined too – for example, to reject files with no description. This will allow tools that separate uploading the file and publishing the file (e.g. [[mw:UploadWizard|UploadWizard]] or [[mw:upload dialog|upload dialog]]) to inform the user of the failure before they spend the time filling in the upload details.
 
{{anchor|Performance}}
 
=== Performance ===
 
As noted in the table above, some of these variables can be very slow. While writing filters, remember that the condition limit is '''not''' a good metric of how heavy filters are. For instance, variables like <code>*_recent_contributors</code> or <code>*_links</code> always need a DB query to be computed, while <code>*_pst</code> variables will have to perform parsing of the text, which again is a heavy operation; all these variables should be used very, very carefully. For instance, on Italian Wikipedia it's been observed that, with 135 active filters and an average of 450 used conditions, filters execution time was around 500ms, with peaks reaching 15 seconds. Removing the <code>added_links</code> variable from a single filter, and halving the cases when another filter would use <code>added_lines_pst</code> brought the average execution time to 50ms. More specifically:
As noted in the table above, some of these variables can be very slow.While writing filters, remember that the condition limit is '''not''' a good metric of how heavy filters are.For instance, variables like <code>*_recent_contributors</code> or <code>*_links</code> always need a DB query to be computed, while <code>*_pst</code> variables will have to perform parsing of the text, which again is a heavy operation; all these variables should be used very, very carefully.For instance, on Italian Wikipedia it's been observed that, with 135 active filters and an average of 450 used conditions, filters execution time was around 500ms, with peaks reaching 15 seconds.Removing the <code>added_links</code> variable from a single filter, and halving the cases when another filter would use <code>added_lines_pst</code> brought the average execution time to 50ms.More specifically:
 
*Use <code>_links</code> variables when you need high accuracy and checking for "http://..." in other variables (for instance, <code>added_lines</code>) could lead to heavy malfunctioning;
*Use <code>_pst</code> variables when you're really sure that non-PST variables aren't enough. You may also conditionally decide which one to check: if, for instance, you want to examine a signature, check first if <code>added_lines</code> contains <code><nowiki>~~~</nowiki></code>;
*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.
 
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.
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.
 
== Keywords ==
 
{{note|Where not specifically stated, keywords cast their operands to strings}}
{{note|1=Where not specifically stated, keywords cast their operands to strings}}
The following special keywords are included for often-used functionality:
* <code>like</code> (or <code>matches</code>) returns true if the left-hand operand matches the [[w:en:Glob (programming)#Syntax|glob pattern]] in the right-hand operand.
* <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).
* <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).
* <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://secure.php.net/manual/en/reference.pcre.pattern.modifiers.php in PHP]); for <code>irlike</code> both <code>PCRE_CASELESS</code> and <code>PCRE_UTF8</code> are enabled (modifier <code>iu</code>).
* <code>if ... then ... else ... end</code>
* <code>... ? ... : ...</code>
* <code>true</code>, <code>false</code> and <code>null</code>
 
*<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>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).
*<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).
*<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>).
 
*<code>if ... then ... end</code>
*<code>if ... then ... else ... end</code>
*<code>... ? ... : ...</code>
*<code>true</code>,<code>false</code>,<code>null</code>
 
'''Examples'''
Line 530 ⟶ 628:
| <code>"a\b" regex "a\\\\b"</code>
| True
| rowspan= "2" | To look for the escape character backslash using regex you need<br /> to use either four backslashes or two <code>\x5C</code>. (Either works fine.)
|-
| <code>"a\b" regex "a\x5C\x5Cb"</code>
Line 537 ⟶ 635:
 
== Functions ==
 
A number of built-in functions are included to ease some common issues. They are executed in the general format <code>functionName( arg1, arg2, arg3 )</code>, and can be used in place of any literal or variable. Its arguments can be given as literals, variables, or even other functions.
A number of built-in functions are included to ease some common issues.They are executed in the general format <code>functionName( arg1, arg2, arg3 )</code>, and can be used in place of any literal or variable.Its arguments can be given as literals, variables, or even other functions.
 
{| class="wikitable sortable"
Line 546 ⟶ 645:
| <code>ucase</code> || Returns the argument converted to upper case.
|-
| <code>length</code> || Returns the length of the string given as the argument. If the argument is an array, returns its number of elements.
|-
| <code>string</code> || Casts to string data type. If the argument is an array, implodes it with linebreaks.
|-
| <code>int</code> || Casts to integer data type.
Line 556 ⟶ 655:
| <code>bool</code> || Casts to boolean data type.
|-
| <code>norm</code> || Equivalent to  <code>rmwhitespace(rmspecials(rmdoubles(ccnorm(arg1))))</code>.
|-
| <code>ccnorm</code> || Normalises confusable/similar characters in the argument, and returns a canonical form. A list of characters and their replacements can be found [[phab:source/Equivset/browse/master/data/equivset.in|on git]], ege.g. <code>ccnorm( "Eeèéëēĕėęě3ƐƷ" ) === "EEEEEEEEEEEEE"</code>.<ref name="T27619">Be aware of [[phab:T27619]]. You can use [[Special:AbuseFilter/tools]] to evaluate <code>ccnorm( "your string" )</code> to see which characters are transformed.</ref> The output of this function is always uppercase.
|-
| <code>ccnorm_contains_any</code> || Normalises confusable/similar characters in the arguments, and returns true if the first string contains '''any''' stringsstring from the following arguments (unlimited number of arguments, logic OR mode). A list of characters and their replacements can be found [[phab:source/Equivset/browse/master/data/equivset.in|on git]].
|-
| <code>ccnorm_contains_all</code> || Normalises confusable/similar characters in the arguments, and returns true if the first string contains '''every''' stringsstring from the following arguments (unlimited number of arguments, logic AND mode). A list of characters and their replacements can be found [[phab:source/Equivset/browse/master/data/equivset.in|on git]].
|-
| <code>specialratio</code> || Returns the number of non-alphanumeric characters divided by the total number of characters in the argument.
Line 572 ⟶ 671:
| <code>rmwhitespace</code> || Removes whitespace (spaces, tabs, newlines).
|-
| <code>count</code> || Returns the number of times the needle (first string) appears in the haystack (second string). If only one argument is given, splits it by commas and returns the number of segments.
|-
| <code>rcount</code> || Similar to <code>count</code> but the needle uses a regular expression instead. Can be made case-insensitive by letting the regular expression start with "(?i)".Please note that, for plain strings, this function can be up to 50 times slower than <code>count</code><ref>https://3v4l.org/S6IGP</ref>, so use that one when possible.
|-
| <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 rangesrange (second string, in [[:w:CIDR notation|CIDR notation]]). Only works for anonymous users. Supports both IPv4 and IPv6 addresses.
|-
| <code>contains_any</code> || Returns true if the first string contains '''any''' stringsstring 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> || Returns true if the first string contains '''every''' stringsstring 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> || 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> || Returns the portion of the first string, by offset from the second argument (starts at 0) and maximum length from the third argument (optional).
Line 590 ⟶ 689:
| <code>strlen</code> || Same as <code>length</code>.
|-
| <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> || 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> || 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> || 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> || Same as <code>set</code>.
Line 602 ⟶ 701:
 
=== Examples ===
 
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-functions.t -->
{| class="wikitable"
! Code
! Result
! Comment
|-
| <code>length( "Wikipedia" )</code>
Line 618 ⟶ 718:
| <code>ccnorm( "w1k1p3d14" )</code>
| WIKIPEDIA
| <code>ccnorm</code> output is always uppercase
|-
| <code>ccnorm( "ωɨƙɩᑭƐƉ1α" )</code>
Line 646 ⟶ 746:
|<code>norm( "F00 B@rr" )</code>
|FOBAR
| <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
Line 694 ⟶ 794:
 
== Order of operations ==
Operations are generally done left-to-right, but there is an order to which they are resolved. As soon as the filter fails one of the conditions, it will stop checking the rest of them (due to [[w:short-circuit evaluation|short-circuit evaluation]]) and move on to the next filter (except for [[phab:T43693]]). The evaluation order is:
# Anything surrounded by parentheses (<code>(</code> and <code>)</code>) is evaluated as a single unit.
# Turning variables/literals into their respective data. (i.e., <code>page_namespace</code> to 0)
# Function calls (<code>norm</code>, <code>lcase</code>, etc.)
# Unary <code>+</code> and <code>-</code> (defining positive or negative value, e.g. <code>-1234</code>, <code>+1234</code>)
# Keywords
# Boolean inversion (<code>!x</code>)
# Exponentiation (<code>2**3 → 8</code>)
# Multiplication-related (multiplication, division, modulo)
# Addition and subtraction (<code>3-2 → 1</code>)
# Comparisons. (<code><</code>, <code>></code>, <code>==</code>)
# Boolean operations. (<code>&</code>, <code>|</code>, <code>^</code>)
 
Operations are generally done left-to-right, but there is an order to which they are resolved.As soon as the filter fails one of the conditions, it will stop checking the rest of them (due to [[w:short-circuit evaluation|short-circuit evaluation]]) and move on to the next filter.The evaluation order is:
=== Examples ===
 
* <code>A & B | C</code> is equivalent to <code>(A & B) | C</code>, not to <code>A & (B | C)</code>. In particular, both <code>false & true '''| true'''</code> and <code>false & false '''| true'''</code> evaluates to <code>true</code>.
#Anything surrounded by parentheses (<code>(</code> and <code>)</code>) is evaluated as a single unit.
* <code>A | B & C</code> is equivalent to <code>(A | B) & C</code>, not to <code>A | (B & C)</code>. In particular, both <code>true | true '''& false'''</code> and <code>true | false '''& false'''</code> evaluates to <code>false</code>.
#Turning variables/literals into their respective data. (e.g.,<code>page_namespace</code> to 0)
#Function calls (<code>norm</code>,<code>lcase</code>, etc.)
#Unary <code>+</code> and <code>-</code> (defining positive or negative value, e.g.<code>-1234</code>, <code>+1234</code>)
#Keywords (<code>in</code>, <code>rlike</code>, etc.)
#Boolean inversion (<code>!x</code>)
#Exponentiation (<code>2**3 → 8</code>)
#Multiplication-related (multiplication, division, modulo)
#Addition and subtraction (<code>3-2 → 1</code>)
#Comparisons. (<code><</code>, <code>></code>, <code>==</code>)
#Boolean operations. (<code>&</code>, <code>|</code>, <code>^</code>)
 
=== Examples ===
 
*<code>A & B | C</code> is equivalent to <code>(A & B) | C</code>, not to <code>A & (B | C)</code>.In particular, both <code>false & true '''| true'''</code> and <code>false & false '''| true'''</code> evaluates to <code>true</code>.
*<code>A | B & C</code> is equivalent to <code>(A | B) & C</code>, not to <code>A | (B & C)</code>.In particular, both <code>true | true '''& false'''</code> and <code>true | false '''& false'''</code> evaluates to <code>false</code>.
 
== Condition counting ==
 
== Condition counting ==
The condition limit is (more or less) tracking the number of comparison operators + number of function calls entered.
 
Further explanation on how to reduce conditions used can be found at [[{{ll|Extension:AbuseFilter/Conditions]]}}.
 
== Exclusions ==
 
Although the AbuseFilter examine function will identify "rollback" actions as edits, the AbuseFilter will not evaluate rollback actions for matching.<ref>[[phab:T24713|T24713 - rollback not matched by AF]]</ref>
 
== ExclusionsUseful links ==
Although the AbuseFilter examine function will identify "rollback" actions as edits, the AbuseFilter will not evaluate rollback actions for matching. <ref>[[phab:T24713|T24713 - rollback not matched by AF]]</ref>
 
* [https://php.net/reference.pcre.pattern.syntax PCRE pattern syntax]
== Useful links ==
* [[m:Edit filters benefiting to various local Wikiprojects|Edit filters benefiting to various local Wikiprojects]]
* [https://secure.php.net/manual/en/reference.pcre.pattern.syntax.php PCRE pattern syntax]
* {{ll|Extension:AbuseFilter/Conditions}}
* [[:meta:Edit filters benefiting to various local Wikiprojects]]
* [[Extension:AbuseFilter/Conditions]]
 
== Notes ==
<references/>
222

edits