Extension:AbuseFilter
滥用过滤器(AbuseFilter)扩展允许具有权限的用户设置当用户的操作(例如编辑)匹配特定标准时,要进行的特定動作。
例如,可以创建一个过滤器防止匿名用户添加外部链接或封禁移除超过2000个字符的用户。
安裝
- 下载文件,并将其放置在您
extensions/
文件夹中的AbuseFilter
目录内。 - 只有從git安裝才运行Composer来安装PHP依赖,通过发行
composer install --no-dev
至扩展目录。 (参见任务T173141了解潜在问题。) - 将下列代码放置在您的LocalSettings.php 的底部:
wfLoadExtension( 'AbuseFilter' );
- 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
- 按需求配置。
完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
So, after installation from Git change to the directory containing the extension e.g. "../extensions/AbuseFilter/" and run composer install --no-dev
, or when updating: composer update --no-dev
.
Alternatively as well as preferably add the line "extensions/AbuseFilter/composer.json"
to the "composer.local.json" file in the root directory of your wiki like e.g.
{
"extra": {
"merge-plugin": {
"include": [
"extensions/AbuseFilter/composer.json"
]
}
}
}
配置
用户权限
一旦您安装了此扩展,您将需要在"LocalSettings.php"设置用户权限。
权限 | 描述 | Notes | User groups that have this right by default |
---|---|---|---|
abusefilter-modify | 创建或修改滥用过滤器 | Requires the abusefilter-view right | sysop |
abusefilter-view | 查看滥用过滤器 | * | |
abusefilter-log | 查看滥用日志 | * | |
abusefilter-log-detail | 查看详细滥用日志 | Requires the abusefilter-log right | sysop |
abusefilter-privatedetails | 查看滥用日志中的私有数据 | Prior to 1.34 this right was named abusefilter-private - Requires the abusefilter-log-detail right | — |
abusefilter-modify-restricted | 修改包含受限动作的滥用过滤器 | Requires the abusefilter-modify right | sysop |
abusefilter-modify-global | 创建或修改全域滥用过滤器 | Requires the abusefilter-modify right | — |
abusefilter-revert | 撤销指定滥用过滤器作出的所有更改 | sysop | |
abusefilter-view-private | 查看被标记为私有的滥用过滤器 | Requires the abusefilter-view right (not needed if the group already has the abusefilter-modify right) | sysop |
abusefilter-log-private | 查看标记为私有的滥用过滤器的过滤日志 | Requires the abusefilter-log right (not needed if the group already has the abusefilter-modify or abusefilter-view-private rights) | sysop |
abusefilter-hide-log | 将条目在滥用日志中隐藏 | Requires the abusefilter-log right | suppress |
abusefilter-hidden-log | 查看隐藏的滥用日志条目 | Requires the abusefilter-log right | suppress |
abusefilter-privatedetails-log | 查看滥用过滤器私有详情访问日志 | Prior to 1.34 this right was named abusefilter-private-log | — |
举个例子,如果按照以下配置的话,管理员能对滥用过滤器做任何设定,而任何人都能查看过滤日志和已公开的过滤器过滤代码:
$wgGroupPermissions['sysop']['abusefilter-modify'] = true;
$wgGroupPermissions['*']['abusefilter-log-detail'] = true;
$wgGroupPermissions['*']['abusefilter-view'] = true;
$wgGroupPermissions['*']['abusefilter-log'] = true;
$wgGroupPermissions['sysop']['abusefilter-privatedetails'] = true;
$wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
$wgGroupPermissions['sysop']['abusefilter-revert'] = true;
参数
值名 | 默认值 | 描述 |
---|---|---|
$wgAbuseFilterActions
|
[
'throttle' => true,
'warn' => true,
'disallow' => true,
'blockautopromote' => true,
'block' => true,
'rangeblock' => false,
'degroup' => false,
'tag' => true
]
|
滥用过滤器可以进行的動作。 當添加新動作時,確認是否在$wgAbuseFilterActionRestrictions 中被限制,若是的話,別忘了將abusefilter-modify-restricted 權限加入到適當的用戶組。
|
$wgAbuseFilterConditionLimit
|
1000
|
每次针对更改运行过滤器时可以使用的最大“条件”数。 (更复杂的过滤器需要更多'条件')。 |
$wgAbuseFilterValidGroups
|
[
'default'
]
|
“组”过滤器列表可以分为。默认情况下,只有一个组。 其他扩展可能会添加其他组。 |
$wgAbuseFilterEmergencyDisableThreshold
|
[
'default' => 0.05
]
|
如果匹配超过2次编辑,则禁用过滤器,构成在“观察”期间(最多一天)针对过滤器组检查的操作的5%以上,除非过去86400秒(一天)内更改了过滤器 。 請參閱緊急限制。 |
$wgAbuseFilterEmergencyDisableCount
|
[
'default' => 2
]
| |
$wgAbuseFilterEmergencyDisableAge
|
[
'default' => 86400
]
| |
$wgAbuseFilterParserClass
|
'AbuseFilterParser'
|
滥用过滤器的解析器级的名字。 |
$wgAbuseFilterActionRestrictions
|
[
"throttle" => false,
"warn" => false,
"disallow" => false,
"blockautopromote" => true,
"block" => true,
"rangeblock" => true,
"degroup" => true,
"tag" => false
]
|
用户必须具有“abusefilter-modify-restricted”用户权限以及“abusefilter-modify”才能创建或修改执行这些動作的过滤器。 |
$wgAbuseFilterNotifications
|
false
|
允许配置扩展以发送触发通知至Special:RecentChanges或UDP。 可用的设置: rc, udp, rcandudp
要将滥用过滤器的更改发送到 Special:RecentChanges,请使用
unset($wgLogRestrictions['abusefilter']); 。 |
$wgAbuseFilterNotificationsPrivate
|
false
|
允许私有过滤器使用通知功能。 |
$wgAbuseFilterCentralDB
|
null
|
指定全域过滤器的数据库名(只支持最新开发版) 需要安装 CentralAuth,否则全局过滤器将在 wikifarm 上失效。 |
$wgAbuseFilterIsCentral
|
false
|
如果wiki為全域过滤器所儲存的数据库時设定为true(只支持最新开发版) 需要安装 CentralAuth,否则全局过滤器将在 wikifarm 上失效。 |
$wgAbuseFilterLocallyDisabledGlobalActions
|
[
"throttle" => false,
"warn" => false,
"disallow" => false,
"blockautopromote" => false,
"block" => false,
"rangeblock" => false,
"degroup" => false,
"tag" => false
]
|
禁止中央过滤器执行此变量中设置为 true 的操作。 |
$wgAbuseFilterBlockDuration
|
'indefinite'
|
滥用过滤器做出的封禁持续时间。
从1.31.0-wmf.25开始,可以为每个过滤器指定封禁持续时间,并覆盖此变量。 此变量仅在启用封禁时使用,以便预先选择默认持续时间。
|
$wgAbuseFilterAnonBlockDuration
|
null
|
AbuseFilter对未登录的用户所做的封禁的持续时间。如果未设置,则将使用$wgAbuseFilterBlockDuration的值。
从1.31.0-wmf.25开始,可以为每个过滤器指定封禁持续时间,并覆盖此变量。 此变量仅在启用封禁时使用,以便预先选择默认持续时间。
|
$wgAbuseFilterBlockAutopromoteDuration
|
5
|
过滤器阻止用户自动升级的持续时间(以天为单位)。 |
$wgAbuseFilterCustomActionsHandlers
|
[]
|
自定义动作的回调方法。 (在1.36版本中已弃用) 改用 AbuseFilterCustomActions 钩子。 |
$wgAbuseFilterDefaultWarningMessage
|
[
'default' => 'abusefilter-warning'
]
|
每个过滤器组的默认警告信息 |
$wgAbuseFilterDefaultDisallowMessage
|
[
'default' => 'abusefilter-disallowed'
]
|
每个过滤器组的默认禁止消息 |
$wgAbuseFilterLogIPMaxAge
|
3 * 30 * 24 * 3600
|
清除旧IP日志数据时使用的时长作为截止值。默认为3个月。由维护脚本purgeOldLogIPData.php使用。 |
$wgAbuseFilterProfileActionsCap
|
10000
|
确定何时重置分析统计信息的操作数。 |
$wgAbuseFilterLogPrivateDetailsAccess
|
false
|
是否能夠從被記錄的過濾器日誌項目中存取私人資訊。 |
$wgAbuseFilterPrivateDetailsForceReason
|
false
|
是否強制用戶透過過濾器日誌項目存取私人資訊時需要提供原因。 |
$wgAbuseFilterSlowFilterRuntimeLimit
|
500
|
过滤器被认为较慢之前的运行时间(以毫秒为单位)。 |
$wgAbuseFilterRangeBlockSize
|
[
'IPv4' => '16',
'IPv6' => '19',
]
|
'rangeblock' 操作封禁的范围的大小。 |
$wgAbuseFilterLogIP
|
true
|
是否在abuse_filter_log中包含IP |
$wgAbuseFilterBlockedExternalDomainsNotifications
|
false
|
Feature flag to enable realtime notifications when an editor types a link to a blocked external domain. As of October 2023, this requires that $wgAbuseFilterEnableBlockedExternalDomain also be true . See Help:BlockedExternalDomains for more information.
|
緊急限制
防濫用過濾器有個功能是能夠自動節流(停用)過濾器,當過濾器最近編輯過且符合最近操作的數量達到一定門檻時運作。
這麼做是為了防止對過濾器進行有害的編輯,而導致阻止所有用戶對Wiki進行操作。
停用過濾器的條件根據這些變數:
$wgAbuseFilterEmergencyDisableThreshold
- 觀測期間內匹配數在操作總數中的百分比。$wgAbuseFilterEmergencyDisableCount
- 觀察期間內過濾器的匹配數。$wgAbuseFilterEmergencyDisableAge
- 進行評估的過濾器年齡。如果過濾器的最後一次編輯時間早於該秒數,則不會對其進行限制,除非它已被限制。$wgAbuseFilterProfileActionsCap
- 最近操作中可計入閾值的最大數量。 请注意,每个操作都会增加一次计数,一旦计数器的计数达到此配置的顶值,此计数器计数和与所有筛选器匹配的最近操作的数量将重置为0。
被拦截过滤器的已启用, 高匹配率状态可以在的过滤器列表(Special:AbuseFilter)中查看。 拦截是无声的,我们没有办法看到过滤器何时被拦截。
当过滤器被拦截时,它不会执行任何危险的操作(通常限制為特殊權限才能使用的操作,例如封鎖使用者或從使用者群組中移除使用者,由$wgAbuseFilterActionRestrictions控制),并且只允许“安全”操作(可以警告或阻止嘗試的操作之類的)。 拦截过滤器不会自动启用。若要禁用拦截,则需要编辑过滤器设置。 请注意,您实际上需要更改过滤器:从过滤器的注释中更改内容就可以了。
请注意,编辑过滤器将会更新它的历史,如果它再次达到上次编辑后的短时间内被拦截的条件,则会导致它被禁用,如果您的wiki比合法的编辑有更多的滥用,则会导致无法使用的过滤器。
创建和管理过滤器
当安装好本插件,通过滥用管理器管理页Special:AbuseFilter查看过滤日志和创建、修改、测试、删除过滤器。
- 要从Wikipedia导入过滤器:您需要在安装扩展之后,转到w:Special:AbuseFilter,选择一个过滤器(例如w:Special:AbuseFilter/3),然后单击“导出此过滤器”,复制随后出现的文本,转到目标wiki上的“Special:AbuseFilter/import”,粘贴文本。
- m:Small wiki toolkits/Starter kit/AbuseFilter - Metawiki上針對小型Wiki的社區指南
API
滥用过滤器有两个API的list模块,一个用于获得过滤器列表(“abusefilters”),另一个用于获得过滤日志。过滤日志是孤立于其他MediaWiki日志的(日志名为“abuselog”)。不能通过API创建或修改滥用过滤器。
list = abusefilters
列出关于过滤器的信息
- 參數
abfstartid
- 从该过滤器ID开始列举abfendid
- 列举到该过滤器ID为止abfdir
- 列举的方向(older、newer)abfshow
- 只显示符合对应属性的过滤器(enabled|!enabled|deleted|!deleted|private|!private)abflimit
- 每次列举最大数量abfprop
- 欲获取的属性(id|description|pattern|actions|hits|comments|lasteditor|lastedittime|status|private)
如果过滤器是非公开的且您没有查看它的权限,abfprop
中某些参数则不会显示。
- 例子
列出非私有滥用过滤器
结果 |
---|
{
"batchcomplete": "",
"continue": {
"abfstartid": 18,
"continue": "-||"
},
"query": {
"abusefilters": [
{
"id": 1,
"hits": 41430
},
{
"id": 3,
"hits": 957485
},
{
"id": 5,
"hits": 5931
},
{
"id": 6,
"hits": 19
},
{
"id": 8,
"hits": 7
},
{
"id": 9,
"hits": 41354
},
{
"id": 11,
"hits": 132971
},
{
"id": 12,
"hits": 139693
},
{
"id": 14,
"hits": 63
},
{
"id": 15,
"hits": 15
}
]
}
}
|
list = abuselog
列出过滤器的触发日志。
- 參數
aflstart
- 从该时间戳开始列举aflend
- 列举到该时间戳为止afldir
- 列举的方向(older、newer)afluser
- 只显示该用户或IP地址触发过滤器的日志。afltitle
- 只显示该页面中触发过滤器的日志。aflfilter
- 只显示该过滤器ID的触发日志afllimit
- 每次列举最大数量aflprop
- 欲获取的属性: (ids|filter|user|ip|title|action|details|result|timestamp|hidden|revid|wiki)
- 示例
列出其中触发滥用过滤器响应用户“SineBot”的操作的实例
结果 |
---|
{
"batchcomplete": "",
"continue": {
"aflstart": "2018-03-06T02:34:18Z",
"continue": "-||"
},
"query": {
"abuselog": [
{
"id": 27219261,
"filter_id": "1073"
},
{
"id": 26938051,
"filter_id": ""
},
{
"id": 23388942,
"filter_id": "1"
},
{
"id": 22044912,
"filter_id": ""
},
{
"id": 22032235,
"filter_id": ""
},
{
"id": 22032196,
"filter_id": ""
},
{
"id": 21983882,
"filter_id": ""
},
{
"id": 20594818,
"filter_id": "904"
},
{
"id": 20593489,
"filter_id": "904"
},
{
"id": 20590442,
"filter_id": "904"
}
]
}
}
|
可能的错误
- 有些用户可能会遇到创建新的过滤器器或修改旧过滤器器失败了,随后用户被重定向到原始页面的情况。 如果Wiki使用的是SSL证书,则此错误可能是由于
$wgServer
的值,该值可能使用的是“http://”而不是“https://”。 对此错误的一个提示是,浏览器的Special:AbuseFilter标签页弹出https警告。(Topic:T23dyyih0ofjada5)
整合其他擴充功能
您可以通過多種方式將防濫用過濾器與其他擴展整合。
添加用於過濾的變數
可以添加新的变量用于滥用过滤器。示例列表可用 。要做到这一点,您应该:
- 为AbuseFilter-builder 钩子添加一个处理程序。 要添加变量,您应该使用
$builder['vars']['variable_name'] = 'i18n-key';
,其中variable_name
是变量的名称,i18n-key
是i18n秘钥的片段。 这整段秘钥应该是abusefilter-edit-builder-vars-{$your_key}
。 - 添加您在上一点选择的 i18n 消息。
- Choose a hook handler where the variable will be computed. Depending on your use case, you could:
- Implement the AbuseFilter-generateTitleVars hook; this is specifically thought for page-related variables;
- Implement the AbuseFilter-generateUserVars hook; this is specifically thought for user-related variables;
- Implement the AbuseFilter-generateGenericVars hook; this is for variables not bound to a specific page or user;
- Implement the AbuseFilterAlterVariables hook; this is a bit more flexible than the other hooks, but it has a downside: your variable will not be available when examining past RecentChanges entries. If you want to implement that feature (and it's recommended to do so), you should use one of the hooks listed above, and use its third parameter (
$RCRow
).
- Inside the hook handler, there are two ways to add a variable:
- The "direct" way is calling
$vars->setVar( 'var_name', var_value );
. This is ideal only when the value is easy and quick to compute: the value is computed even if no active filter will use it. - The "lazy" way is calling
$vars->setLazyLoadVar( 'var_name', 'method_name', $params );
. Here, 'method_name' is a (unique) identifier that will be used to compute the variable (it's recommended to prefix it with the name of your extension). To register the method, you should add a handler for the AbuseFilter-computeVariable hook; therein, you should check if the $method passed matches your 'method_name', and if so, compute the variable. Lastly, $params is an array of parameters that you'll need to compute the variable; these are passed to the computeVariable hook handler. For an example of this, you can check out CentralAuth'sglobal_user_groups
.
- The "direct" way is calling
Adding custom actions
You can add custom action handlers, so that each filter may perform further actions. To do that, you choose a name for the action ('my-action' from now on), and then:
- Create a class named e.g. MyAction, that should extend \MediaWiki\Extension\AbuseFilter\Consequence, which can also implement HookAborterConsequence or ConsequencesDisablerConsequence
- Add a subscriber to the AbuseFilterCustomActions hook; the subscriber should provide a callback as documented in the hook documentation, that returns an instance of the class created above, for instance:
class MyAction extends \MediaWiki\Extension\AbuseFilter\Consequence {
public function run() {
throw new \Exception( 'Write me' );
}
}
public function onAbuseFilterCustomActions( &$actions ) {
$actions[] = function ( \MediaWiki\Extension\AbuseFilter\Consequence\Parameters $params, array $rawParams ) : MyConsequence {
return new MyAction( $params, $rawParams );
};
}
Then you should add the following i18n messages; you can replace 'my_action' with e.g. 'block' to see what the messages are for:
'abusefilter-edit-action-${my_action}'
'abusefilter-action-${my_action}'
添加規則組
You can also add extra rule groups, which can be used to group existing abuse filters. Note that, at the moment, each filter can only be in a single group (T116642). Currently, the only known consumer of this feature is 扩展:结构式讨论 . To do that, you should:
- Append the name of the group to
$wgAbuseFilterValidGroups
- Add some code to run the filters with your group. Note that AbuseFilter won't do that on its own. To do that, you should construct an
AbuseFilterRunner
object, passing in the name of your group.
參見
- 多个启用此擴展的WMF維基(以及使用的配置)
![]() | 此扩展用于一个或多个维基媒体项目。 这可能意味着扩展足够稳定、运作足够良好,可以用在这样的高流量的网站上。 请在维基媒体的CommonSettings.php和InitialiseSettings.php配置文件中查找此扩展的名称以查看哪些网站安装了该扩展。 特定wiki上的已安装的扩展的完整列表位于Special:Version页面。 |
![]() | 此扩展在以下wiki农场/托管网站和/或软件包中提供: 這不是一份權威名單。 即使某些wiki农场/托管网站和/或软件包未在这里列出,它们也可能提供此扩展。 请检查你的wiki农场/托管网站或软件包以确认提供情况。 |
- Extensions bundled with MediaWiki 1.38/zh
- Stable extensions/zh
- User activity extensions/zh
- Special page extensions/zh
- API extensions/zh
- Extensions supporting Composer/zh
- GPL licensed extensions/zh
- Extensions in Wikimedia version control/zh
- ArticleDelete extensions/zh
- BeforeCreateEchoEvent extensions/zh
- ChangeTagsListActive extensions/zh
- CheckUserInsertChangesRow extensions/zh
- CheckUserInsertLogEventRow extensions/zh
- CheckUserInsertPrivateEventRow extensions/zh
- ContributionsToolLinks extensions/zh
- EditFilterMergedContent extensions/zh
- EditPage::showEditForm:initial extensions/zh
- GetAutoPromoteGroups extensions/zh
- HistoryPageToolLinks extensions/zh
- JsonValidateSave extensions/zh
- ListDefinedTags extensions/zh
- LoadExtensionSchemaUpdates extensions/zh
- PageSaveComplete extensions/zh
- ParserOutputStashForEdit extensions/zh
- RecentChange save extensions/zh
- RenameUserSQL extensions/zh
- TitleMove extensions/zh
- UndeletePageToolLinks extensions/zh
- UploadStashFile extensions/zh
- UploadVerifyUpload extensions/zh
- UserMergeAccountFields extensions/zh
- GetUserPermissionsErrors extensions/zh
- All extensions/zh
- Extensions requiring Composer with git/zh
- Extensions used on Wikimedia/zh
- Extensions included in Canasta/zh
- Extensions available as Debian packages/zh
- Extensions included in Fandom/zh
- Extensions included in Miraheze/zh
- Extensions included in MyWikis/zh
- Extensions included in ProWiki/zh
- Extensions included in ShoutWiki/zh
- Extensions included in Telepedia/zh
- Extensions included in wiki.gg/zh
- Extensions included in WikiForge/zh
- Extensions included in WikiTide/zh
- Spam management extensions/zh