Extension:TitleBlacklist
TitleBlacklist Release status: stable |
|
---|---|
Implementation | User rights , API |
Description | Blocks the creation of pages matching a regular expression blacklist |
Author(s) | Victor Vasiliev (VasilievVVtalk) |
Latest version | 1.5.0 (Continuous updates) |
Compatibility policy | Snapshots releases along with MediaWiki. Master is not backward compatible. |
MediaWiki | 1.35+ |
PHP | 7.0+ |
License | GNU General Public License 2.0 or later |
Download | |
|
|
|
|
Quarterly downloads | 55 (Ranked 76th) |
Translate the TitleBlacklist extension if it is available at translatewiki.net | |
Issues | Open tasks · Report a bug |
The TitleBlacklist extension allows wiki administrators to block the creation, movement and upload of pages, the title of which matches one or more regular expressions, as well as blocking creation of accounts with matching usernames.
Installation
[edit]- Download and move the extracted
TitleBlacklist
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'TitleBlacklist' );
- Configure blacklist sources (see below)
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
$wgGroupPermissions['sysop']['tboverride'] = false;
.Configuration
[edit]$wgTitleBlacklistSources
- Array of title blacklist sources.
- Should be in array( name => source description ) format. Defaults to an empty array.
$wgTitleBlacklistUsernameSources
- Sets the sources which may work as a username filter.
- "
*
" is for all; false disables all. - If you want to limit it to particular sources, use array( source name 1, source name 2 ). This may be useful when you have shared account creation system in order to avoid blacklist fragmentation.
$wgTitleBlacklistLogHits
- When true, logs on Special:Log/titleblacklist all attempts of local account creation that match the blacklists. Defaults to
false
. Note that even disabled, the log will still be visible for users groups with thetitleblacklistlog
right. $wgTitleBlacklistCaching
- ?
$wgTitleBlacklistBlockAutoAccountCreation
- Also blocks account created automatically that match the blacklists. Defaults to
true
.
- Multiple blacklist sources
The title blacklist can be gathered from multiple sources outside the local message. For configuring blacklist sources use code as described below:
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',
]
];
See task T113864 for further information.
Usage
[edit]Blacklist
[edit]The title blacklist is found on the MediaWiki:Titleblacklist page.
This page consists of regular expressions, each on a separate line. Each of them forbids the creation of pages whose titles match it.
Each entry may also contain one or more attributes.
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
- also forbid edits to matching pages that already existmoveonly
- 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
If the AntiSpoof extension is installed, the antispoof
attribute can be used to normalize titles before checking them against the rules.
For example:
Foo <autoconfirmed|noedit|errmsg=blacklisted-testpage> # This page name is not allowed [Bb]ar # No one should create article about it .*pandora.* # This word is not allowed in any part of a page name
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").
Whitelist
[edit]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.
Customizing
[edit]- Warning messages
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.
Example: Using TitleBlacklist to control user account creation
[edit]Conceptual overview
[edit]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.
How to
[edit]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. Install TitleBlacklist.
2. Add the following to your LocalSettings.php
wfLoadExtension( 'TitleBlacklist' );
$wgGroupPermissions['sysop']['tboverride'] = false;
$wgTitleBlacklistSources = [
[
'type' => 'localpage',
'src' => 'MediaWiki:Titleblacklist'
]
];
3. In https://www.example.com/mywiki/MediaWiki:Titleblacklist add
# Block all user accounts, and only permit those that match the MediaWiki:Titlewhitelistregex
.* <newaccountonly>
4. In https://www.example.com/mywiki/MediaWiki:Titlewhitelist add
# 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. In 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.
Testing for matches
[edit]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
Result |
---|
{
"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"
}
}
|
If Scribunto is installed, TitleBlacklist allows for testing if particular titles and actions will match an entry in the blacklist using the mw.ext.TitleBlacklist.test
function.
If a match is found, the details for the matched entry are returned.
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
running the function:
mw.ext.TitleBlacklist.test("new-account", "AAAAAAAAAAA")
would return the following table containing details about the matched entry:
{
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> # Disallows eleven or more of the same character repeated in usernames",
regex = ".*(.)\1{10}.*",
version = 3
}
Clearing the cache
[edit]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
[edit]- 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
See also
[edit]This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. |
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Extensions bundled with MediaWiki 1.21
- Stable extensions
- User rights extensions
- API extensions
- GPL licensed extensions
- Extensions in Wikimedia version control
- Extensions which add rights
- EditFilter extensions
- MovePageCheckPermissions extensions
- PageSaveComplete extensions
- ScribuntoExternalLibraries extensions
- TitleGetEditNotices extensions
- GetUserPermissionsErrorsExpensive extensions
- All extensions
- Extensions used on Wikimedia
- Extensions included in BlueSpice
- Extensions included in Canasta
- Extensions available as Debian packages
- Extensions included in Fandom
- Extensions included in Miraheze
- Extensions included in MyWikis
- Extensions included in ProWiki
- Extensions included in semantic::core
- Extensions included in ShoutWiki
- Extensions included in wiki.gg
- Extensions included in WikiForge