Jump to content

扩展:标题黑名单

本頁使用了標題或全文手工轉換
From mediawiki.org
This page is a translated version of the page Extension:TitleBlacklist and the translation is 54% complete.
此扩展随附于MediaWiki 1.21及更高版本。 因此您无需另外下载。 但是,您仍需遵循此页面提供的其他使用说明。
MediaWiki扩展手册
TitleBlacklist
发行状态: 稳定版
实现 用户权限 , API
描述 禁止建立與正規表達式黑名單匹配的頁面
作者 Victor Vasiliev (VasilievVV留言)
最新版本 1.5.0 (
持续更新)
兼容性政策 快照跟随MediaWiki发布。 master分支不向后兼容。
MediaWiki 1.35+
PHP 7.0+
许可协议 GNU通用公眾授權條款2.0或更新版本
下載
  • $wgTitleBlacklistSources
  • $wgTitleBlacklistUsernameSources
  • $wgTitleBlacklistCaching
  • $wgTitleBlacklistBlockAutoAccountCreation
  • $wgTitleBlacklistLogHits

  • tboverride
  • tboverride-account
  • titleblacklistlog
季度下載量 52 (Ranked 89th)
前往translatewiki.net翻譯TitleBlacklist扩展
問題 开启的任务 · 报告错误
一项重命名此扩展的提案正在工單T254650讨论。

使用标题黑名单扩展,维基管理员可以以若干条正则表达式的形式来设立一个标题黑名单。如果一个页面的标题与黑名单中的规则相匹配,用户将不能创建此页面、上传文件至此页面,或将其他页面移动至此页面。此外,该扩展程序还能设立用户名黑名单,阻止用户创建特定名称的新用户。

安裝

  • 下载文件,并将解压后的TitleBlacklist文件夹移动到extensions/目录中。
    开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
  • 将下列代码放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'TitleBlacklist' );
    
  • 设置封鎖名單来源(见下文
  • Yes 完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
默认情况下,该扩展仅对非管理员用户有效。要使该扩展对所有用户有效,请设置$wgGroupPermissions['sysop']['tboverride'] = false;

配置

$wgTitleBlacklistSources
標題黑名單來源的陣列。
應該採用 array( 名稱 => 來源描述 ) 的格式。 默认为空数组。
$wgTitleBlacklistUsernameSources
設定可作為使用者名稱過濾器的來源。
*」為全部;false為停用全部。
如果要將其限制為特定的來源,請使用 array( 來源名稱1, 來源名稱2 )。 This may be useful when you have shared account creation system in order to avoid blacklist fragmentation.
$wgTitleBlacklistLogHits
如果為true,則在Special:Log/titleblacklist上記錄所有與黑名單匹配的本地帳戶建立嘗試。 默认值为“false.” 請注意即使禁用此選項,具有titleblacklistlog權限的使用者群組仍可見到該日誌。
$wgTitleBlacklistCaching
?
$wgTitleBlacklistBlockAutoAccountCreation
也禁止與黑名單匹配的帳戶自動建立。 默认值为“true.”

多个封鎖名單来源

標題封鎖名單可以從本地訊息以為的多個來源收集而來,要配置封鎖名單來源,請使用以下代碼:

wfLoadExtension( 'TitleBlacklist' );
$wgTitleBlacklistSources = [
    [
         'type' => 'localpage',
         'src'  => 'MediaWiki:Titleblacklist'
    ],
    [
         'type' => 'url',
         'src'  => 'https://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw'
    ],
    [
         'type' => 'file',
         'src'  => '/home/wikipedia/blacklists/titles',
    ]
];

参见任务 T113864以获取详细信息

用法

封鎖名單

標題封鎖名單可在MediaWiki:Titleblacklist頁面找到。

該頁面由正規表達式組成,每個正規表達式單獨一行。 Each of them forbids the creation of pages whose titles match it. 例如:

Foo <autoconfirmed|noedit|errmsg=blacklisted-testpage> # 这个页面名称不被允许
[Bb]ar # 不应该有人创建关于它的条目
.*pandora.* # 这个单词不允许存在于页面名称的任何部分

每個項目還能包含可選的屬性,並包在<>內,以|分隔。

  • autoconfirmed - 允許自動確認使用者執行此類操作
  • casesensitive - 檢查標題是否被列入封鎖名單時不要忽略大小寫
  • noedit - 同时禁止编辑页面(如果页面已存在)
  • moveonly - 禁止移動但允許普通建立 (rev:35163)
  • newaccountonly - 禁止建立匹配的使用者名稱,但允許建立頁面 (rev:38977)
  • reupload - 允許重新上傳現在被列入封鎖名單的檔案 (rev:33656)
  • errmsg - 應該顯示的訊息名稱,而不是標準名稱

如果已安裝AntiSpoof 擴充功能,您還能使用‎<antispoof>屬性。

What is referred to here as regular expressions are not proper regular expressions, but rather subpatterns that are inserted into a hard-coded regular expression. i.e. the subpattern Foo from above would create a regular expression like /^Foo$/usi.

Underscores ("_") in regular expressions will be converted to spaces by the extension, because titles are matched against its text form ("Page title" instead of "Page_title").

安全名单

There is also a whitelist at MediaWiki:Titlewhitelist. The blacklist is applied first, then the whitelist. So user input that matches an entry on the blacklist is blocked, except if it matches an entry on the whitelist. You don't have to configure anything in LocalSettings.php in order to use the whitelist. Some of the optional attributes listed above, for the blacklist, also work for the whitelist, e.g. casesensitive.

自定义

警告消息

When an attempt to create a page is blocked due to a blacklisted title, a warning message is shown to the user. This can be customized via following system messages defined in the namespace Mediawiki:

Custom messages can be defined by using the errmsg attribute.

範例:使用此扩展来限制新用户的创建

概念概览

The username for new accounts will be regarded by this extension differently to the way it regards new articles. This extension will prepend "User:" (or its localized equivalent) to the string that a user enters at Username on the create account page. So when this extension is performing matches with your Regex's, as found on MediaWiki:Titleblacklist or MediaWiki:Titlewhitelist, it will match against "User:" + <userinput>.

For example, imagine you want to block "jill" as a new user. Imagine you had a blacklist regex "jill.* <newaccountonly>" and a user enters "jill" as the username on the create account page. This will pass as the comparison this extension will make will be between "jill.*" (the regex) and "User:jill" (the constructed input string). These don't match and so "jill" is allowed (and you probably didn't intend this). To effect the intended block use a regex like ".*jill.* <newaccountonly>" or "User:jill.* <newaccountonly>" on MediaWiki:Titleblacklist.

If you want to block all users except for all those that do match a regex then block all users in MediaWiki:Titleblacklist and write the permissible regex in the MediaWiki:Titlewhitelist.

如何使用

If you would like to force all usernames, during account creation, to consist of exactly two names, space separated, with each name capitalized then do the following:

1. 安装TitleBlacklist.

2. 将以下内容添加至您的LocalSettings.php

wfLoadExtension( 'TitleBlacklist' );
$wgGroupPermissions['sysop']['tboverride'] = false; 
$wgTitleBlacklistSources = [
  [
    'type' => 'localpage',
    'src'  => 'MediaWiki:Titleblacklist'
  ]
];

3. 在https://www.example.com/mywiki/MediaWiki:Titleblacklist中添加

# Block all user accounts, and only permit those that match the MediaWiki:Titlewhitelistregex 
.* <newaccountonly>

4. 在https://www.example.com/mywiki/MediaWiki:Titlewhitelist中添加

# Only allow two names, separated by a space, with each name capitalized, e.g. "Fred Mew" OK, "Fred mew" fails, "Fredmew" fails.
# Depends on .* <newaccountonly> in blacklist
User:[A-Z][a-z]+\s[A-Z][a-z]+ <casesensitive>

5. 在https://www.example.com/mywiki/MediaWiki:Titleblacklist-forbidden-new-account edit中编辑

The user name "$2" has been blocked from creation. It matches the following blacklist entry: <code>$1</code>.

Please use a real name for the user name. User names need to be comprised of two names separated by a space. Each name must be capitalized.

E.g.:
* "Mary Smith". OK.
* "MarySmith". Invalid.
* "Mary smith". Invalid.
* "marysmith". Invalid.

User name creation (and article creation) blocking rules are controlled by MediaWiki:Titleblacklist and MediaWiki:Titlewhitelist. This message can be customized at MediaWiki:Titleblacklist-forbidden-new-account.

測試是否匹配

The API module action=titleblacklist can be used to test a title and action (e.g. edit, create, new-account) against the blacklist. Users with the 'tboverride' right should be sure to supply the tbnooverride parameter.

For example, if the blacklist contained the filter:

.*(.)\1{10}.* <newaccountonly|errmsg=titleblacklist-forbidden-new-account-invalid> # Disallows eleven or more of the same character repeated in usernames

you could use an API request like

结果
{
    "titleblacklist": {
        "result": "blacklisted",
        "reason": "<table  class=\"plainlinks fmbox\nfmbox-system \" style=\"\" role=\"presentation\" dir=\"ltr\">\n<tr>\n<td class=\"mbox-image\">\n  [[File:Imbox notice.png|40x40px|link=|alt=]]</td>\n<td class=\"mbox-text\" style=\"\"> The user name \"AAAAAAAAAAA\" [[Mediawiki talk:Titleblacklist|has been blocklisted]] from creation. </td>\n\n</tr>\n</table>",
        "message": "titleblacklist-forbidden-new-account-invalid",
        "line": ".*(.)\1{10}.* &lt;newaccountonly|errmsg=titleblacklist-forbidden-new-account-invalid&gt; # Disallows eleven or more of the same character repeated in usernames"
    }
}

如果安裝了Scribunto ,这个擴充功能允许使用mw.ext.TitleBlacklist.test函數測試特定標題和操作是否会匹配封鎖名單中的項目。 如果找到了匹配的,會返回該匹配項目的詳細資料。

例如,如果封鎖名單包括這個過濾器:

.*(.)\1{10}.* <newaccountonly|errmsg=titleblacklist-forbidden-new-account-invalid> # 不允許使用者名稱中重複11個或更多相同字母

運行這個函數:

mw.ext.TitleBlacklist.test("new-account", "AAAAAAAAAAA")

會返回如下表,包括關於該匹配項目的詳細資料:

{
	custommessage = "titleblacklist-forbidden-new-account-invalid",
	message = "titleblacklist-forbidden-new-account-invalid",
	params = {
		errmsg = "titleblacklist-forbidden-new-account-invalid",
		newaccountonly = true
	},
	raw = " .*(.)\1{10}.* <newaccountonly|errmsg=titleblacklist-forbidden-new-account-invalid> # -{}-不允許使用者名稱中重複11個或更多相同字母",
	regex = ".*(.)\1{10}.*",
	version = 3
}

Clearing the cache

The contents of the blacklists are cached. Changes in blacklists configured at a URL or a file on the server are not applied immediately. To force clearing the cache, edit and save the page MediaWiki:Titleblacklist (even if you don't change anything). It doesn't matter if it's configured as a blacklist or not. See includes/Hooks.php.

Resources on regular expressions

參見