Extension:AbuseFilter/Rules format/hu

From mediawiki.org
This page is a translated version of the page Extension:AbuseFilter/Rules format and the translation is 52% complete.

A szabályok egy egyedi nyelv. Egy C/Java/Perl-szerű nyelv feltételes állításaihoz hasonló formátumúak.

Karakterláncok

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 \n, tab characters with \t, and you can also escape the quote character with a backslash.

Use the + (plus) symbol to concatenate two literal strings or the values of two vars with a string value.

Példák
"Ez egy karakterlánc"
'Ez is egy karakterlánc'
'This string shouldn\'t fail'
"Ebben a karakterláncban\nsortörés van"
1234
1.234
-123

A felhasználó meghatározta változók

You can define custom variables for ease of understanding with the assign symbol := in a line (closed by ;) within a condition. Such variables may use letters, underscores, and numbers (apart from the first character) and are case-insensitive. Példa (w:Special:AbuseFilter/79-ből):

(
	line1:="(\{\{(r|R)eflist|\{\{(r|R)efs|<references\s?/>|</references\s?>)";
	rcount(line1, removed_lines)
) > (
	rcount(line1, added_lines)
)

Tömbök

AbuseFilter has support for non-associative arrays, which can be used like in the following examples.

Vigyázat! Vigyázat: Expressions like page_namespace in [14, 15] may not work as expected. This one will evaluate to true also if page_namespace is 1, 4, or 5. For more information and possible workarounds, please see T181024.
my_array := [ 5, 6, 7, 10 ];
my_array[0] == 5
length(my_array) == 4
int( my_array ) === 4 // Megegyezik a hosszal
float( my_array ) === 4.0 // Counts the elements
string(my_array) == "5\n6\n7\n10\n" // Note: the last linebreak could be removed in the future
5 in my_array == true
'5' in my_array == true
'5\n6' in my_array == true // Note: this is due to how arrays are casted to string, i.e. by imploding them with linebreaks
1 in my_array == true // Note: this happens because 'in' casts arguments to strings, so the 1 is caught in '10' and returns true.
my_array[] := 57; // This appends an element at the end of the array
my_array === [ 5, 6, 7, 10, 57 ]
my_array[2] := 42; // And this is for changing an element in the array
my_array === [ 5, 6, 42, 10, 57 ]

Megjegyzések

You can specify comments using the following syntax:

/* Ez egy megjegyzés */

Számtan

You can use basic arithmetic symbols to do arithmetic on variables and literals with the following syntax:

  • - — A jobb oldali operandus kivonása a bal oldaliból.
  • + — A jobb oldali operandus hozzáadása a bal oldalihoz.
  • * — A bal oldali operandus osztása a jobb oldalival.
  • / — A bal oldali operandus osztása a jobb oldalival.
  • ** — A bal oldali operandus jobb oldali operandussal megegyező kitevőjű hatványra emelése.
  • % — A bal oldali operandus jobb oldali operandussal vett osztási maradéka.

The type of the returned result is the same that would be returned by PHP, for which a lot of documentation may be found online. More exhaustive examples may be found in this AF parser test.

Példa Eredmény
1 + 1 2
2 * 2 4
1 / 2 0.5
9 ** 2 81
6 % 5 1

Boole-műveletek

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.

  • x | y — OR – returns true if one or more of the conditions is true.
  • x & y — AND – returns true if both of the conditions are true.
  • x ^ y — XOR – returns true if one, and only one of the two conditions is true.
  • !x — NOT – returns true if the condition is not true.

Példák

Kód Eredmény
1 | 1 true
1 | 0 true
0 | 0 false
1 & 1 true
1 & 0 false
0 & 0 false
1 ^ 1 false
1 ^ 0 true
0 ^ 0 false
!1 false
!0 true

Egyszerű összehasonlítások

You can compare variables with other variables and literals with the following syntax:

  • <, > — Return true if the left-hand operand is less than/greater than the right-hand operand respectively.

Watch out: operands are casted to strings and, like it happens in PHP, null < any number === true and null > any number === false.

  • <=, >= — Return true if the left-hand operand is less than or equal to/greater than or equal to the right-hand operand respectively.

Watch out: operands are casted to strings and, like it happens in PHP, null <= any number === true and null >= any number === false.

  • == (or =), != — Return true if the left-hand operand is equal to/not equal to the right-hand operand respectively.
  • ===, !== — 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.
Példa Eredmény
1 == 2 false
1 <= 2 true
1 >= 2 false
1 != 2 true
1 < 2 true
1 > 2 false
2 = 2 true
'' == false true
'' === false false
1 == true true
1 === true false
['1','2','3'] == ['1','2','3'] true
[1,2,3] === [1,2,3] true
['1','2','3'] == [1,2,3] true
['1','2','3'] === [1,2,3] false
[1,1,''] == [true, true, false] true
[] == false & [] == null true
['1'] == '1' false[1]

Beépített változók

The abuse filter passes various variables by name into the parser. These variables can be accessed by typing their name in, in a place where a literal would work. You can view the variables associated with each request in the abuse log.

Variables from AbuseFilter

Mindig elérhető változók

Vigyázat! Vigyázat: User-related variables are always available, except for one case: account creation when the creator is not logged in. All variables starting with user_ are affected, except user_type.
Leírás Név Adattípus Megjegyzések
Művelet action sztring Az alábbiak egyike: edit, move, createaccount, autocreateaccount, delete, upload[2], stashupload[3]
A változás Unix-időbélyegzője timestamp sztring int(timestamp) gives you a number with which you can calculate the date, time, day of week, etc.
Wiki adatbázisneve wiki_name sztring For instance, this is "enwiki" on the English Wikipedia, and "itwikiquote" on the Italian Wikiquote.
Wiki nyelvkódja wiki_language sztring 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".
a szerkesztő szerkesztéseinek száma user_editcount integer/null Csak nem regisztrált felhasználók esetén null.
a szerkesztő neve (IP in case the user is not registered) user_name sztring
For "createaccount" and "autocreateaccount" actions, use accountname if you want the name of the account being created.
Type of the user account user_type string The type of the user, which will be one of ip, temp (if the user is using a temporary account ), named, external, or unknown.
az e-mail-cím megerősítésének ideje user_emailconfirm sztring/null YYYYMMDDHHMMSS formátumban. Null, ha az e-mail nem lett megerősítve.
A felhasználó fiókjának életkora user_age integer Másodpercben. Nem regisztrált felhasználók esetén 0.
Ha a felhasználó blokkolva van user_blocked boolean True blokkolt regisztrált felhasználókra. Szintén true blokkolt IP-címekről érkezett szerkesztésekre, akkor is, ha a szerkesztő nem blokkolt regisztrált felhasználó. False ellenkező esetben.
Ez nem különböztet meg részleges és teljes blokkot.
a szerkesztő csoportjai (beleértve az implicit csoportokat is) user_groups sztringek tömbje lásd Special:ListGroupRights
Felhasználó jogai user_rights sztringek tömbje lásd Special:ListGroupRights
oldalazonosító article_articleid integer (deprecated) Use page_id instead.
oldalazonosító (can be seen via "page information" link in sidebar) page_id integer Ez 0 az új oldalakra, de ez nem megbízható korábbi találatok vizsgálatakor. Pontos eredményhez korábbi találatok vizsgálatakor használd a „page_age == 0”-et az újoldal-készítés azonosításához. (Ugyanakkor ez lassabb.) This issue has been fixed in 9369d08, merged on September 11th 2023.
lap névtere article_namespace integer (deprecated) Use page_namespace instead.
lap névtere page_namespace integer refers to namespace index . Check for namespace(s) using expressions like "page_namespace == 2" or "equals_to_any(page_namespace, 1, 3)"
Oldal életkora (másodpercben) page_age integer Az első szerkesztés óta eltelt másodpercek száma (új oldalak esetén 0). This is reliable, but it tends to be slow; consider using page_id if you don't need much precision.
lap címe (névtér nélkül) article_text sztring (deprecated) Use page_title instead.
lap címe (névtér nélkül) page_title sztring
a lap teljes címe article_prefixedtext sztring (deprecated) Use page_prefixedtitle instead.
a lap teljes címe page_prefixedtitle sztring
A lap védelmi szintje (szerkesztésnél) article_restrictions_edit sztring (deprecated) Use page_restrictions_edit instead.
A lap védelmi szintje (szerkesztésnél) page_restrictions_edit sztringek tömbje
A lap védelmi szintje (átnevezésnél) article_restrictions_move sztring (deprecated) Use page_restrictions_move instead.
A lap védelmi szintje (átnevezésnél) page_restrictions_move sztringek tömbje
fájl védelmi szinte (feltöltéskor) article_restrictions_upload sztring (deprecated) Use page_restrictions_upload instead.
fájl védelmi szinte (feltöltéskor) page_restrictions_upload sztringek tömbje
a lap védelmi szintje (létrehozáskor) article_restrictions_create sztring (deprecated) Use page_restrictions_create instead.
a lap védelmi szintje (létrehozáskor) page_restrictions_create sztringek tömbje
a lap utolsó tíz szerkesztője article_recent_contributors array of strings (deprecated) Use page_recent_contributors instead.
a lap utolsó tíz szerkesztője page_recent_contributors sztringek tömbje Ez általában lassú (lásd: #Teljesítmény). Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query. Ez az érték üres, ha a felhasználó a lap egyetlen szerkesztője (?), és csak az utolsó 100 szerkesztést nézi meg
Az első közreműködő ezen az oldalon article_first_contributor sztring (deprecated) Use page_first_contributor instead.
Az első közreműködő ezen az oldalon page_first_contributor sztring Ez általában lassú (lásd: #Teljesítmény).[4] Try to put conditions more likely evaluate to false before this one, to avoid unnecessarily running the query.

Variables available for some actions

Vigyázat! Vigyázat: Always check that the variables you want to use are available for the current action being filtered, e.g. by using the action variable. Failing to do so (for instance using accountname for an edit, or edit_delta for a deletion) will make any code using the variable in question return false.
Edit variables are not available when examining past uploads. (T345896)
Leírás Név Adattípus Megjegyzések
szerkesztési összefoglaló summary sztring 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. The variable contains whatever the user sees in the edit summary window, which may include MediaWiki preloaded section titles.[5]
Apró változtatás? (már nincs használatban) minor_edit sztring Disabled, and set to false for all entries between 2016 and 2018.[6]
A korábbi oldal wikiszövege a szerkesztés előtt old_wikitext sztring This variable can be very large. Consider using removed_lines if possible to improve performance.
Az új oldal wikiszövege szerkesztés után new_wikitext sztring This variable can be very large. Consider using added_lines if possible to improve performance.
A szerkesztés során történt változások Unified diffje edit_diff sztring
A szerkesztés során történt változások Unified diffje, mentés előtti állapotba alakítva edit_diff_pst sztring Ez általában lassú (lásd: #Teljesítmény). Checking both added_lines and removed_lines is probably more efficient.[7]
új lapméret new_size integer
régi lapméret old_size integer
a szerkesztés során történt méretváltozás edit_delta integer
Szerkesztés során hozzáadott sorok, mentés előtti állapotba alakítva added_lines_pst sztringek tömbje Use added_lines if possible, which is more efficient.
Szerkesztés során hozzáadott sorok added_lines sztringek tömbje includes all lines in the final diff that begin with +
Szerkesztés során eltávolított sorok removed_lines sztringek tömbje
az új szövegben lévő összes hivatkozás all_links sztringek tömbje This tends to be slow (see #Performance).
Az oldal hivatkozásai a szerkesztés előtt old_links sztringek tömbje This tends to be slow (see #Performance).
hozzáadott hivatkozások added_links sztringek tömbje Ez általában lassú (lásd: #Teljesítmény). Consider checking against added_lines first, then check added_links so that fewer edits are slowed down. This follows MediaWiki's rules for external links . Only unique links are added to the array. Changing a link will count as 1 added and 1 removed link.
eltávolított hivatkozások removed_links sztringek tömbje Ez általában lassú (lásd: #Teljesítmény). Consider checking against removed_lines first, then check removed_links so that fewer edits are slowed down. This follows MediaWiki's rules for external links . Only unique links are added to the array. Changing a link will count as 1 added and 1 removed link.
Az új oldal wikiszövege, mentés előtti állapotba alakítva new_pst sztring This variable can be very large.
az új változat HTML-lé alakított kódja new_html sztring Ez a változó nagyon nagy lehet. Ha lehet, használd a added_lines-et a teljesítmény növelése érdekében.
az új wikiszöveg, jelölőnyelv nélkül new_text sztring This variable can be very large. Consider using added_lines if possible to improve performance.
A korábbi oldal wikiszövege HTML-ben (már nincs használatban) old_html sztring Letiltva teljesítménybeli okokból.
A régi lap szövege, jelölőnyelv nélkül old_text sztring Letiltva teljesítménybeli okokból.
Time since last page edit (in seconds) page_last_edit_age integer or null null when the page does not exist
A fájl tartalmának SHA1 hash-se file_sha1 sztring [2]
A fájl mérete bájtokban file_size integer A fájl mérete bájtokban[2]
A fájl szélessége pixelben file_width integer Szélesség pixelben[2]
A fájl magassága pixelben file_height integer Magasság pixelben[2]
A fájl színcsatornánkénti bitjei file_bits_per_channel integer Bitek száma színcsatornánként[2]
a fájl MIME-típusa file_mime sztring A fájl MIME-típusa.[2]
a fájl médiatípusa file_mediatype sztring A fájl médiatípusa.[8][2]
átnevezésnél a céllap azonosítója moved_to_articleid integer (deprecated) Use moved_to_id instead.
átnevezésnél a céllap azonosítója moved_to_id integer
átnevezésnél a céllap címe moved_to_text sztring (deprecated) Use moved_to_title instead.
átnevezésnél a céllap címe moved_to_title sztring
átnevezésnél a céllap teljes címe moved_to_prefixedtext sztring (deprecated) Use moved_to_prefixedtitle instead.
átnevezésnél a céllap teljes címe moved_to_prefixedtitle sztring
átnevezésnél a céllap névtere moved_to_namespace integer
A céllap életkora (másodpercben) moved_to_age integer
Time since last move destination page edit (in seconds) moved_to_last_edit_age integer or null null when the target page does not exist
A céllap védelmi szintje (szerkesztésnél) moved_to_restrictions_edit sztringek tömbje Same as page_restrictions_edit, but for the target of the move.
A céllap védelmi szintje (átnevezésnél) moved_to_restrictions_move sztringek tömbje Same as page_restrictions_move, but for the target of the move.
A célfájl védelmi szintje (feltöltéskor) moved_to_restrictions_upload sztringek tömbje Same as page_restrictions_upload, but for the target of the move.
A céllap védelmi szintje (létrehozáskor) moved_to_restrictions_create sztringek tömbje Same as page_restrictions_create, but for the target of the move.
A céllap utolsó tíz szerkesztője moved_to_recent_contributors sztringek tömbje Same as page_recent_contributors, but for the target of the move.
A céllap első közreműködője moved_to_first_contributor sztring Same as page_first_contributor, but for the target of the move.
átnevezésnél a forráslap névtere moved_from_namespace integer
átnevezésnél a forráslap címe moved_from_text sztring (deprecated) Use moved_from_title instead.
átnevezésnél a forráslap címe moved_from_title sztring
átnevezésnél a forráslap teljes címe moved_from_prefixedtext sztring (deprecated) Use moved_from_prefixedtitle instead.
átnevezésnél a forráslap teljes címe moved_from_prefixedtitle sztring
átnevezésnél a forráslap azonosítója moved_from_articleid integer (deprecated) Use moved_from_id instead.
átnevezésnél a forráslap azonosítója moved_from_id integer
Az átnevezendő lap életkora (másodpercben) moved_from_age integer
Time since last move source page edit (in seconds) moved_from_last_edit_age integer
Az átnevezendő lap védelmi szintje (szerkesztésnél) moved_from_restrictions_edit sztringek tömbje Same as page_restrictions_edit, but for the page being moved.
Az átnevezendő lap védelmi szintje (átnevezésnél) moved_from_restrictions_move sztringek tömbje Same as page_restrictions_move, but for the page being moved.
Az átnevezendő fájl védelmi szintje (feltöltéskor) moved_from_restrictions_upload sztringek tömbje Same as page_restrictions_upload, but for the page being moved.
Az átnevezendő lap védelmi szintje (létrehozáskor) moved_from_restrictions_create sztringek tömbje Same as page_restrictions_create, but for the page being moved.
Az átnevezendő lap utolsó tíz szerkesztője moved_from_recent_contributors sztringek tömbje Same as page_recent_contributors, but for the page being moved.
Az átnevezendő lap első közreműködője moved_from_first_contributor sztring Same as page_first_contributor, but for the page being moved.
szerkesztői fiók neve (fióklétrehozáskor) accountname sztring
Content model of the old revision old_content_model sztring A tartalommodell-váltásokról szóló információhoz lásd: Help:ChangeContentModel .
Az új szerkesztés tartalommodellje new_content_model sztring A tartalommodell-váltásokról szóló információkhoz lásd: Help:ChangeContentModel .

Más kiterjesztésekből származó változók

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. Lásd: T102944.
Leírás Név Adattípus Értékek Hozzáadta:
A felhasználó globális csoportjai global_user_groups tömb CentralAuth
A felhasználó globális szerkesztésszáma global_user_editcount integer CentralAuth
Global groups that the user is in (on account creation) global_account_groups array Available only when action is 'createaccount' (then it is always empty) or 'autocreateaccount'. CentralAuth
Global edit count of the user (on account creation) global_account_editcount integer Available only when action is 'createaccount' (then it is always zero) or 'autocreateaccount'. CentralAuth
OAuth consumer used to perform this change oauth_consumer integer OAuth
Strukturált beszélgetőoldal lapazonosítója (ID-je) board_articleid integer (deprecated) Use board_id instead. StructuredDiscussions
Strukturált beszélgetőoldal lapazonosítója (ID-je) board_id integer StructuredDiscussions
Strukturált beszélgetőoldal névtere board_namespace integer refers to namespace index StructuredDiscussions
Strukturált beszélgetőoldal címe (névtér nélkül) board_text sztring (deprecated) Use board_title instead. StructuredDiscussions
Strukturált beszélgetőoldal címe (névtér nélkül) board_title sztring StructuredDiscussions
Strukturált beszélgetőoldal teljes címe board_prefixedtext sztring (deprecated) Use board_prefixedtitle instead. StructuredDiscussions
Strukturált beszélgetőoldal teljes címe board_prefixedtitle sztring StructuredDiscussions
A fordítási egység forrásszövege translate_source_text sztring Kiterjesztés:Translate
A fordítás célnyelve translate_target_language sztring Ez a nyelvkód, például az angol esetén en. Kiterjesztés:Translate
A szerkesztés egy tor-csomópontról készült vagy sem. tor_exit_node boolean true if the action comes from a tor exit node. Kiterjesztés:TorBlock
Egy felhasználó a mobil felületen keresztül fordít-e. user_mobile boolean Igaz a mobilhasználókra, ellenkező esetben hamis. MobileFrontend
A felhasználó mobilalkalmazásból szerkesztett-e user_app boolean true if the user is editing from the mobile app, false otherwise. MobileApp
Megtekintések[1] article_views integer (deprecated) Use page_views instead. HitCounters
Megtekintések[2] page_views integer lapmegtekintések száma HitCounters
forrásmegtekintések száma[3] moved_from_views integer a forráslap megtekintéseinek száma HitCounters
Céllapmegtekintések[4] moved_to_views integer a céllap megtekintésszáma HitCounters
A stopforumspam.com-lista alapján van-e az IP-cím blokkolva[5] sfs_blocked boolean Whether the IP address is blocked using the stopforumspam.com list StopForumSpam

Megjegyzések

When action='move', only the summary, action, timestamp and user_* variables are available. The page_* variables are also available, but the prefix is replaced by moved_from_ and moved_to_, that represent the values of the original article name and the destination one, respectively. Például moved_from_title és moved_to_title a page_title helyett.

Since MediaWiki 1.28 (gerrit:295254), action='upload' is only used when publishing an upload, and not for uploads to stash. A new action='stashupload' is introduced, which is used for all uploads, including uploads to stash. This behaves like action='upload' used to, and only provides file metadata variables (file_*). Variables related to the page edit, including summary, new_wikitext and several others, are now available for action='upload'. For every file upload, filters may be called with action='stashupload' (for uploads to stash), and are always called with action='upload'; they are not called with action='edit'.

Filter authors should use action='stashupload' | action='upload' in filter code when a file can be checked based only on the file contents – for example, to reject low-resolution files – and action='upload' only when the wikitext parts of the edit need to be examined too – for example, to reject files with no description. This allows 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.

Teljesítmény

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 *_recent_contributors or *_links always need a DB query to be computed, while *_pst 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 added_links variable from a single filter, and halving the cases when another filter would use added_lines_pst brought the average execution time to 50ms. More specifically:

  • Use _links variables when you need high accuracy and checking for "http://..." in other variables (for instance, added_lines) could lead to heavy malfunctioning;
  • Use _pst 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 added_lines contains ~~~;

  • In general, when dealing with these variables, it's always much better to consume further conditions but avoid computing heavy stuff.

In order to achieve this, always put heavy variables as last conditions.

Last but not least, note that whenever a variable is computed for a given filter, it'll be saved and any other filter will immediately retrieve it. This means that one single filter computing this variable counts more or less as dozens of filters using it.

Kulcsszavak

Where not specifically stated, keywords cast their operands to strings

The following special keywords are included for often-used functionality:

  • like (or matches) returns true if the left-hand operand matches the glob pattern in the right-hand operand.
  • in returns true if the right-hand operand (a string) contains the left-hand operand. Megjegyzés: empty strings are not contained in, nor contain, any other string (not even the empty string itself).
  • contains works like in, but with the left and right-hand operands switched. Megjegyzés: empty strings are not contained in, nor contain, any other string (not even the empty string itself).
  • rlike (or regex) and irlike return true if the left-hand operand matches (contains) the regex pattern in the right-hand operand (irlike is case insensitive).
    • The system uses PCRE.
    • The only PCRE option enabled is PCRE_UTF8 (modifier u in PHP); for irlike both PCRE_CASELESS and PCRE_UTF8 are enabled (modifier iu).
  • if ... then ... end
  • if ... then ... else ... end
  • ... ? ... : ...
  • true, false, null

Példák

Kód Eredmény Megjegyzés
"1234" like "12?4" True
"1234" like "12*" True
"foo" in "foobar" True
"foobar" contains "foo" True
"o" in ["foo", "bar"] True Due to the string cast
"foo" regex "\w+" True
"a\b" regex "a\\\\b" True To look for the escape character backslash using regex you need to use either four backslashes or two \x5C. (Either works fine.)
"a\b" regex "a\x5C\x5Cb" True

Függvények

A number of built-in functions are included to ease some common issues. They are executed in the general format functionName( arg1, arg2, arg3 ), and can be used in place of any literal or variable. Its arguments can be given as literals, variables, or even other functions.

név Leírás
lcase Az argumentum csupa kisbetűssé alakított változatával tér vissza.
ucase Az argumentum nagybetűssé alakított változatával tér vissza.
length Az argumentumként megadott sztring hosszával tér vissza. Ha az argumentum több, annak elemszámával tér vissza.
string Sztring adattípusra alakít át. Ha az argumentum tömb, sortörésekkel választja el.
int Integer adattípusra alakít át.
float Lebegőpontos adattípusra alakít át.
bool Boolean adattípusra alakít át.
norm Ekvivalens a rmwhitespace(rmspecials(rmdoubles(ccnorm(arg1))))-lel.
ccnorm Normalises confusable/similar characters in the argument, and returns a canonical form. A list of characters and their replacements can be found on git, e.g. ccnorm( "Eeèéëēĕėęě3ƐƷ" ) === "EEEEEEEEEEEEE".[9] The output of this function is always uppercase. While not expensive, this function isn't cheap either, and could slow a filter down if called many times.
ccnorm_contains_any Normalises confusable/similar characters in all its arguments, and returns true if the first string contains any string from the following arguments (unlimited number of arguments, logic OR mode). A list of characters and their replacements can be found on git. Due to the usage of ccnorm, this function can be slow if passed too many arguments.
ccnorm_contains_all Normalises confusable/similar characters in all its arguments, and returns true if the first string contains every string from the following arguments (unlimited number of arguments, logic AND mode). A list of characters and their replacements can be found on git. Due to the usage of ccnorm, this function can be slow if passed too many arguments.
specialratio Returns the number of non-alphanumeric characters divided by the total number of characters in the argument.
rmspecials Removes any special characters in the argument, and returns the result. Nem távolítja el az üres karaktereket. (Equivalent to s/[^\p{L}\p{N}\s]//g.)
rmdoubles Eltávolítja az üres karaktereket az argumentumban, és visszatér az eredménnyel.
rmwhitespace Eltávolítja az üres karaktereket (szóközök, tabulátorok, új sorok).
count Returns the number of times the needle (first string) appears in the haystack (second string). If only one argument is given, splits it by commas and returns the number of segments.
rcount Similar to count but the needle uses a regular expression instead. Can be made case-insensitive by letting the regular expression start with "(?i)". Please note that, for plain strings, this function can be up to 50 times slower than count[10], so use that one when possible.
get_matches MW 1.31+ Looks for matches of the regex needle (first string) in the haystack (second string). Returns an array where the 0 element is the whole match and every [n] element is the match of the n'th capturing group of the needle. Can be made case-insensitive by letting the regular expression start with "(?i)". If a capturing group didn't match, that array position will take value of false.
ip_in_range Returns true if user's IP (first string) matches the specified IP range (second string, can be in CIDR notation, explicit notation like "1.1.1.1-2.2.2.2", or a single IP). Only works for anonymous users. Supports both IPv4 and IPv6 addresses.
ip_in_ranges Returns true if user's IP (first string) matches any of the specified IP ranges (following strings in logic OR mode, can be in CIDR notation, explicit notation like "1.1.1.1-2.2.2.2", or a single IP). Only works for anonymous users. Supports both IPv4 and IPv6 addresses.
contains_any Returns true if the first string contains any string from the following arguments (unlimited number of arguments in logic OR mode). If the first argument is an array, it gets casted to string.
contains_all Returns true if the first string contains every string from the following arguments (unlimited number of arguments in logic AND mode). If the first argument is an array, it gets casted to string.
equals_to_any Returns true if the first argument is identical (===) to any of the following ones (unlimited number of arguments). Basically, equals_to_any(a, b, c) is the same as a===b | a===c, but more compact and saves conditions.
substr Returns the portion of the first string, by offset from the second argument (starts at 0) and maximum length from the third argument (optional).
strlen Same as length.
strpos Returns the numeric position of the first occurrence of needle (second string) in the haystack (first string), starting from offset from the third argument (optional, default is 0). This function may return 0 when the needle is found at the beginning of the haystack, so it might be misinterpreted as false value by another comparative operator. The better way is to use === or !== for testing whether it is found. Differently from PHP's strpos(), which returns false when the needle is not found, this function returns -1 when the needle is not found.
str_replace Replaces all occurrences of the search string with the replacement string. The function takes 3 arguments in the following order: text to perform the search on, text to find, replacement text.
str_replace_regexp Replaces all occurrences of the search string with the replacement string using regular expressions. The function takes 3 arguments in the following order: text to perform the search on, regular expression to match, replacement expression.
rescape Returns the argument with some characters preceded with the escape character "\", so that the string can be used in a regular expression without those characters having a special meaning.
set Sets a variable (first string) with a given value (second argument) for further use in the filter. Another syntax: name := value.
set_var Same as set.

Példák

Kód Eredmény Megjegyzés
length( "Wikipedia" ) 9
lcase( "WikiPedia" ) wikipedia
ccnorm( "w1k1p3d14" ) WIKIPEDIA ccnorm output is always uppercase
ccnorm( "ωɨƙɩᑭƐƉ1α" ) WIKIPEDIA
ccnorm_contains_any( "w1k1p3d14", "wiKiP3D1A", "foo", "bar" ) true
ccnorm_contains_any( "w1k1p3d14", "foo", "bar", "baz" ) false
ccnorm_contains_any( "w1k1p3d14 is 4w3s0me", "bar", "baz", "some" ) true
ccnorm( "ìíîïĩїį!ľ₤ĺľḷĿ" ) IIIIIII!LLLLLL
norm( "!!ω..ɨ..ƙ..ɩ..ᑭᑭ..Ɛ.Ɖ@@1%%α!!" ) WIKIPEDAIA
norm( "F00 B@rr" ) FOBAR norm removes whitespace, special characters and duplicates, then uses ccnorm
rmdoubles( "foobybboo" ) fobybo
specialratio( "Wikipedia!" ) 0.1
count( "foo", "foofooboofoo" ) 3
count( "foo,bar,baz" ) 3
rmspecials( "FOOBAR!!1" ) FOOBAR1
rescape( "abc* (def)" ) abc\* \(def\)
str_replace( "foobarbaz", "bar", "-" ) foo-baz
str_replace_regexp( "foobarbaz", "(.)a(.)", "$2a$1" ) foorabzab
ip_in_range( "127.0.10.0", "127.0.0.0/12" ) true
ip_in_ranges( "127.0.10.0", "10.0.0.0/8", "127.0.0.0/12" ) true
contains_any( "foobar", "x", "y", "f" ) true
get_matches( "(foo?ba+r) is (so+ good)", "fobaaar is soooo good to eat" ) ['fobaaar is soooo good', 'fobaaar', 'soooo good']

Műveleti sorrend

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 short-circuit evaluation) and move on to the next filter. A kiértékelési sorrend:

  1. Anything surrounded by parentheses (( and )) is evaluated as a single unit.
  2. Turning variables/literals into their respective data. (e.g., page_namespace to 0)
  3. Függvényhívások (norm, lcase stb.)
  4. Unáris + és - (pozitív vagy negatív érték definiálása, pl. -1234, +1234)
  5. Kulcsszavak (in, rlike stb.)
  6. Boole-inverzió (!x)
  7. Hatványozás (2**3 → 8)
  8. Szorzással kapcsolatos (szorzás, osztás, modulo)
  9. Összeadás és kivonás (3-2 → 1)
  10. Összehasonlítások. (<, >, ==)
  11. Boole-műveletek. (&, |, ^)
  12. Ternary operator (... ? ... : ...)
  13. Assignments (:=)

Példák

  • A & B | C is equivalent to (A & B) | C, not to A & (B | C). In particular, both false & true | true and false & false | true evaluates to true.
  • A | B & C is equivalent to (A | B) & C, not to A | (B & C). In particular, both true | true & false and true | false & false evaluates to false.
  • added_lines rlike "foo" + "|bar" is wrong, use added_lines rlike ("foo" + "|bar") instead.

Feltételszámlálás

The condition limit is (more or less) tracking the number of comparison operators + number of function calls entered.

Further explanation on how to reduce conditions used can be found at Extension:AbuseFilter/Conditions .

Kivételek

Although the AbuseFilter examine function will identify "rollback" actions as edits, the AbuseFilter will not evaluate rollback actions for matching.[11]

Useful links

Jegyzetek

  1. Comparing arrays to other types will always return false, except for the example above
  2. 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 The only variables currently available for file uploads (action='upload') are user_*, page_*, file_sha1, file_size, file_mime, file_mediatype, file_width, file_height, file_bits_per_channel (the last five were only added since the release for MediaWiki 1.27 gerrit:281503). All the file_* variables are unavailable for other actions (including action='edit').
  3. MediaWiki 1.28 (gerrit:295254)-től
  4. Several filters (12) that use this variable have showed up in the AbuseFilterSlow Grafana dashboard (requires logstash access to view). Moving this variable to towards the end of the filter seemed to help.
  5. Lásd: phabricator:T191722
  6. Deprecated with this commit and disabled with this one.
  7. Some filters using this variable have showed up in the AbuseFilterSlow Grafana dashboard (example, requires logstash access). For instance, instead of using "text" in edit_diff_pst (or even edit_diff), consider something like "text" in added_lines & !("text" in removed_lines)
  8. A típusok listájához lásd a forráskódot.
  9. Be aware of phab:T27619. You can use Special:AbuseFilter/tools to evaluate ccnorm( "your string" ) to see which characters are transformed.
  10. https://3v4l.org/S6IGP
  11. T24713 - rollback not matched by AF