扩展:标题黑名单
TitleBlacklist 发行状态: 稳定版 |
|
---|---|
实现 | 用户权限 , API |
描述 | 禁止建立與正規表達式黑名單匹配的頁面 |
作者 | Victor Vasiliev (VasilievVV留言) |
最新版本 | 1.5.0 ( |
兼容性政策 | 快照跟随MediaWiki发布。 master分支不向后兼容。 |
MediaWiki | 1.35+ |
PHP | 7.0+ |
许可协议 | GNU通用公眾授權條款2.0或更新版本 |
下載 | |
|
|
|
|
季度下載量 | 54 (Ranked 82nd) |
前往translatewiki.net翻譯TitleBlacklist扩展 | |
問題 | 开启的任务 · 报告错误 |
使用标题黑名单扩展,维基管理员可以以若干条正则表达式的形式来设立一个标题黑名单。如果一个页面的标题与黑名单中的规则相匹配,用户将不能创建此页面、上传文件至此页面,或将其他页面移动至此页面。此外,该扩展程序还能设立用户名黑名单,阻止用户创建特定名称的新用户。
安裝
- 下载文件,并将解压后的
TitleBlacklist
文件夹移动到extensions/
目录中。
开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist - 将下列代码放置在您的LocalSettings.php 的底部:
wfLoadExtension( 'TitleBlacklist' );
- 设置封鎖名單来源(见下文)
- 完成 – 在您的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.
每個項目還能包含可選的屬性,並包在$1內,以$2分隔。
The list of attributes must be enclosed in <>
and separated with |
.
The possible attributes are:
autoconfirmed
- allow autoconfirmed users to bypass the restrictioncasesensitive
- only apply the restriction when the letter case exactly matches the entrynoedit
- 同时禁止编辑页面(如果页面已存在)moveonly
- only forbid page moves to matching titles, allowing ordinary page creationsnewaccountonly
- only forbid matching account creations, allowing other actionsreupload
- allow uploading new versions of matching files that already existerrmsg=X
- when an action is prevented, display the error message with the nameX
instead of the standard message
如果已安裝AntiSpoof 擴充功能,您還能使用antispoof
屬性。
例如:
Foo <autoconfirmed|noedit|errmsg=blacklisted-testpage> # 这个页面名称不被允许 [Bb]ar # 不应该有人创建关于它的条目 .*pandora.* # 这个单词不允许存在于页面名称的任何部分
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:
- MediaWiki:Titleblacklist-forbidden-edit — for page creation and editing,
- MediaWiki:Titleblacklist-forbidden-move — for page moves,
- MediaWiki:Titleblacklist-forbidden-upload — for image uploads,
- MediaWiki:Titleblacklist-forbidden-new-account — for new accounts.
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}.* <newaccountonly|errmsg=titleblacklist-forbidden-new-account-invalid> # 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
- Brief Introduction to Regular Expressions
- The 30 Minute Regular Expression Tutorial
- PHP: PCRE regex syntax, the syntax of regular expressions used by PHP and therefore this extension
參見
此扩展用于一个或多个维基媒体项目。 这可能意味着扩展足够稳定、运作足够良好,可以用在这样的高流量的网站上。 请在维基媒体的CommonSettings.php和InitialiseSettings.php配置文件中查找此扩展的名称以查看哪些网站安装了该扩展。 特定wiki上的已安装的扩展的完整列表位于Special:Version页面。 |
此扩展在以下wiki农场/托管网站和/或软件包中提供: 這不是一份權威名單。 即使某些wiki农场/托管网站和/或软件包未在这里列出,它们也可能提供此扩展。 请检查你的wiki农场/托管网站或软件包以确认提供情况。 |
- Extensions bundled with MediaWiki 1.21/zh
- Stable extensions/zh
- User rights extensions/zh
- API extensions/zh
- Pages using deprecated NoteTA template
- GPL licensed extensions/zh
- Extensions in Wikimedia version control/zh
- Extensions which add rights/zh
- EditFilter extensions/zh
- MovePageCheckPermissions extensions/zh
- PageSaveComplete extensions/zh
- ScribuntoExternalLibraries extensions/zh
- TitleGetEditNotices extensions/zh
- GetUserPermissionsErrorsExpensive extensions/zh
- All extensions/zh
- Extensions used on Wikimedia/zh
- Extensions included in BlueSpice/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 semantic::core/zh
- Extensions included in ShoutWiki/zh
- Extensions included in wiki.gg/zh
- Extensions included in WikiForge/zh