2012-01-18 23:29:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Email Blacklisting
|
|
|
|
*/
|
|
|
|
class EmailBlacklist extends BaseBlacklist {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the code for the blacklist implementation
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getBlacklistType() {
|
|
|
|
return 'email';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-21 15:05:49 +00:00
|
|
|
* Checks a User object for a blacklisted e-mail address
|
2012-01-18 23:29:37 +00:00
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @return bool True on valid email
|
|
|
|
*/
|
|
|
|
public function checkUser( User $user ) {
|
|
|
|
$blacklists = $this->getBlacklists();
|
|
|
|
$whitelists = $this->getWhitelists();
|
|
|
|
|
|
|
|
// The email to check
|
|
|
|
$email = $user->getEmail();
|
|
|
|
|
|
|
|
if ( !count( $blacklists ) ) {
|
|
|
|
// Nothing to check
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-21 15:05:49 +00:00
|
|
|
// Check for whitelisted e-mail addresses
|
2012-01-18 23:29:37 +00:00
|
|
|
if ( is_array( $whitelists ) ) {
|
2012-01-21 15:05:49 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "Excluding whitelisted e-mail addresses from " . count( $whitelists ) .
|
2012-01-18 23:29:37 +00:00
|
|
|
" regexes: " . implode( ', ', $whitelists ) . "\n" );
|
|
|
|
foreach ( $whitelists as $regex ) {
|
|
|
|
if ( preg_match( $regex, $email ) ) {
|
|
|
|
// Whitelisted email
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Do the match
|
2012-01-21 15:05:49 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "Checking e-mail address against " . count( $blacklists ) .
|
2012-01-18 23:29:37 +00:00
|
|
|
" regexes: " . implode( ', ', $blacklists ) . "\n" );
|
|
|
|
foreach ( $blacklists as $regex ) {
|
|
|
|
if ( preg_match( $regex, $email ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|