Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
EmailBlacklist | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
filter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBlacklistType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkUser | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
56 |
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 | * Email Blacklisting |
12 | */ |
13 | class EmailBlacklist extends BaseBlacklist { |
14 | /** |
15 | * @inheritDoc |
16 | * @suppress PhanPluginNeverReturnMethod LSP/ISP violation |
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 | * Returns the code for the blacklist implementation |
24 | * |
25 | * @return string |
26 | */ |
27 | protected function getBlacklistType() { |
28 | return 'email'; |
29 | } |
30 | |
31 | /** |
32 | * Checks a User object for a blacklisted email address |
33 | * |
34 | * @param User $user |
35 | * @return bool True on valid email |
36 | */ |
37 | public function checkUser( User $user ) { |
38 | $blacklists = $this->getBlacklists(); |
39 | $whitelists = $this->getWhitelists(); |
40 | |
41 | // The email to check |
42 | $email = $user->getEmail(); |
43 | |
44 | if ( !count( $blacklists ) ) { |
45 | // Nothing to check |
46 | return true; |
47 | } |
48 | |
49 | // Check for whitelisted email addresses |
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 | // Whitelisted email |
59 | return true; |
60 | } |
61 | } |
62 | } |
63 | |
64 | # Do the match |
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 | } |