| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\SpamBlacklist; |
| 4 |
|
| 5 |
use LogicException; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
use MediaWiki\User\User; |
| 8 |
use Wikimedia\AtEase\AtEase; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class EmailBlacklist extends BaseBlacklist { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public function filter( array $links, ?Title $title, User $user, $preventLog = false ) { |
| 19 |
throw new LogicException( __CLASS__ . ' cannot be used to filter links.' ); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
protected function getBlacklistType() { |
| 28 |
return 'email'; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function checkUser( User $user ) { |
| 38 |
$blacklists = $this->getBlacklists(); |
| 39 |
$whitelists = $this->getWhitelists(); |
| 40 |
|
| 41 |
|
| 42 |
$email = $user->getEmail(); |
| 43 |
|
| 44 |
if ( !count( $blacklists ) ) { |
| 45 |
|
| 46 |
return true; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
if ( is_array( $whitelists ) ) { |
| 51 |
wfDebugLog( 'SpamBlacklist', "Excluding whitelisted email addresses from " . |
| 52 |
count( $whitelists ) . " regexes: " . implode( ', ', $whitelists ) . "\n" ); |
| 53 |
foreach ( $whitelists as $regex ) { |
| 54 |
AtEase::suppressWarnings(); |
| 55 |
$match = preg_match( $regex, $email ); |
| 56 |
AtEase::restoreWarnings(); |
| 57 |
if ( $match ) { |
| 58 |
|
| 59 |
return true; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
wfDebugLog( 'SpamBlacklist', "Checking e-mail address against " . count( $blacklists ) . |
| 66 |
" regexes: " . implode( ', ', $blacklists ) . "\n" ); |
| 67 |
foreach ( $blacklists as $regex ) { |
| 68 |
AtEase::suppressWarnings(); |
| 69 |
$match = preg_match( $regex, $email ); |
| 70 |
AtEase::restoreWarnings(); |
| 71 |
if ( $match ) { |
| 72 |
return false; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return true; |
| 77 |
} |
| 78 |
} |