2020-01-15 16:08:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This service can be used to manage the list of keywords recognized by the Parser
|
|
|
|
*/
|
|
|
|
class KeywordsManager {
|
|
|
|
public const SERVICE_NAME = 'AbuseFilterKeywordsManager';
|
|
|
|
|
Reorder messages that describe operators
Make the order of the messages that describe
operators and functions in the en.json file
identical to their order in
KeywordManager::BUILDER_VALUES, which is also
their order in the actual UI of the filter editor.
This only reorders the mesages in the en.json file.
It's not supposed to change anything in
the end users' experience, but it will change
the order in which translators on translatewiki.net
see them.
This is a cleanup step towards removing
the explicit operators from the messages,
as suggested in T360909, and this reordering
is hopefully useful even without that change,
for general consistency.
Comments about particular messages:
* abusefilter-edit-builder-vars-timestamp-expanded
is moved to the very end because, despite its key,
it's not actually used in the filter builder.
* old-text, old-html, and minor-edit are moved towards
the end because they are outdated. They are listed
separately from BUILDER_VALUES and they are not used
in the filter builder UI, but they are used in the logs
of previous actions. This patch adds a code comment
for the benefit of developers who touch that code
in the future.
Bug: T360909
Change-Id: I86ecdca5a6173b9068d5e968e69c57c74a379888
2024-03-25 21:21:14 +00:00
|
|
|
/**
|
|
|
|
* Operators and functions that can be used in AbuseFilter code.
|
|
|
|
* They are shown in the dropdown in the filter editor.
|
|
|
|
* Keys of translatable messages with their descriptions are
|
|
|
|
* based on keys of this array.
|
|
|
|
* When editing this list or the messages, keep the order
|
|
|
|
* consistent in both lists.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-01-15 16:08:53 +00:00
|
|
|
private const BUILDER_VALUES = [
|
|
|
|
'op-arithmetic' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-addition
|
2020-01-15 16:08:53 +00:00
|
|
|
'+' => 'addition',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-subtraction
|
2020-01-15 16:08:53 +00:00
|
|
|
'-' => 'subtraction',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-multiplication
|
2020-01-15 16:08:53 +00:00
|
|
|
'*' => 'multiplication',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-divide
|
2020-01-15 16:08:53 +00:00
|
|
|
'/' => 'divide',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-modulo
|
2020-01-15 16:08:53 +00:00
|
|
|
'%' => 'modulo',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-arithmetic-pow
|
2020-01-15 16:08:53 +00:00
|
|
|
'**' => 'pow'
|
|
|
|
],
|
|
|
|
'op-comparison' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-equal
|
2020-01-15 16:08:53 +00:00
|
|
|
'==' => 'equal',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-equal-strict
|
2020-01-15 16:08:53 +00:00
|
|
|
'===' => 'equal-strict',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-notequal
|
2020-01-15 16:08:53 +00:00
|
|
|
'!=' => 'notequal',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-notequal-strict
|
2020-01-15 16:08:53 +00:00
|
|
|
'!==' => 'notequal-strict',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-lt
|
2020-01-15 16:08:53 +00:00
|
|
|
'<' => 'lt',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-gt
|
2020-01-15 16:08:53 +00:00
|
|
|
'>' => 'gt',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-lte
|
2020-01-15 16:08:53 +00:00
|
|
|
'<=' => 'lte',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-comparison-gte
|
2020-01-15 16:08:53 +00:00
|
|
|
'>=' => 'gte'
|
|
|
|
],
|
|
|
|
'op-bool' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-bool-not
|
2020-01-15 16:08:53 +00:00
|
|
|
'!' => 'not',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-bool-and
|
2020-01-15 16:08:53 +00:00
|
|
|
'&' => 'and',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-bool-or
|
2020-01-15 16:08:53 +00:00
|
|
|
'|' => 'or',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-op-bool-xor
|
2020-01-15 16:08:53 +00:00
|
|
|
'^' => 'xor'
|
|
|
|
],
|
|
|
|
'misc' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-in
|
2020-01-15 16:08:53 +00:00
|
|
|
'in' => 'in',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-contains
|
2020-01-15 16:08:53 +00:00
|
|
|
'contains' => 'contains',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-like
|
2020-01-15 16:08:53 +00:00
|
|
|
'like' => 'like',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-stringlit
|
2020-01-15 16:08:53 +00:00
|
|
|
'""' => 'stringlit',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-rlike
|
2020-01-15 16:08:53 +00:00
|
|
|
'rlike' => 'rlike',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-irlike
|
2020-01-15 16:08:53 +00:00
|
|
|
'irlike' => 'irlike',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-tern
|
2020-01-15 16:08:53 +00:00
|
|
|
'cond ? iftrue : iffalse' => 'tern',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-cond
|
2020-01-15 16:08:53 +00:00
|
|
|
'if cond then iftrue else iffalse end' => 'cond',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-misc-cond-short
|
2020-01-15 16:08:53 +00:00
|
|
|
'if cond then iftrue end' => 'cond-short',
|
|
|
|
],
|
|
|
|
'funcs' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-length
|
2020-01-15 16:08:53 +00:00
|
|
|
'length(string)' => 'length',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-lcase
|
2020-01-15 16:08:53 +00:00
|
|
|
'lcase(string)' => 'lcase',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ucase
|
2020-01-15 16:08:53 +00:00
|
|
|
'ucase(string)' => 'ucase',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ccnorm
|
2020-01-15 16:08:53 +00:00
|
|
|
'ccnorm(string)' => 'ccnorm',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ccnorm-contains-any
|
2020-01-15 16:08:53 +00:00
|
|
|
'ccnorm_contains_any(haystack,needle1,needle2,..)' => 'ccnorm-contains-any',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ccnorm-contains-all
|
2020-01-15 16:08:53 +00:00
|
|
|
'ccnorm_contains_all(haystack,needle1,needle2,..)' => 'ccnorm-contains-all',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-rmdoubles
|
2020-01-15 16:08:53 +00:00
|
|
|
'rmdoubles(string)' => 'rmdoubles',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-specialratio
|
2020-01-15 16:08:53 +00:00
|
|
|
'specialratio(string)' => 'specialratio',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-norm
|
2020-01-15 16:08:53 +00:00
|
|
|
'norm(string)' => 'norm',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-count
|
2020-01-15 16:08:53 +00:00
|
|
|
'count(needle,haystack)' => 'count',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-rcount
|
2020-01-15 16:08:53 +00:00
|
|
|
'rcount(needle,haystack)' => 'rcount',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-get_matches
|
2020-01-15 16:08:53 +00:00
|
|
|
'get_matches(needle,haystack)' => 'get_matches',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-rmwhitespace
|
2020-01-15 16:08:53 +00:00
|
|
|
'rmwhitespace(text)' => 'rmwhitespace',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-rmspecials
|
2020-01-15 16:08:53 +00:00
|
|
|
'rmspecials(text)' => 'rmspecials',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ip_in_range
|
2020-01-15 16:08:53 +00:00
|
|
|
'ip_in_range(ip, range)' => 'ip_in_range',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-ip_in_ranges
|
2022-05-08 01:14:40 +00:00
|
|
|
'ip_in_ranges(ip, range1, range2, ...)' => 'ip_in_ranges',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-contains-any
|
2020-01-15 16:08:53 +00:00
|
|
|
'contains_any(haystack,needle1,needle2,...)' => 'contains-any',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-contains-all
|
2020-01-15 16:08:53 +00:00
|
|
|
'contains_all(haystack,needle1,needle2,...)' => 'contains-all',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-equals-to-any
|
2020-01-15 16:08:53 +00:00
|
|
|
'equals_to_any(haystack,needle1,needle2,...)' => 'equals-to-any',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-substr
|
2020-01-15 16:08:53 +00:00
|
|
|
'substr(subject, offset, length)' => 'substr',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-strpos
|
2020-01-15 16:08:53 +00:00
|
|
|
'strpos(haystack, needle)' => 'strpos',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-str_replace
|
2020-01-15 16:08:53 +00:00
|
|
|
'str_replace(subject, search, replace)' => 'str_replace',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-str_replace_regexp
|
2022-04-17 15:05:10 +00:00
|
|
|
'str_replace_regexp(subject, search, replace)' => 'str_replace_regexp',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-rescape
|
2020-01-15 16:08:53 +00:00
|
|
|
'rescape(string)' => 'rescape',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-set_var
|
2020-01-15 16:08:53 +00:00
|
|
|
'set_var(var,value)' => 'set_var',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-funcs-sanitize
|
2020-01-15 16:08:53 +00:00
|
|
|
'sanitize(string)' => 'sanitize',
|
|
|
|
],
|
|
|
|
'vars' => [
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-timestamp
|
2020-01-15 16:08:53 +00:00
|
|
|
'timestamp' => 'timestamp',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-accountname
|
2020-01-15 16:08:53 +00:00
|
|
|
'accountname' => 'accountname',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-action
|
2020-01-15 16:08:53 +00:00
|
|
|
'action' => 'action',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-addedlines
|
2020-01-15 16:08:53 +00:00
|
|
|
'added_lines' => 'addedlines',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-delta
|
2020-01-15 16:08:53 +00:00
|
|
|
'edit_delta' => 'delta',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-diff
|
2020-01-15 16:08:53 +00:00
|
|
|
'edit_diff' => 'diff',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-newsize
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_size' => 'newsize',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-oldsize
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_size' => 'oldsize',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-new-content-model
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_content_model' => 'new-content-model',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-old-content-model
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_content_model' => 'old-content-model',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-removedlines
|
2020-01-15 16:08:53 +00:00
|
|
|
'removed_lines' => 'removedlines',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-summary
|
2020-01-15 16:08:53 +00:00
|
|
|
'summary' => 'summary',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-id
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_id' => 'page-id',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-ns
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_namespace' => 'page-ns',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-title
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_title' => 'page-title',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-prefixedtitle
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_prefixedtitle' => 'page-prefixedtitle',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-age
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_age' => 'page-age',
|
2022-11-26 13:20:37 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-page-last-edit-age
|
|
|
|
'page_last_edit_age' => 'page-last-edit-age',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-id
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_id' => 'movedfrom-id',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-ns
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_namespace' => 'movedfrom-ns',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-title
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_title' => 'movedfrom-title',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-prefixedtitle
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_prefixedtitle' => 'movedfrom-prefixedtitle',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-age
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_age' => 'movedfrom-age',
|
2022-11-26 13:20:37 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-last-edit-age
|
|
|
|
'moved_from_last_edit_age' => 'movedfrom-last-edit-age',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-id
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_id' => 'movedto-id',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-ns
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_namespace' => 'movedto-ns',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-title
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_title' => 'movedto-title',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-prefixedtitle
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_prefixedtitle' => 'movedto-prefixedtitle',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-age
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_age' => 'movedto-age',
|
2022-11-26 13:20:37 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-last-edit-age
|
|
|
|
'moved_to_last_edit_age' => 'movedto-last-edit-age',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-editcount
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_editcount' => 'user-editcount',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-age
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_age' => 'user-age',
|
2024-03-22 13:40:06 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-unnamed-ip
|
|
|
|
'user_unnamed_ip' => 'user-unnamed-ip',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-name
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_name' => 'user-name',
|
2024-02-27 17:25:35 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-type
|
|
|
|
'user_type' => 'user-type',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-groups
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_groups' => 'user-groups',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-rights
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_rights' => 'user-rights',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-blocked
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_blocked' => 'user-blocked',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-user-emailconfirm
|
2020-01-15 16:08:53 +00:00
|
|
|
'user_emailconfirm' => 'user-emailconfirm',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-old-wikitext
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_wikitext' => 'old-wikitext',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-new-wikitext
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_wikitext' => 'new-wikitext',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-added-links
|
2020-01-15 16:08:53 +00:00
|
|
|
'added_links' => 'added-links',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-removed-links
|
2020-01-15 16:08:53 +00:00
|
|
|
'removed_links' => 'removed-links',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-all-links
|
2020-01-15 16:08:53 +00:00
|
|
|
'all_links' => 'all-links',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-new-pst
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_pst' => 'new-pst',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-diff-pst
|
2020-01-15 16:08:53 +00:00
|
|
|
'edit_diff_pst' => 'diff-pst',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-addedlines-pst
|
2020-01-15 16:08:53 +00:00
|
|
|
'added_lines_pst' => 'addedlines-pst',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-new-text
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_text' => 'new-text',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-new-html
|
2020-01-15 16:08:53 +00:00
|
|
|
'new_html' => 'new-html',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-restrictions-edit
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_restrictions_edit' => 'restrictions-edit',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-restrictions-move
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_restrictions_move' => 'restrictions-move',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-restrictions-create
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_restrictions_create' => 'restrictions-create',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-restrictions-upload
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_restrictions_upload' => 'restrictions-upload',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-recent-contributors
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_recent_contributors' => 'recent-contributors',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-first-contributor
|
2020-01-15 16:08:53 +00:00
|
|
|
'page_first_contributor' => 'first-contributor',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-restrictions-edit
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_restrictions_edit' => 'movedfrom-restrictions-edit',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-restrictions-move
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_restrictions_move' => 'movedfrom-restrictions-move',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-restrictions-create
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_restrictions_create' => 'movedfrom-restrictions-create',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-restrictions-upload
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_restrictions_upload' => 'movedfrom-restrictions-upload',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-recent-contributors
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_recent_contributors' => 'movedfrom-recent-contributors',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedfrom-first-contributor
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_from_first_contributor' => 'movedfrom-first-contributor',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-restrictions-edit
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_restrictions_edit' => 'movedto-restrictions-edit',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-restrictions-move
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_restrictions_move' => 'movedto-restrictions-move',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-restrictions-create
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_restrictions_create' => 'movedto-restrictions-create',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-restrictions-upload
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_restrictions_upload' => 'movedto-restrictions-upload',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-recent-contributors
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_recent_contributors' => 'movedto-recent-contributors',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-movedto-first-contributor
|
2020-01-15 16:08:53 +00:00
|
|
|
'moved_to_first_contributor' => 'movedto-first-contributor',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-old-links
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_links' => 'old-links',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-sha1
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_sha1' => 'file-sha1',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-size
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_size' => 'file-size',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-mime
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_mime' => 'file-mime',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-mediatype
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_mediatype' => 'file-mediatype',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-width
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_width' => 'file-width',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-height
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_height' => 'file-height',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-file-bits-per-channel
|
2020-01-15 16:08:53 +00:00
|
|
|
'file_bits_per_channel' => 'file-bits-per-channel',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-wiki-name
|
2020-01-15 16:08:53 +00:00
|
|
|
'wiki_name' => 'wiki-name',
|
2023-11-08 16:34:08 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-wiki-language
|
2020-01-15 16:08:53 +00:00
|
|
|
'wiki_language' => 'wiki-language',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
Reorder messages that describe operators
Make the order of the messages that describe
operators and functions in the en.json file
identical to their order in
KeywordManager::BUILDER_VALUES, which is also
their order in the actual UI of the filter editor.
This only reorders the mesages in the en.json file.
It's not supposed to change anything in
the end users' experience, but it will change
the order in which translators on translatewiki.net
see them.
This is a cleanup step towards removing
the explicit operators from the messages,
as suggested in T360909, and this reordering
is hopefully useful even without that change,
for general consistency.
Comments about particular messages:
* abusefilter-edit-builder-vars-timestamp-expanded
is moved to the very end because, despite its key,
it's not actually used in the filter builder.
* old-text, old-html, and minor-edit are moved towards
the end because they are outdated. They are listed
separately from BUILDER_VALUES and they are not used
in the filter builder UI, but they are used in the logs
of previous actions. This patch adds a code comment
for the benefit of developers who touch that code
in the future.
Bug: T360909
Change-Id: I86ecdca5a6173b9068d5e968e69c57c74a379888
2024-03-25 21:21:14 +00:00
|
|
|
/**
|
|
|
|
* Old vars which aren't in use anymore.
|
|
|
|
* The translatable messages that are based
|
|
|
|
* on them are not shown in the filter editor,
|
|
|
|
* but may still be shown in the log descriptions of
|
|
|
|
* filter actions that were taken by filters
|
|
|
|
* that used them.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-01-15 16:08:53 +00:00
|
|
|
private const DISABLED_VARS = [
|
Reorder messages that describe operators
Make the order of the messages that describe
operators and functions in the en.json file
identical to their order in
KeywordManager::BUILDER_VALUES, which is also
their order in the actual UI of the filter editor.
This only reorders the mesages in the en.json file.
It's not supposed to change anything in
the end users' experience, but it will change
the order in which translators on translatewiki.net
see them.
This is a cleanup step towards removing
the explicit operators from the messages,
as suggested in T360909, and this reordering
is hopefully useful even without that change,
for general consistency.
Comments about particular messages:
* abusefilter-edit-builder-vars-timestamp-expanded
is moved to the very end because, despite its key,
it's not actually used in the filter builder.
* old-text, old-html, and minor-edit are moved towards
the end because they are outdated. They are listed
separately from BUILDER_VALUES and they are not used
in the filter builder UI, but they are used in the logs
of previous actions. This patch adds a code comment
for the benefit of developers who touch that code
in the future.
Bug: T360909
Change-Id: I86ecdca5a6173b9068d5e968e69c57c74a379888
2024-03-25 21:21:14 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-old-text
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_text' => 'old-text',
|
Reorder messages that describe operators
Make the order of the messages that describe
operators and functions in the en.json file
identical to their order in
KeywordManager::BUILDER_VALUES, which is also
their order in the actual UI of the filter editor.
This only reorders the mesages in the en.json file.
It's not supposed to change anything in
the end users' experience, but it will change
the order in which translators on translatewiki.net
see them.
This is a cleanup step towards removing
the explicit operators from the messages,
as suggested in T360909, and this reordering
is hopefully useful even without that change,
for general consistency.
Comments about particular messages:
* abusefilter-edit-builder-vars-timestamp-expanded
is moved to the very end because, despite its key,
it's not actually used in the filter builder.
* old-text, old-html, and minor-edit are moved towards
the end because they are outdated. They are listed
separately from BUILDER_VALUES and they are not used
in the filter builder UI, but they are used in the logs
of previous actions. This patch adds a code comment
for the benefit of developers who touch that code
in the future.
Bug: T360909
Change-Id: I86ecdca5a6173b9068d5e968e69c57c74a379888
2024-03-25 21:21:14 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-old-html
|
2020-01-15 16:08:53 +00:00
|
|
|
'old_html' => 'old-html',
|
Reorder messages that describe operators
Make the order of the messages that describe
operators and functions in the en.json file
identical to their order in
KeywordManager::BUILDER_VALUES, which is also
their order in the actual UI of the filter editor.
This only reorders the mesages in the en.json file.
It's not supposed to change anything in
the end users' experience, but it will change
the order in which translators on translatewiki.net
see them.
This is a cleanup step towards removing
the explicit operators from the messages,
as suggested in T360909, and this reordering
is hopefully useful even without that change,
for general consistency.
Comments about particular messages:
* abusefilter-edit-builder-vars-timestamp-expanded
is moved to the very end because, despite its key,
it's not actually used in the filter builder.
* old-text, old-html, and minor-edit are moved towards
the end because they are outdated. They are listed
separately from BUILDER_VALUES and they are not used
in the filter builder UI, but they are used in the logs
of previous actions. This patch adds a code comment
for the benefit of developers who touch that code
in the future.
Bug: T360909
Change-Id: I86ecdca5a6173b9068d5e968e69c57c74a379888
2024-03-25 21:21:14 +00:00
|
|
|
// Generates abusefilter-edit-builder-vars-minor-edit
|
2020-01-15 16:08:53 +00:00
|
|
|
'minor_edit' => 'minor-edit'
|
|
|
|
];
|
|
|
|
|
|
|
|
private const DEPRECATED_VARS = [
|
|
|
|
'article_text' => 'page_title',
|
|
|
|
'article_prefixedtext' => 'page_prefixedtitle',
|
|
|
|
'article_namespace' => 'page_namespace',
|
|
|
|
'article_articleid' => 'page_id',
|
|
|
|
'article_restrictions_edit' => 'page_restrictions_edit',
|
|
|
|
'article_restrictions_move' => 'page_restrictions_move',
|
|
|
|
'article_restrictions_create' => 'page_restrictions_create',
|
|
|
|
'article_restrictions_upload' => 'page_restrictions_upload',
|
|
|
|
'article_recent_contributors' => 'page_recent_contributors',
|
|
|
|
'article_first_contributor' => 'page_first_contributor',
|
|
|
|
'moved_from_text' => 'moved_from_title',
|
|
|
|
'moved_from_prefixedtext' => 'moved_from_prefixedtitle',
|
|
|
|
'moved_from_articleid' => 'moved_from_id',
|
|
|
|
'moved_to_text' => 'moved_to_title',
|
|
|
|
'moved_to_prefixedtext' => 'moved_to_prefixedtitle',
|
|
|
|
'moved_to_articleid' => 'moved_to_id',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var string[][] Final list of builder values */
|
|
|
|
private $builderValues;
|
|
|
|
|
|
|
|
/** @var string[] Final list of deprecated vars */
|
|
|
|
private $deprecatedVars;
|
|
|
|
|
|
|
|
/** @var AbuseFilterHookRunner */
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param AbuseFilterHookRunner $hookRunner
|
|
|
|
*/
|
|
|
|
public function __construct( AbuseFilterHookRunner $hookRunner ) {
|
|
|
|
$this->hookRunner = $hookRunner;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDisabledVariables(): array {
|
|
|
|
return self::DISABLED_VARS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDeprecatedVariables(): array {
|
|
|
|
if ( $this->deprecatedVars === null ) {
|
|
|
|
$this->deprecatedVars = self::DEPRECATED_VARS;
|
2021-03-06 17:18:07 +00:00
|
|
|
$this->hookRunner->onAbuseFilter_deprecatedVariables( $this->deprecatedVars );
|
2020-01-15 16:08:53 +00:00
|
|
|
}
|
|
|
|
return $this->deprecatedVars;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBuilderValues(): array {
|
|
|
|
if ( $this->builderValues === null ) {
|
|
|
|
$this->builderValues = self::BUILDER_VALUES;
|
2021-03-06 17:18:07 +00:00
|
|
|
$this->hookRunner->onAbuseFilter_builder( $this->builderValues );
|
2020-01-15 16:08:53 +00:00
|
|
|
}
|
|
|
|
return $this->builderValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isVarDisabled( string $name ): bool {
|
|
|
|
return array_key_exists( $name, self::DISABLED_VARS );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isVarDeprecated( string $name ): bool {
|
|
|
|
return array_key_exists( $name, $this->getDeprecatedVariables() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isVarInUse( string $name ): bool {
|
|
|
|
return array_key_exists( $name, $this->getVarsMappings() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the given name corresponds to a known variable.
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function varExists( string $name ): bool {
|
|
|
|
return $this->isVarInUse( $name ) ||
|
|
|
|
$this->isVarDisabled( $name ) ||
|
|
|
|
$this->isVarDeprecated( $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the message for a builtin variable; takes deprecated variables into account.
|
|
|
|
* Returns null for non-builtin variables.
|
|
|
|
*
|
|
|
|
* @param string $var
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getMessageKeyForVar( string $var ): ?string {
|
|
|
|
if ( !$this->varExists( $var ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ( $this->isVarDeprecated( $var ) ) {
|
|
|
|
$var = $this->getDeprecatedVariables()[$var];
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = self::DISABLED_VARS[$var] ??
|
|
|
|
$this->getVarsMappings()[$var];
|
|
|
|
return "abusefilter-edit-builder-vars-$key";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getVarsMappings(): array {
|
|
|
|
return $this->getBuilderValues()['vars'];
|
|
|
|
}
|
2018-08-28 17:22:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of core variables, i.e. variables defined in AbuseFilter (ignores hooks).
|
|
|
|
* You usually want to use getVarsMappings(), not this one.
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function getCoreVariables(): array {
|
2018-08-28 17:22:16 +00:00
|
|
|
return array_keys( self::BUILDER_VALUES['vars'] );
|
|
|
|
}
|
2020-01-15 16:08:53 +00:00
|
|
|
}
|