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

(Translation code removal)
 
(36 intermediate revisions by the same user not shown)
Line 1:
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.
 
 
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:
Line 22 ⟶ 20:
</syntaxhighlight>
 
==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.
Line 29 ⟶ 27:
 
Example (from [[w:Special:AbuseFilter/79]]):
 
 
<syntaxhighlight lang="c">
Line 40 ⟶ 37:
</syntaxhighlight>
 
==Arrays==
 
==Arrays==
 
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-arrays.t -->
Line 47 ⟶ 43:
AbuseFilter has support for non-associative arrays, which can be used like in the following examples.
 
{{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>}}
 
<syntaxhighlight lang="c">
Line 53 ⟶ 49:
my_array[0] == 5
length(my_array) == 4
int( my_array ) === 4 // <translate><!--T:409--> Same as length</translate>
float( my_array ) === 4.0 // <translate><!--T:410--> Counts the elements</translate>
string(my_array) == "5\n6\n7\n10\n" //<translate><!--T:17--> Note: the last linebreak could be removed in the future</translate>
5 in my_array == true
'5' in my_array == true
'5\n6' in my_array == true //<translate><!--T:18--> Note: this is due to how arrays are casted to string, i.e. by imploding them with linebreaks</translate>
1 in my_array == true //<translate><!--T:19--> Note: this happens because 'in' casts arguments to strings, so the 1 is caught in '10' and returns true.</translate>
my_array[] := 57 // <translate><!--T:411--> This appends an element at the end of the array</translate>
my_array === [ 5, 6, 7, 10, 57 ]
my_array[2] := 42 // <translate><!--T:412--> And this is for changing an element in the array</translate>
my_array === [ 5, 6, 42, 10, 57 ]
</syntaxhighlight>
 
== Comments ==
<translate>
== Comments == <!--T:20-->
 
<!--T:21-->
You can specify comments using the following syntax:
</translate>
/* <translate><!--T:22--> This is a comment</translate> */
 
/* This is a comment */
<translate>
 
== Arithmetic == <!--T:23-->
== Arithmetic ==
 
<!--T:24-->
You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax:
</translate>
 
* <code>-</code> — <translate><!--T:25--> Subtract the right-hand operand from the left-hand operand.</translate>
* <code>+</code> — <translate><!--T:26--> Add the right-hand operand to the left-hand operand.</translate>
* <code>*</code> — <translate><!--T:27--> Multiply the left-hand operand by the right-hand operand.</translate>
* <code>/</code> — <translate><!--T:28--> Divide the left-hand operand by the right-hand operand.</translate>
* <code>**</code> — <translate><!--T:29--> Raise the left-hand operand to the exponential power specified by the right-hand operand.</translate>
* <code>%</code> — <translate><!--T:30--> Return the remainder given when the left-hand operand is divided by the right-hand operand.</translate>
 
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].
<translate>
<!--T:31-->
The type of the returned result is the same that would be returned by PHP, for which a lot of documentation may be found [<tvar|url>https://php.net/language.operators.arithmetic</> online].</translate>
<translate>
<!--T:32-->
More exhaustive examples may be found in [<tvar|url>https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/arith.t</> this AF parser test].
</translate>
 
<!--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%;"|<translate><!--T:33--> Example</translate>
!Result
!<translate><!--T:34--> Result</translate>
|-
| <code>1 + 1</code> || 2
Line 112 ⟶ 99:
|}
 
== Boolean operations ==
<translate>
== Boolean operations == <!--T:35-->
 
<!--T:36-->
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.
<!--T:37-->
* <tvar|1><code>x |& y</code> &mdash; OR</>AND &ndash; returns true if one or moreboth of the conditions isare true.</translate>
*<code>x ^ y</code> &mdash; XOR &ndash; returns true if one, and only one of the two conditions is true.
<translate>
*<code>!x</code> &mdash; NOT &ndash; returns true if the condition is not true.
<!--T:38-->
* <tvar|1><code>x & y</code> &mdash; AND</> &ndash; returns true if both of the conditions are true.</translate>
<translate>
<!--T:39-->
* <tvar|1><code>x ^ y</code> &mdash; XOR</> &ndash; returns true if one, and only one of the two conditions is true.</translate>
<translate>
<!--T:40-->
* <tvar|1><code>!x</code> &mdash; NOT</> &ndash; returns true if the condition is not true.
</translate>
 
'''<translate><!--T:41--> Examples</translate>'''
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-bools.t -->
 
{| class="wikitable"
|-
!Code
! <translate><!--T:42--> Code</translate>
!Result
! <translate><!--T:43--> Result</translate>
|-
| <code>1 <nowiki>|</nowiki> 1</code>
Line 174 ⟶ 151:
 
{{anchor|Simple comparisons}}
<translate>
== Simple comparisons == <!--T:44-->
 
== Simple comparisons ==
<!--T:45-->
 
You can compare [[w:Variable (computer science)|variables]] with other variables and [[w:Operand|literals]] with the following [[w:syntax|syntax]]:
 
*<code>&lt;</code>{{int|comma-separator}}<code>&gt;</code> &mdash; Return true if the left-hand [[w: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>.
<!--T:46-->
* <tvar|1><code>&lt;=</code>{{int|comma-separator}}<code>&gt;=</code></> &mdash; Return true if the left-hand [[w:Operand|operand]] is ''less than or equal to/greater than or equal to'' the right-hand operand respectively.</translate> <translate><!--T:47--> Watch out: operands are casted to strings and, like it happens in PHP, <code><tvar|1>null <</>= any number <tvar|2>=== true</></code> and <code><tvar|3>null ></>= any number <tvar|4>=== false</></code>.</translate>
*<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.
<translate>
*<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.
<!--T:48-->
* <tvar|1><code>&lt;=</code>{{int|comma-separator}}<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.</translate> <translate><!--T:49--> Watch out: operands are casted to strings and, like it happens in PHP, <code><tvar|1>null <=</> any number <tvar|2>=== true</></code> and <code><tvar|3>null >=</> any number <tvar|4>=== false</></code>.</translate>
<translate>
<!--T:50-->
* <tvar|1><code>==</code></> (or <tvar|2><code>=</code></>), <tvar|3><code>!=</code></> &mdash; Return true if the left-hand operand is ''equal to/not equal to'' the right-hand operand respectively.</translate>
<translate>
<!--T:51-->
* <tvar|1><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.</translate>
<!--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%;"| <translate><!--T:52--> Example</translate>
! Result
! <translate><!--T:53--> Result</translate>
|-
|<code>1 == 2</code>|| false
Line 242 ⟶ 211:
|-
|<code>['1'] == '1'</code>
|false<ref><translate><!--T:54--> Comparing arrays to other types will always return false, except for the example above</translate></ref>
|}
 
== Built-in variables ==
<translate>
== Built-in variables == <!--T:55-->
 
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.
<!--T:56-->
The abuse filter passes various variables by name into the parser.</translate>
<translate>
<!--T:57-->
These variables can be accessed by typing their name in, in a place where a literal would work.</translate>
<translate>
<!--T:58-->
You can view the variables associated with each request in the abuse log.
 
===Variables from AbuseFilter=== <!--T:59-->
 
====Variables always available==== <!--T:60-->
 
</translate>
{{Caution|1=<translate><!--T:414--> User-related variables are always available, except for one case: account creation when the creator is not logged in.</translate> <translate><!--T:415--> All variables starting with <tvar|1>=<code>user_</code></> are affected.</translate>}}
 
{| class="wikitable sortable"
! <translate><!--T:61--> Description</translate>
! Name
! <translate><!--T:62--> Name</translate>
! <translate><!--T:63--> Data type</translate>
! Notes
! <translate><!--T:64--> Notes</translate>
|-
| <translate><!--T:65--> Action</translate> || <code>action</code> || <translate><!--T:66--> string</translate> || <translate><!--T:67--> One of the following:</translate> edit, move, createaccount, autocreateaccount, delete, upload<ref name="upload"><translate><!--T:68--> The only variables currently available for file uploads (<tvar|1>action='upload'</>) are <tvar|2>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 <tvar|3>MediaWiki 1.27 [[mw:gerrit:281503|gerrit:281503]]</>).</translate> <translate><!--T:69--> All the <tvar|1>file_*</> variables are unavailable for other actions (including <tvar|2>action='edit'</>).</translate></ref>, stashupload<ref><translate><!--T:70--> Since <tvar|1>MediaWiki 1.28 ([[mw:gerrit:295254|gerrit:295254]])</></translate></ref>
|-
| <translate><!--T:442--> Unix timestamp of change</translate> || <code>timestamp</code> || <translate><!--T:184--> string</translate> || <translate><!--T:185--> <tvar|1>int(timestamp)</> gives you a number with which you can calculate the date, time, day of week, etc.</translate>
|-
| {{int|abusefilter-edit-builder-vars-wiki-name}} || <code>wiki_name</code> || <translate><!--T:435--> string</translate> || <translate><!--T:436--> For instance, this is "enwiki" on the English Wikipedia, and "itwikiquote" on the Italian Wikiquote.</translate>
|-
| {{int|abusefilter-edit-builder-vars-wiki-language}} || <code>wiki_language</code> || <translate><!--T:437--> string</translate> || <translate><!--T:438--> 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".</translate>
|-
| {{int|abusefilter-edit-builder-vars-user-editcount}} || <code>user_editcount</code> || <translate><!--T:71--> integer/null</translate> || <translate><!--T:72--> Null only for unregistered users.</translate>
|-
| {{int|abusefilter-edit-builder-vars-user-name}} || <code>user_name</code> || <translate><!--T:73--> string</translate> || {{note|1=<translate><!--T:74--> For <tvar|1>"createaccount"</> and <tvar|3>"autocreateaccount"</> actions, use <tvar|2><code>accountname</code></> if you want the name of the account being created.</translate>}}
|-
| {{int|abusefilter-edit-builder-vars-user-emailconfirm}} || <code>user_emailconfirm</code> || <translate><!--T:416--> string/null</translate> || <translate><!--T:76--> In the format: YYYYMMDDHHMMSS.</translate> <translate><!--T:77--> Null if the email wasn't confirmed.</translate>
|-
| {{int|abusefilter-edit-builder-vars-user-age}} || <code>user_age</code> || <translate><!--T:78--> integer</translate> || <translate><!--T:79--> In seconds.</translate> <translate><!--T:80--> 0 for unregistered users.</translate>
|-
| {{int|abusefilter-edit-builder-vars-user-blocked}} || <code>user_blocked</code> || <translate><!--T:406--> boolean</translate> || <translate><!--T:81--> <tvar|1>True</> for blocked registered users.</translate> <translate><!--T:407--> Also true for edits from blocked IP addresses, even if the editor is a registered user who is not blocked.</translate> <translate><!--T:408--> <tvar|1>False</> otherwise.</translate> {{note|1=<translate><!--T:82--> This doesn't differentiate between partial and total blocks.</translate>}}
|-
| {{int|abusefilter-edit-builder-vars-user-groups}} || <code>user_groups</code> || <translate><!--T:83--> array of strings</translate> || <translate><!--T:84--> see <tvar|1>[[Special:ListGroupRights]]</></translate>
|-
| {{int|abusefilter-edit-builder-vars-user-rights}} || <code>user_rights</code> || <translate><!--T:85--> array of strings</translate> || <translate><!--T:86--> see <tvar|1>[[Special:ListGroupRights]]</></translate>
|-
| <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"><translate><!--T:87--> integer</translate></span> || {{deprecated-inline}} <translate><!--T:88--> Use <tvar|1><code>page_id</code></> instead.</translate>
|-
| {{ll|Manual:Page_table#page_id|{{int|abusefilter-edit-builder-vars-page-id}}}} <translate><!--T:443--> (found in the page's HTML source - search for wgArticleId)</translate> || <code>page_id</code> || <translate><!--T:89--> integer</translate> || <translate><!--T:90--> In theory this is 0 for new pages, but this is unreliable.</translate> <translate><!--T:91--> If you need an exact result, use "<tvar|1>page_age == 0</>" to identify new page creation.</translate> (<translate><!--T:403--> note that it is slower, though.</translate>)
|-
| <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"><translate><!--T:92--> integer</translate></span> || {{deprecated-inline}} <translate><!--T:93--> Use <tvar|1><code>page_namespace</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-page-ns}} || <code>page_namespace</code> || <translate><!--T:94--> integer</translate> || <translate><!--T:95--> refers to {{<tvar|1>ll|Manual:Namespace#Built-in_namespaces</>|namespace index}}</translate>
|-
| {{int|abusefilter-edit-builder-vars-page-age}} || <code>page_age</code> || <translate><!--T:96--> integer</translate> || <translate><!--T:97--> the number of seconds since the first edit (or 0 for new pages).</translate> <translate><!--T:404--> This is reliable, but it tends to be slow; consider using <tvar|1><code>page_id</code></> if you don't need much precision.</translate>
|-
| <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"><translate><!--T:98--> string</translate></span> || {{deprecated-inline}} <translate><!--T:99--> Use <tvar|1><code>page_title</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-page-title}} || <code>page_title</code> || <translate><!--T:100--> string</translate> ||
|-
| <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"><translate><!--T:101--> string</translate></span> || {{deprecated-inline}} <translate><!--T:102--> Use <tvar|1><code>page_prefixedtitle</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-page-prefixedtitle}} || <code>page_prefixedtitle</code> || <translate><!--T:103--> string</translate> ||
|-
| <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"><translate><!--T:104--> string</translate></span> || {{deprecated-inline}} <translate><!--T:105--> Use <tvar|1><code>page_restrictions_edit</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-restrictions-edit}} || <code>page_restrictions_edit</code> || <translate><!--T:106--> array of strings</translate> ||
|-
| <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"><translate><!--T:107--> string</translate></span> || {{deprecated-inline}} <translate><!--T:108--> Use <tvar|1><code>page_restrictions_move</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-restrictions-move}} || <code>page_restrictions_move</code> || <translate><!--T:109--> array of strings</translate> ||
|-
| <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"><translate><!--T:110--> string</translate></span> || {{deprecated-inline}} <translate><!--T:111--> Use <tvar|1><code>page_restrictions_upload</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-restrictions-upload}} || <code>page_restrictions_upload</code> || <translate><!--T:112--> array of strings</translate> ||
|-
| <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"><translate><!--T:113--> string</translate></span> || {{deprecated-inline}} <translate><!--T:114--> Use <tvar|1><code>page_restrictions_create</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-restrictions-create}} || <code>page_restrictions_create</code> || <translate><!--T:115--> array of strings</translate> ||
|-
| <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-inline}} <translate><!--T:116--> Use <tvar|1><code>page_recent_contributors</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-recent-contributors}} || <code>page_recent_contributors</code> || <translate><!--T:117--> array of strings</translate> || <translate><!--T:118--> This tends to be '''slow''' (see [[<tvar|1>#Performance</>|#Performance]]).</translate> <translate><!--T:119--> Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query.</translate> <translate><!--T:120--> This value is empty if the user is the only contributor to the page(?), and only scans the last 100 revisions</translate>
|-
| <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"><translate><!--T:121--> string</translate></span> || {{deprecated-inline}} <translate><!--T:122--> Use <tvar|1><code>page_first_contributor</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-first-contributor}} || <code>page_first_contributor</code> || <translate><!--T:123--> string</translate> || <translate><!--T:124--> This tends to be '''slow''' (see [[<tvar|1>#Performance</>|#Performance]]).</translate><ref><translate><!--T:125--> Several filters (<tvar|1>[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 [<tvar|url>https://logstash.wikimedia.org/app/kibana#/dashboard/941a0560-b9b2-11e7-a3f7-cb9288bcae84</> AbuseFilterSlow Grafana dashboard] (requires logstash access to view).</translate> <translate><!--T:126--> Moving this variable to towards the end of the filter seemed to help.</translate></ref> <translate><!--T:127--> Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query.</translate>
|}
 
==== <translate><!--T:128--> Variables available for some actions</translate> ====
{{Caution|1=<translate><!--T:444--> Always check that the variables you want to use are available for the current action being filtered, e.g. by using the <tvar|1><code>action</code></> variable.</translate> <translate><!--T:445--> Failing to do so (for instance using <tvar|1><code>accountname</code></> for an edit, or <tvar|2><code>edit_delta</code></> for a deletion) will make any code using the variable in question return false.</translate>}}
 
{| class="wikitable sortable"
! <translate><!--T:129--> Description</translate>
! Name
! <translate><!--T:130--> Name</translate>
! <translate><!--T:131--> Data type</translate>
! Notes
! <translate><!--T:132--> Notes</translate>
|-
| {{int|abusefilter-edit-builder-vars-summary}} || <code>summary</code> || <translate><!--T:133--> string</translate> || <translate><!--T:134--> 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.</translate><ref><translate><!--T:135--> See <tvar|1>[[phabricator:T191722]]</></translate></ref>
|-
| <s>{{int|abusefilter-edit-builder-vars-minor-edit}}</s> || <s><code>minor_edit</code></s> || <s><translate><!--T:136--> string</translate></s> || <translate><!--T:137--> Disabled, and set to false for all entries between 2016 and 2018.</translate><ref><translate><!--T:138--> Deprecated with [[<tvar|1>mw:gerrit:296268</>|this commit]] and disabled with [[<tvar|2>mw:gerrit:481544</>|this one]].</translate></ref>
|-
| {{int|abusefilter-edit-builder-vars-old-wikitext}} || <code>old_wikitext</code> || <translate><!--T:139--> string</translate> ||<translate><!--T:140--> This variable can be very large.</translate> <translate><!--T:141--> Consider using <tvar|1><code>removed_lines</code></> if possible to improve performance.</translate>
|-
| {{int|abusefilter-edit-builder-vars-new-wikitext}} || <code>new_wikitext</code> || <translate><!--T:142--> string</translate> || <translate><!--T:143--> This variable can be very large.</translate> <translate><!--T:144--> Consider using <tvar|1><code>added_lines</code></> if possible to improve performance.</translate>
|-
| {{int|abusefilter-edit-builder-vars-diff}} || <code>edit_diff</code> || <translate><!--T:145--> string</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-diff-pst}} || <code>edit_diff_pst</code> || <translate><!--T:146--> string</translate> || <translate><!--T:147--> This tends to be '''slow''' (see [[<tvar|1>#Performance</>|#Performance]]).</translate> <translate><!--T:148--> Checking both <tvar|1><code>added_lines</code></> and <tvar|2><code>removed_lines</code></> is probably more efficient.</translate><ref><translate><!--T:149--> Some filters using this variable have showed up in the AbuseFilterSlow Grafana dashboard ([<tvar|url>https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-2017.11.22/mediawiki?id=AV_j4TTs-DyidI0FMJNq</> example], requires logstash access).</translate> <translate><!--T:150--> For instance, instead of using <tvar|1><code>"text" in edit_diff_pst</code></> (or even <tvar|2><code>edit_diff</code></>), consider something like <tvar|3><code>"text" in added_lines & !("text" in removed_lines)</code></></translate></ref>
|-
| {{int|abusefilter-edit-builder-vars-newsize}} || <code>new_size</code> || <translate><!--T:151--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-oldsize}} || <code>old_size</code> || <translate><!--T:152--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-delta}} || <code>edit_delta</code> || <translate><!--T:153--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-addedlines-pst}} || <code>added_lines_pst</code> || <translate><!--T:156--> array of strings</translate> || <translate><!--T:157--> Use <tvar|1><code>added_lines</code></> if possible, which is more efficient.</translate>
|-
| {{int|abusefilter-edit-builder-vars-addedlines}} || <code>added_lines</code> || <translate><!--T:158--> array of strings</translate> || <translate><!--T:159--> includes all lines in the final diff that begin with <tvar|1>+</></translate>
|-
| {{int|abusefilter-edit-builder-vars-removedlines}} || <code>removed_lines</code> || <translate><!--T:160--> array of strings</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-all-links}} || <code>all_links</code> || <translate><!--T:446--> array of strings</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-old-links}} || <code>old_links</code> || <translate><!--T:447--> array of strings</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-added-links}} || <code>added_links</code> || <translate><!--T:161--> array of strings</translate> || <translate><!--T:162--> This tends to be '''slow''' (see [[<tvar|1>#Performance</>|#Performance]]).</translate> <translate><!--T:163--> Consider checking against <tvar|1><code>added_lines</code></> first, then check <tvar|2><code>added_links</code></> so that fewer edits are slowed down.</translate> <translate><!--T:164--> This follows {{<tvar|1>ll|Help:Links#External_links</>|MediaWiki's rules for external links}}.</translate> <translate><!--T:165--> Only unique links are added to the array.</translate> <translate><!--T:166--> Changing a link will count as 1 added and 1 removed link.</translate>
|-
| {{int|abusefilter-edit-builder-vars-removed-links}} || <code>removed_links</code> || <translate><!--T:167--> array of strings</translate> || <translate><!--T:168--> This tends to be '''slow''' (see [[<tvar|1>#Performance</>|#Performance]]).</translate> <translate><!--T:169--> Consider checking against <tvar|1><code>removed_lines</code></> first, then check <tvar|2><code>removed_links</code></> so that fewer edits are slowed down.</translate> <translate><!--T:170--> This follows {{<tvar|1>ll|Help:Links#External_links</>|MediaWiki's rules for external links}}.</translate> <translate><!--T:171--> Only unique links are added to the array.</translate> <translate><!--T:172--> Changing a link will count as 1 added and 1 removed link.</translate>
|-
| {{int|abusefilter-edit-builder-vars-new-pst}} || <code>new_pst</code> || <translate><!--T:173--> string</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-new-html}} || <code>new_html</code> || <translate><!--T:174--> string</translate> ||<translate><!--T:175--> This variable can be very large.</translate> <translate><!--T:176--> Consider using <tvar|1><code>added_lines</code></> if possible to improve performance.</translate>
|-
| {{int|abusefilter-edit-builder-vars-new-text}} || <code>new_text</code> || <translate><!--T:177--> string</translate> ||<translate><!--T:178--> This variable can be very large.</translate> <translate><!--T:179--> Consider using <tvar|1><code>added_lines</code></> if possible to improve performance.</translate>
|-
| <s>{{int|abusefilter-edit-builder-vars-old-html}}</s> || <s><code>old_html</code></s> || <s><translate><!--T:180--> string</translate></s> || <translate><!--T:181--> Disabled for performance reasons.</translate>
|-
| <s>{{int|abusefilter-edit-builder-vars-old-text}}</s> || <s><code>old_text</code></s> || <s><translate><!--T:182--> string</translate></s> || <translate><!--T:183--> Disabled for performance reasons.</translate>
|-
| {{int|abusefilter-edit-builder-vars-file-sha1}} || <code>file_sha1</code> || <translate><!--T:186--> string</translate> || <ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-size}} || <code>file_size</code> || <translate><!--T:187--> integer</translate> || <translate><!--T:188--> The file size in bytes</translate><ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-width}} || <code>file_width</code> || <translate><!--T:189--> integer</translate> || <translate><!--T:190--> The width in pixels</translate><ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-height}} || <code>file_height</code> || <translate><!--T:191--> integer</translate> || <translate><!--T:192--> The height in pixels</translate><ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-bits-per-channel}} || <code>file_bits_per_channel</code> || <translate><!--T:193--> integer</translate> || <translate><!--T:194--> The amount of bits per color channel</translate><ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-mime}} || <code>file_mime</code> || <translate><!--T:417--> string</translate> || <translate><!--T:418--> The file [[w:MIME|MIME]] type.</translate><ref name=upload/>
|-
| {{int|abusefilter-edit-builder-vars-file-mediatype}} || <code>file_mediatype</code> || <translate><!--T:419--> string</translate> || <translate><!--T:420--> The file media type.</translate><ref><translate><!--T:461--> See [<tvar|1>https://gerrit.wikimedia.org/g/mediawiki/core/+/d887b9ff37a4956f6db15ddeea68e6d933e108c7/includes/libs/mime/defines.php</> the source code] for a list of types.</translate></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"><translate><!--T:195--> integer</translate></span> || {{deprecated-inline}} <translate><!--T:196--> Use <tvar|1><code>moved_to_id</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-id}} || <code>moved_to_id</code> || <translate><!--T:197--> integer</translate> ||
|-
| <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"><translate><!--T:198--> string</translate></span> || {{deprecated-inline}} <translate><!--T:199--> Use <tvar|1><code>moved_to_title</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-title}} || <code>moved_to_title</code> || <translate><!--T:200--> string</translate> ||
|-
| <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"><translate><!--T:201--> string</translate></span> || {{deprecated-inline}} <translate><!--T:202--> Use <tvar|1><code>moved_to_prefixedtitle</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-prefixedtitle}} || <code>moved_to_prefixedtitle</code> || <translate><!--T:203--> string</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-movedto-ns}} || <code>moved_to_namespace</code> || <translate><!--T:421--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-movedto-age}} || <code>moved_to_age</code> || <translate><!--T:205--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-edit}} || <code>moved_to_restrictions_edit</code> || <translate><!--T:422--> array of string</translate> || <translate><!--T:448--> Same as <tvar|1><code>page_restrictions_edit</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-move}} || <code>moved_to_restrictions_move</code> || <translate><!--T:423--> array of string</translate> || <translate><!--T:449--> Same as <tvar|1><code>page_restrictions_move</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-upload}} || <code>moved_to_restrictions_upload</code> || <translate><!--T:424--> array of string</translate> || <translate><!--T:450--> Same as <tvar|1><code>page_restrictions_upload</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-restrictions-create}} || <code>moved_to_restrictions_create</code> || <translate><!--T:425--> array of string</translate> || <translate><!--T:451--> Same as <tvar|1><code>page_restrictions_create</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-recent-contributors}} || <code>moved_to_recent_contributors</code> || <translate><!--T:426--> array of strings</translate> || <translate><!--T:452--> Same as <tvar|1><code>page_recent_contributors</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedto-first-contributor}} || <code>moved_to_first_contributor</code> || <translate><!--T:427--> string</translate> || <translate><!--T:453--> Same as <tvar|1><code>page_first_contributor</code></>, but for the target of the move.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-ns}} || <code>moved_from_namespace</code> || <translate><!--T:428--> integer</translate> ||
|-
| <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"><translate><!--T:207--> string</translate></span> || {{deprecated-inline}} <translate><!--T:208--> Use <tvar|1><code>moved_from_title</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-title}} || <code>moved_from_title</code> || <translate><!--T:209--> string</translate> ||
|-
| <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"><translate><!--T:210--> string</translate></span> || {{deprecated-inline}} <translate><!--T:211--> Use <tvar|1><code>moved_from_prefixedtitle</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-prefixedtitle}} || <code>moved_from_prefixedtitle</code> || <translate><!--T:212--> string</translate> ||
|-
| <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"><translate><!--T:213--> integer</translate></span> || {{deprecated-inline}} <translate><!--T:214--> Use <tvar|1><code>moved_from_id</code></> instead.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-id}} || <code>moved_from_id</code> || <translate><!--T:215--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-age}} || <code>moved_from_age</code> || <translate><!--T:216--> integer</translate> ||
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-edit}} || <code>moved_from_restrictions_edit</code> || <translate><!--T:429--> array of string</translate> || <translate><!--T:454--> Same as <tvar|1><code>page_restrictions_edit</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-move}} || <code>moved_from_restrictions_move</code> || <translate><!--T:430--> array of string</translate> || <translate><!--T:455--> Same as <tvar|1><code>page_restrictions_move</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-upload}} || <code>moved_from_restrictions_upload</code> || <translate><!--T:431--> array of string</translate> || <translate><!--T:456--> Same as <tvar|1><code>page_restrictions_upload</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-restrictions-create}} || <code>moved_from_restrictions_create</code> || <translate><!--T:432--> array of string</translate> || <translate><!--T:457--> Same as <tvar|1><code>page_restrictions_create</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-recent-contributors}} || <code>moved_from_recent_contributors</code> || <translate><!--T:433--> array of strings</translate> || <translate><!--T:458--> Same as <tvar|1><code>page_recent_contributors</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-movedfrom-first-contributor}} || <code>moved_from_first_contributor</code> || <translate><!--T:434--> string</translate> || <translate><!--T:459--> Same as <tvar|1><code>page_first_contributor</code></>, but for the page being moved.</translate>
|-
| {{int|abusefilter-edit-builder-vars-accountname}} || <code>accountname</code> || <translate><!--T:217--> string</translate> ||
|-
|<translate><!--T:218--> Content model of the old revision</translate>
|<code>old_content_model</code>
| string
|<translate><!--T:219--> string</translate>
|<translate><!--T:220--> See <tvar|1>{{ll|Help:ChangeContentModel}}</> for information about content model changes</translate>
|-
|<translate><!--T:221--> Content model of the new revision</translate>
|<code>new_content_model</code>
| string
|<translate><!--T:222--> string</translate>
|<translate><!--T:223--> See <tvar|1>{{ll|Help:ChangeContentModel}}</> for information about content model changes</translate>
|-
|}
 
===Variables from other extensions===
<translate>
===Variables from other extensions=== <!--T:224-->
</translate>
 
{{Note|1=<translate><!--T:470--> 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.</translate> <translate><!--T:471--> See <tvar|1>[[:phab:T102944|T102944]]</>.</translate>|2=warn}}
 
{| class="wikitable sortable"
|+
! <translate><!--T:225--> Description</translate>
! Name
! <translate><!--T:226--> Name</translate>
! <translate><!--T:227--> Data type</translate>
! Values
! <translate><!--T:228--> Values</translate>
! <translate><!--T:229--> Added by</translate>
|-
| {{int|abusefilter-edit-builder-vars-global-user-groups}}
|<code>global_user_groups</code>
| array
|<translate><!--T:230--> array</translate>
|
|{{ll|Extension:CentralAuth|nsp=0}}
Line 491 ⟶ 450:
| <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"><translate><!--T:231--> integer</translate></span>
| {{deprecated-inline}} <translate><!--T:232--> Use <tvar|1><code>board_id</code></> instead.</translate>
|{{ll|Extension:StructuredDiscussions|nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-id}}
|<code>board_id</code>
|<translate><!--T:233--> integer</translate>
|
|{{ll|Extension:StructuredDiscussions|nsp=0}}
Line 503 ⟶ 462:
|{{int|abusefilter-edit-builder-vars-board-namespace}}
|<code>board_namespace</code>
|<translate><!--T:234--> integer</translate>
|<translate><!--T:235--> refers to {{<tvar|1>ll|Manual:Namespace#Built-in_namespaces</>|namespace index}}</translate>
|{{ll|Extension: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"><translate><!--T:236--> string</translate></span>
| {{deprecated-inline}} <translate><!--T:237--> Use <tvar|1><code>board_title</code></> instead.</translate>
|{{ll|Extension:StructuredDiscussions|nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-title}}
|<code>board_title</code>
| string
|<translate><!--T:238--> string</translate>
|
|{{ll|Extension:StructuredDiscussions|nsp=0}}
Line 521 ⟶ 480:
| <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"><translate><!--T:239--> string</translate></span>
| {{deprecated-inline}} <translate><!--T:240--> Use <tvar|1><code>board_prefixedtitle</code></> instead.</translate>
|{{ll|Extension:StructuredDiscussions|nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-board-prefixedtitle}}
|<code>board_prefixedtitle</code>
| string
|<translate><!--T:241--> string</translate>
|
|{{ll|Extension:StructuredDiscussions|nsp=0}}
Line 533 ⟶ 492:
| {{int|abusefilter-edit-builder-vars-translate-source-text}}
|<code>translate_source_text</code>
| string
|<translate><!--T:242--> string</translate>
|
|{{ll|Extension:Translate|nsp=0}}
Line 539 ⟶ 498:
| {{int|abusefilter-edit-builder-vars-translate-target-language}}
|<code>translate_target_language</code>
| string
| <translate><!--T:462--> string</translate>
| <translate><!--T:463--> This is the language code, like <tvar|1><code>en</code></> for English.</translate>
|{{ll|Extension:Translate|nsp=0}}
|-
| {{int|abusefilter-edit-builder-vars-tor-exit-node}}
|<code>tor_exit_node</code>
| boolean
| <translate><!--T:243--> boolean</translate>
| <translate><!--T:244--> true if the action comes from a tor exit node.</translate>
|{{ll|Extension:TorBlock|nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-user-mobile}}
| <code>user_mobile</code>
| <translate><!--T:245--> boolean</translate>
| <translate><!--T:246--> true for mobile users, false otherwise.</translate>
|{{ll|Extension:MobileFrontend|nsp=0}}
|-
|{{int|abusefilter-edit-builder-vars-user-app}}
| <code>user_app</code>
| boolean
| <translate><!--T:247--> boolean</translate>
| <translate><!--T:248--> true if the user is editing from the mobile app, false otherwise.</translate>
|{{ll|Extension:MobileApp|nsp=0}}
|-
| <span style="opacity:0.5"><translate><!--T:464--> Page views</translate>[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"><translate><!--T:252--> integer</translate></span>
| {{deprecated-inline}} <translate><!--T:253--> Use <tvar|1><code>page_views</code></> instead.</translate>
|{{ll|Extension:HitCounters|nsp=0}}
|-
|<translate><!--T:465--> Page views</translate>[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-page-views/&namespace=0]
| <code>page_views</code>
| integer
| <translate><!--T:254--> integer</translate>
| <translate><!--T:255--> the amount of page views</translate>
|{{ll|Extension:HitCounters|nsp=0}}
|-
|<translate><!--T:466--> Source page views</translate>[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-movedfrom-views/&namespace=0]
| <code>moved_from_views</code>
| integer
| <translate><!--T:256--> integer</translate>
| <translate><!--T:257--> the amount of page views of the source page</translate>
|{{ll|Extension:HitCounters|nsp=0}}
|-
|<translate><!--T:467--> Target page views</translate>[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-movedto-views/&namespace=0]
| <code>moved_to_views</code>
| integer
| <translate><!--T:258--> integer</translate>
| <translate><!--T:259--> the amount of page views of the target page</translate>
|{{ll|Extension:HitCounters|nsp=0}}
|-
| <translate><!--T:468--> True if this action was performed through a proxy</translate>[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-is-proxy/&namespace=0]
| <code>is_proxy</code>
| integer
| <translate><!--T:260--> integer</translate>
| <translate><!--T:261--> Whether this action was performed through a proxy</translate>
| {{ll|Extension:AutoProxyBlock|nsp=0}}
|-
|<translate><!--T:469--> Whether the IP address is blocked using the stopforumspam.com list</translate>[https://translatewiki.net/wiki/Special:PrefixIndex?prefix=MediaWiki:abusefilter-edit-builder-vars-sfs-blocked/&namespace=0]
| <code>sfs_blocked</code>
| boolean
| <translate><!--T:262--> boolean</translate>
| <translate><!--T:263--> Whether the IP address is blocked using the <tvar|1>stopforumspam.com</> list</translate>
| {{ll|Extension:StopForumSpam|nsp=0}}
|}
 
=== Notes ===
<translate>
=== Notes === <!--T:264-->
 
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>.
<!--T:265-->
When <tvar|1><code>action='move'</code></>, only the <tvar|2><code>summary</code></>, <tvar|3><code>action</code></>, <tvar|4><code>timestamp</code></> and <tvar|5><code>user_*</code></> variables are available.</translate>
<translate>
<!--T:266-->
The <tvar|1><code>page_*</code></> variables are also available, but the prefix is replaced by <tvar|2><code>moved_from_</code></> and <tvar|3><code>moved_to_</code></>, that represent the values of the original article name and the destination one, respectively.</translate>
<translate>
<!--T:267-->
For example, <tvar|1><code>moved_from_title</code></> and <tvar|2><code>moved_to_title</code></> instead of <tvar|3><code>page_title</code></>.
 
Since MediaWiki 1.28 ([[mw:gerrit: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>.
<!--T:268-->
Since MediaWiki 1.28 (<tvar|1>[[gerrit:295254]]</>), <tvar|2><code>action='upload'</code></> is only used when publishing an upload, and not for uploads to stash.</translate>
<translate>
<!--T:269-->
A new <tvar|1><code>action='stashupload'</code></> is introduced, which is used for all uploads, including uploads to stash.</translate>
<translate>
<!--T:270-->
This behaves like <tvar|1><code>action='upload'</code></> used to, and only provides file metadata variables (<tvar|2><code>file_*</code></>).</translate>
<translate>
<!--T:271-->
Variables related to the page edit, including <tvar|1><code>summary</code></>, <tvar|2><code>new_wikitext</code></> and several others, are now available for <tvar|3><code>action='upload'</code></>.</translate>
<translate>
<!--T:272-->
For every file upload, filters may be called with <tvar|1><code>action='stashupload'</code></> (for uploads to stash), and are always called with <tvar|2><code>action='upload'</code></>; they are not called with <tvar|3><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.
<!--T:273-->
Filter authors should use <tvar|1><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 <tvar|2><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.</translate>
<translate>
<!--T:274-->
This will allow tools that separate uploading the file and publishing the file (e.g. [[UploadWizard]] or [[upload dialog]]) to inform the user of the failure before they spend the time filling in the upload details.
</translate>
 
{{anchor|Performance}}
<translate>
=== Performance === <!--T:275-->
 
=== Performance ===
<!--T:276-->
As noted in the table above, some of these variables can be very slow.</translate>
<translate>
<!--T:277-->
While writing filters, remember that the condition limit is '''not''' a good metric of how heavy filters are.</translate>
<translate>
<!--T:278-->
For instance, variables like <tvar|1><code>*_recent_contributors</code></> or <tvar|2><code>*_links</code></> always need a DB query to be computed, while <tvar|3><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.</translate>
<translate>
<!--T:279-->
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.</translate>
<translate>
<!--T:280-->
Removing the <tvar|1><code>added_links</code></> variable from a single filter, and halving the cases when another filter would use <tvar|2><code>added_lines_pst</code></> brought the average execution time to 50ms.</translate>
<translate>
<!--T:281-->
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:
<!--T:282-->
* Use <tvar|1><code>_links</code></> variables when you need high accuracy and checking for "<tvar|2>http://...</>" in other variables (for instance, <tvar|3><code>added_lines</code></>) could lead to heavy malfunctioning;</translate>
<translate>
<!--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>
<translate>
<!--T:285-->
* 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> <translate><!--T:288-->
This means that one single filter computing this variable counts more or less as dozens of filters using it.
 
*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;
== Keywords == <!--T:289-->
*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>;
</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.
{{note|1=<translate><!--T:290--> Where not specifically stated, keywords cast their operands to strings</translate>}}
 
<translate>
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.
<!--T:291-->
 
== Keywords ==
 
{{note|1=Where not specifically stated, keywords cast their operands to strings}}
The following special keywords are included for often-used functionality:
</translate>
 
* <translate><!--T:292--> <tvar|1><code>like</code></> (or <tvar|2><code>matches</code></>) returns true if the left-hand operand matches the [[w:Glob (programming)#Syntax|glob pattern]] in the right-hand operand.</translate>
* <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>
* <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>
* <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>
 
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>).
<translate>
<!--T:300-->
The system uses [[w:Perl Compatible Regular Expressions|PCRE]].</translate>
<translate>
<!--T:301-->
The only PCRE option enabled is <tvar|1><code>PCRE_UTF8</code></> (modifier <tvar|2><code>u</code></> [<tvar|3>https://php.net/reference.pcre.pattern.modifiers</> in PHP]); for <tvar|4><code>irlike</code></> both <tvar|5><code>PCRE_CASELESS</code></> and <tvar|6><code>PCRE_UTF8</code></> are enabled (modifier <tvar|7><code>iu</code></>).
</translate>
 
* <code>if ... then ... end</code>
* <code>if ... then ... else ... end</code>
* <code>... ? ... : ...</code>
* <code>true</code>, <code>false</code>, <code>null</code>
 
'''<translate><!--T:302--> Examples</translate>'''
<!--Note: these examples are also used in https://phabricator.wikimedia.org/diffusion/EABF/browse/master/tests/parserTests/mwexamples-keywords.t -->
{| class="wikitable"
|-
! Code
! <translate><!--T:400--> Code</translate>
! Result
! <translate><!--T:401--> Result</translate>
! Comment
! <translate><!--T:402--> Comment</translate>
|-
| <code>"1234" like "12?4"</code>
Line 717 ⟶ 620:
| <code> "o" in ["foo", "bar"]</code>
| True
| <translate><!--T:303--> Due to the string cast</translate>
|-
| <code>"foo" regex "\w+"</code>
Line 725 ⟶ 628:
| <code>"a\b" regex "a\\\\b"</code>
| 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>
|-
| <code>"a\b" regex "a\x5C\x5Cb"</code>
Line 731 ⟶ 634:
|}
 
== Functions ==
<translate>
== Functions == <!--T:306-->
 
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.
<!--T:307-->
A number of built-in functions are included to ease some common issues.</translate>
<translate>
<!--T:308-->
They are executed in the general format <tvar|1><code>functionName( arg1, arg2, arg3 )</code></>, and can be used in place of any literal or variable.</translate>
<translate>
<!--T:309-->
Its arguments can be given as literals, variables, or even other functions.
</translate>
 
{| class="wikitable sortable"
! <translate><!--T:310--> name</translate> !! <translate><!--T:311--> description</translate>
|-
| <code>lcase</code> || <translate><!--T:312--> Returns the argument converted to lower case.</translate>
|-
| <code>ucase</code> || <translate><!--T:313--> Returns the argument converted to upper case.</translate>
|-
| <code>length</code> || <translate><!--T:314--> Returns the length of the string given as the argument.</translate> <translate><!--T:315--> If the argument is an array, returns its number of elements.</translate>
|-
| <code>string</code> || <translate><!--T:316--> Casts to string data type.</translate> <translate><!--T:317--> If the argument is an array, implodes it with linebreaks.</translate>
|-
| <code>int</code> || <translate><!--T:318--> Casts to integer data type.</translate>
|-
| <code>float</code> || <translate><!--T:319--> Casts to floating-point data type.</translate>
|-
| <code>bool</code> || <translate><!--T:320--> Casts to boolean data type.</translate>
|-
| <code>norm</code> || <translate><!--T:321--> Equivalent to <tvar|1> <code>rmwhitespace(rmspecials(rmdoubles(ccnorm(arg1))))</code></>.</translate>
|-
| <code>ccnorm</code> || <translate><!--T:322--> Normalises confusable/similar characters in the argument, and returns a canonical form.</translate> <translate><!--T:323--> A list of characters and their replacements can be found [[<tvar|1>phab:source/Equivset/browse/master/data/equivset.in</>|on git]], e.g. <tvar|2><code>ccnorm( "Eeèéëēĕėęě3ƐƷ" ) === "EEEEEEEEEEEEE"</code></>.</translate><ref name="T27619"><translate><!--T:324--> Be aware of <tvar|1>[[phab:T27619]]</>.</translate> <translate><!--T:325--> You can use <tvar|1>[[Special:AbuseFilter/tools]]</> to evaluate <tvar|2><code>ccnorm( "your string" )</code></> to see which characters are transformed.</translate></ref> <translate><!--T:326--> The output of this function is always uppercase.</translate>
|-
| <code>ccnorm_contains_any</code> || <translate><!--T:327--> Normalises confusable/similar characters in the arguments, and returns true if the first string contains '''any''' string from the following arguments (unlimited number of arguments, logic OR mode).</translate> <translate><!--T:328--> A list of characters and their replacements can be found [[<tvar|1>phab:source/Equivset/browse/master/data/equivset.in</>|on git]].</translate>
|-
| <code>ccnorm_contains_all</code> || <translate><!--T:329--> Normalises confusable/similar characters in the arguments, and returns true if the first string contains '''every''' string from the following arguments (unlimited number of arguments, logic AND mode).</translate> <translate><!--T:330--> A list of characters and their replacements can be found [[<tvar|1>phab:source/Equivset/browse/master/data/equivset.in</>|on git]].</translate>
|-
| <code>specialratio</code> || <translate><!--T:331--> Returns the number of non-alphanumeric characters divided by the total number of characters in the argument.</translate>
|-
| <code>rmspecials</code> || <translate><!--T:332--> Removes any special characters in the argument, and returns the result.</translate> <translate><!--T:333--> (Equivalent to <tvar|1>s/[^\p{L}\p{N}]//g</>.)</translate>
|-
| <code>rmdoubles</code> || <translate><!--T:334--> Removes repeated characters in the argument, and returns the result.</translate>
|-
| <code>rmwhitespace</code> || <translate><!--T:335--> Removes whitespace (spaces, tabs, newlines).</translate>
|-
| <code>count</code> || <translate><!--T:336--> Returns the number of times the needle (first string) appears in the haystack (second string).</translate> <translate><!--T:337--> If only one argument is given, splits it by commas and returns the number of segments.</translate>
|-
| <code>rcount</code> || <translate><!--T:338--> Similar to <tvar|1><code>count</code></> but the needle uses a regular expression instead.</translate> <translate><!--T:339--> Can be made case-insensitive by letting the regular expression start with "<tvar|2>(?i)</>".</translate> <translate><!--T:405--> Please note that, for plain strings, this function can be up to 50 times slower than <tvar|1><code>count</code><ref>https://3v4l.org/S6IGP</ref></>, so use that one when possible.</translate>
|-
| <code>get_matches</code> || {{MW version-inline|MW 1.31+}} <translate><!--T:340--> Looks for matches of the regex needle (first string) in the haystack (second string).</translate> <translate><!--T:341--> Returns an array where the 0 element is the whole match and every <tvar|1><code>[n]</code></> element is the match of the n'th capturing group of the needle.</translate> <translate><!--T:342--> Can be made case-insensitive by letting the regular expression start with "<tvar|1>(?i)</>".</translate> <translate><!--T:343--> If a capturing group didn't match, that array position will take value of ''false''.</translate>
|-
| <code>ip_in_range</code> || <translate><!--T:344--> Returns true if user's IP (first string) matches the specified IP range (second string, in [[:enw:CIDR notation|CIDR notation]]).</translate> <translate><!--T:345--> Only works for anonymous users.</translate> <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>
|}
 
=== Examples ===
<translate>
 
=== Examples === <!--T:364-->
</translate>
<!--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 825 ⟶ 718:
| <code>ccnorm( "w1k1p3d14" )</code>
| WIKIPEDIA
|<translate><!--T:368--> <tvar|1><code>ccnorm</code></> output is always uppercase</translate>
|-
| <code>ccnorm( "ωɨƙɩᑭƐƉ1α" )</code>
Line 853 ⟶ 746:
|<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
Line 900 ⟶ 793:
|}
 
== Order of operations ==
<translate>
== Order of operations == <!--T:370-->
 
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:
<!--T:371-->
Operations are generally done left-to-right, but there is an order to which they are resolved.</translate>
<translate>
<!--T:372-->
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.</translate>
<translate>
<!--T:373-->
The evaluation order is:
</translate>
 
# <translate><!--T:374--> Anything surrounded by parentheses (<tvar|1><code>(</code></> and <tvar|2><code>)</code></>) is evaluated as a single unit.</translate>
# <translate><!--T:375--> Turning variables/literals into their respective data. (e.g., <tvar|1><code>page_namespace</code></> to 0)</translate>
# <translate><!--T:376--> Function calls (<tvar|1><code>norm</code></>, <tvar|2><code>lcase</code></>, etc.)</translate>
# <translate><!--T:377--> Unary <tvar|1><code>+</code></> and <tvar|2><code>-</code></> (defining positive or negative value, e.g. <tvar|3><code>-1234</code></>, <tvar|4><code>+1234</code></>)</translate>
# <translate><!--T:378--> Keywords</translate> (<translate><!--T:413--> <tvar|1><code>in</code></>, <tvar|2><code>rlike</code></>, etc.</translate>)
# <translate><!--T:379--> Boolean inversion</translate> (<code>!x</code>)
# <translate><!--T:380--> Exponentiation</translate> (<code>2**3 → 8</code>)
# <translate><!--T:381--> Multiplication-related (multiplication, division, modulo)</translate>
# <translate><!--T:382--> Addition and subtraction</translate> (<code>3-2 → 1</code>)
# <translate><!--T:383--> Comparisons.</translate> (<code><</code>, <code>></code>, <code>==</code>)
# <translate><!--T:384--> Boolean operations.</translate> (<code>&</code>, <code>|</code>, <code>^</code>)
 
=== Examples ===
<translate>
=== Examples === <!--T:385-->
</translate>
* <translate><!--T:386--> <tvar|1><code>A & B | C</code></> is equivalent to <tvar|2><code>(A & B) | C</code></>, not to <tvar|3><code>A & (B | C)</code></>.</translate> <translate><!--T:387--> In particular, both <tvar|1><code>false & true '''| true'''</code></> and <tvar|2><code>false & false '''| true'''</code></> evaluates to <tvar|3><code>true</code></>.</translate>
* <translate><!--T:388--> <tvar|1><code>A | B & C</code></> is equivalent to <tvar|2><code>(A | B) & C</code></>, not to <tvar|3><code>A | (B & C)</code></>.</translate> <translate><!--T:389--> In particular, both <tvar|1><code>true | true '''& false'''</code></> and <tvar|2><code>true | false '''& false'''</code></> evaluates to <tvar|3><code>false</code></>.</translate>
 
*<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>.
<translate>
*<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 == <!--T:390-->
 
== Condition counting ==
 
<!--T:391-->
The condition limit is (more or less) tracking the number of comparison operators + number of function calls entered.
 
<!--T:392-->
Further explanation on how to reduce conditions used can be found at {{ll|Extension:AbuseFilter/Conditions}}.
 
== Exclusions == <!--T:393-->
 
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>
 
== Useful links ==
<!--T:394-->
Although the AbuseFilter examine function will identify "rollback" actions as edits, the AbuseFilter will not evaluate rollback actions for matching.</translate><ref>[[phab:T24713|T24713 - <translate><!--T:395--> rollback not matched by AF</translate>]]</ref>
 
* [https://php.net/reference.pcre.pattern.syntax PCRE pattern syntax]
<translate>
* [[m:Edit filters benefiting to various local Wikiprojects|Edit filters benefiting to various local Wikiprojects]]
== Useful links == <!--T:396-->
</translate>
* [https://php.net/reference.pcre.pattern.syntax <translate><!--T:397--> PCRE pattern syntax</translate>]
* [[m:Edit filters benefiting to various local Wikiprojects|<translate><!--T:398--> Edit filters benefiting to various local Wikiprojects</translate>]]
* {{ll|Extension:AbuseFilter/Conditions}}
 
== Notes ==
<translate>
== Notes == <!--T:399-->
</translate>
<references/>
222

edits