From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg

Release status:Extension status beta

ImplementationTemplate:Extension#type User identity
DescriptionTemplate:Extension#description Block the creation of accounts if certain email-address criteria are met
Author(s)Template:Extension#username Mirko Schiefelbein (Naitsirktalk)
Latest versionTemplate:Extension#version 1.0 (2017-02-27)
MediaWikiTemplate:Extension#mediawiki 1.17+
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download See here
  • $wgCheckEmailAddressDomainSources
  • $wgCheckEmailAddressNameSigns
Hooks usedTemplate:Extension#hook

Translate the CheckEmailAddress extension if it is available at translatewiki.net

Check usage and version matrix.

The CheckEmailAddress extension checks the email-address during the registration process. It aims at preventing spammers from creating an account on wikis which require email confirmation. CheckEmailAddress basically provides two features:

  • check the domain of the email-address:
If it matches a certain provider-address, e.g. a known trash-email-address, account creation fails, and the user is asked to register with a different email-address.
  • check the name of the email-address:
If the name meets certain criteria, account creation fails, and the user is asked to provide a different email-address.

Download instructions[edit]

Please copy and paste the code found below and place it in

  • $IP/extensions/CheckEmailAddress/CheckEmailAddress.php
  • $IP/extensions/CheckEmailAddress/CheckEmailAddress.hooks.php
  • $IP/extensions/CheckEmailAddress/CheckEmailAddress.i18n.php.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.


To install this extension, add the following to LocalSettings.php:

$wgCheckEmailAddressDomainSources = array(
	'type'	=> CEASRC_FILE,
	'src'	=> "$IP/Blacklistfile.txt"
$wgCheckEmailAddressNameSigns = array(
		'sign'		=> ".",
		'maxcount'	=> 5,

Create a textfile "Blacklistfile.txt". Fill in domains of email-addresses that are known as trash- or once-only-mails, e.g. mailinator.com. Just write the domains you want to disable one below the other, without "@". It should look something like this:


Save Blacklistfile.txt in your root. Note: the root directory of your MediaWiki installation is the same directory that holds LocalSettings.php.

Configuration parameters[edit]


This is a simple array that informs what type the source is and which sourcefile is used. At the moment only "CEASRC_FILE" is possible as "type". Point "src" to the file containing the email-addresses.


This array defines the signs and their limit in the name-part of the email-address, i.e. in the part before "@". Since this variable is an array of arrays, you can name several signs with different limits. If for example known spammers keep registring with characteristic email-names, you can now exclude them by patterns. In the configuration given above, email-names are searched for dots ("."). If they count equal or more than five, account creation fails.


CheckEmailAddress consists of three files.


if ( !defined( 'MEDIAWIKI' ) ) {

$wgExtensionCredits['other'][] = array(
	'path'           => __FILE__,
	'name'           => 'CheckEmailAddress',
	'author'         => 'Mirko Schiefelbein',
	'url'            => 'https://www.mediawiki.org/wiki/Extension:CheckEmailAddress',
	'descriptionmsg' => 'checkemailaddress-desc',
	'version'        => '1.0',

$wgExtensionMessagesFiles[ 'CheckEmailAddress' ] = dirname( __FILE__ ) . '/CheckEmailAddress.i18n.php';
$wgAutoloadClasses[ 'CheckEmailAddressHooks' ] = dirname( __FILE__ ) . '/CheckEmailAddress.hooks.php';

/** for future integration: CheckEmailAddress source types
 *  @{
define( 'CEASRC_MSG',       0 );	///< For internal usage
define( 'CEASRC_LOCALPAGE', 1 );	///< Local wiki page
define( 'CEASRC_URL',	    2 );	///< Load blacklist from URL
define( 'CEASRC_FILE',      3 );	///< Load from file
/** @}

/** Array of CheckEmailAddress sources */
$wgCheckEmailAddressDomainSources = array();

/** Array of CheckEmailAddress names */
$wgCheckEmailAddressNameSigns = array();

/** Hooks */
$wgHooks['AbortNewAccount'][] = 'CheckEmailAddressHooks::abortNewAccountDomain';
$wgHooks['AbortNewAccount'][] = 'CheckEmailAddressHooks::abortNewAccountName';


class CheckEmailAddressHooks {
	/* Check Domain if once- or trash-mail
	public static function abortNewAccountDomain ( $user, &$abortError ) {
		global $wgUser, $wgCheckEmailAddressDomainSources;
		$fulladdress = $user->getEmail();
		$domainat = stristr( $fulladdress, '@' );
		$domain = mb_strtolower( $domainat );
		if( !is_array( $wgCheckEmailAddressDomainSources ) || count( $wgCheckEmailAddressDomainSources ) <= 0 ) {
			return '';
		if( $wgCheckEmailAddressDomainSources[ 'type' ] == CEASRC_FILE ) {
			$srcfile = $wgCheckEmailAddressDomainSources[ 'src' ];
			if( file_exists( $srcfile ) ) {
				$domlines = file( $srcfile );
			} else {
				return true;
			foreach( $domlines as $domline ) {
				$domline = rtrim( $domline, "\r\n");
				$entry = "/@".$domline."/";
				if( preg_match( $entry, $domain ) ) {
					$abortError = wfMessage( 'checkemailaddress-domainerror' )->text();
					unset( $domline );
					return false;
		unset( $domline );
		return true;
	/* Check Name if spammy indicators
	public static function abortNewAccountName ( $user, &$abortError ) {
		global $wgUser, $wgCheckEmailAddressNameSigns;
		$fulladdress = $user->getEmail();
		$at = "@";
		$atpos = strpos( $fulladdress, $at );
		$nameat = substr( $fulladdress, 0, $atpos );
		$name = mb_strtolower( $nameat );
		if( !is_array( $wgCheckEmailAddressNameSigns ) || count( $wgCheckEmailAddressNameSigns ) <= 0 ) {
			return '';
		foreach( $wgCheckEmailAddressNameSigns as $key => $value ) {
			$sign = $value[ 'sign' ];
			$maxcount = $value[ 'maxcount' ];
			$signcount = substr_count( $name, $sign );
			if( $signcount >= $maxcount ) {
				$abortError = wfMessage( 'checkemailaddress-nameerror' )->text();
				unset( $value );
				return false;
		unset( $value );
		return true;


$messages = array();

/** English
* @author Naitsirk
$messages['en'] = array(
    'checkemailaddress-desc'	=> 'Allows to exclude certain email-addresses from registration',
    'checkemailaddress'		=> '# This is a list of forbidden domains for emails which therefore are disabled to register with.',
    'checkemailaddress-domainerror'	=> 'Once-only and trash email-addresses are not allowed on {{SITENAME}}. Please register with a different email-address.',
    'checkemailaddress-nameerror'	=> 'The email-address you submitted is supposed to be spam. If it is not, please email the admin.',

/** German (Deutsch)
* @author Naitsirk
* @author Kghbln
$messages['de'] = array(
	'checkemailaddress-desc'	=> 'Ermöglicht es, bestimmte E-Mail-Adressen von der Registrierung auszuschliessen',
	'checkemailaddress'		=> '# Dies ist eine Liste unzulässiger Domainnamen für E-Mails, mit denen eine Registrierung nicht möglich ist.',
	'checkemailaddress-domainerror'	=> 'Wegwerf- und Einmal-E-Mail-Adressen sind auf {{SITENAME}} nicht zulässig. Bitte registriere dich mit einer anderen E-Mail-Adresse.',
	'checkemailaddress-nameerror'	=> 'Es handelt sich vermutlich um eine Spam-E-Mail-Adresse. Sofen dies nicht der Fall ist, kontaktiere bitte einen Administrator per E-Mail.',

/** German (formal address) (\202aDeutsch (Sie-Form)\202c)
* @author Kghbln
$messages['de-formal'] = array(
	'checkemailaddress-domainerror'	=> 'Wegwerf- und Einmal-E-Mail-Adressen sind auf {{SITENAME}} nicht zulässig. Bitte registrieren Sie sich mit einer anderen E-Mail-Adresse.',
	'checkemailaddress-nameerror'	=> 'Es handelt sich vermutlich um eine Spam-E-Mail-Adresse. Sofen dies nicht der Fall ist, kontaktieren Sie bitte einen Administrator per E-Mail.',

/**  Dutch (Nederlands)
* @author Arent
$messages['nl'] = array(
        'checkemailaddress-desc'        => 'Maakt het mogelijk om bepaalde emailadressen uit te sluiten voor accountregistratie',
        'checkemailaddress'             => '# Dit is een lijst met email-domeinen waarmee geen accountregistratie kan plaatsvinden.',
        'checkemailaddress-domainerror' => 'Eenmalige en wegwerpadressen zijn niet toegestaan op {{SITENAME}}. Gebruik a.u.b. een ander emailadres.',
        'checkemailaddress-nameerror'   => 'Het gebruikte emailadres is als spam-adres geclassificeerd. Mocht dit onterecht gebeurd zijn neem dan contact op met de beheerder...',

/** Polish
 * @author jakubsam
$messages['pl'] = array(
    'checkemailaddress-desc'	=> 'Pozwala na zabronienie rejestracji z niektórych adresów e-mail',
    'checkemailaddress'		=> '# To jest lista domen e-mail z których rejestracja jest zabroniona.',
    'checkemailaddress-domainerror'	=> 'Tymczasowe i fałszywe adresy e-mail nie są dozwolone na {{SITENAME}}. Proszę użyć prawdziwego adresu e-mail.',
    'checkemailaddress-nameerror'	=> 'Wybrany e-mail jest adresem oznaczonym jako spam. Proszę podać innego maila.',


Feedback is greatly appreciated. Give me a call when you have improvements in mind, have identified certain spam-name-patterns, or have done some internationalization.