Extension:CheckEmailAddress
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
CheckEmailAddress Release status: beta |
|||
|---|---|---|---|
| Implementation | User identity | ||
| Description | Block the creation of accounts if certain email-address criteria are met | ||
| Author(s) | Mirko Schiefelbein (Naitsirktalk) | ||
| Last version | 0.9 (02-04-2012) | ||
| MediaWiki | 1.17.0+ (probably former versions as well, not tested) | ||
| License | No license specified | ||
| Download | Extension:CheckEmailAddress#Code | ||
|
|||
|
|||
| Check usage and version matrix | |||
Contents |
What can this extension do? [edit]
This simple 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.
Installation [edit]
To install this extension, add the following to LocalSettings.php:
require_once("$IP/extensions/CheckEmailAddress/CheckEmailAddress.php"); $wgCheckEmailAddressDomainSources = array( 'type' => CEASRC_FILE, 'src' => "$IP/Blacklistfile.txt" ); $wgCheckEmailAddressNameSigns = array( 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:
mailinator.com spoofmail.de ...
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]
$wgCheckEmailAddressDomainSources [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.
$wgCheckEmailAddressNameSigns [edit]
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.
Code [edit]
CheckEmailAddress consists of three files.
CheckEmailAddress.php [edit]
<?php if ( !defined( 'MEDIAWIKI' ) ) { exit(1); } $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'CheckEmailAddress', 'author' => 'Mirko Schiefelbein', 'url' => 'http://www.mediawiki.org/wiki/Extension:CheckEmailAddress', 'descriptionmsg' => 'checkemailaddress-desc', 'version' => '0.9', ); $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';
CheckEmailAddress.hooks.php [edit]
<?php 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 = wfMsg( 'checkemailaddress-domainerror' ); 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 = wfMsg( 'checkemailaddress-nameerror' ); unset( $value ); return false; } } unset( $value ); return true; } }
CheckEmailAddress.i18n.php [edit]
$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 auszuschließen',
'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...',
);
Feedback [edit]
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.