2012-01-18 23:29:37 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-08 13:05:02 +00:00
|
|
|
namespace MediaWiki\Extension\SpamBlacklist;
|
|
|
|
|
|
|
|
use LogicException;
|
|
|
|
use Title;
|
|
|
|
use User;
|
2022-02-24 21:15:28 +00:00
|
|
|
use Wikimedia\AtEase\AtEase;
|
|
|
|
|
2012-01-18 23:29:37 +00:00
|
|
|
/**
|
|
|
|
* Email Blacklisting
|
|
|
|
*/
|
|
|
|
class EmailBlacklist extends BaseBlacklist {
|
2015-06-22 20:00:28 +00:00
|
|
|
/**
|
2020-01-04 11:16:36 +00:00
|
|
|
* @inheritDoc
|
2021-09-08 21:17:20 +00:00
|
|
|
* @suppress PhanPluginNeverReturnMethod LSP/ISP violation
|
2015-06-22 20:00:28 +00:00
|
|
|
*/
|
2020-01-04 12:48:07 +00:00
|
|
|
public function filter( array $links, ?Title $title, User $user, $preventLog = false ) {
|
2015-06-22 20:00:28 +00:00
|
|
|
throw new LogicException( __CLASS__ . ' cannot be used to filter links.' );
|
|
|
|
}
|
2012-01-18 23:29:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the code for the blacklist implementation
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getBlacklistType() {
|
|
|
|
return 'email';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-27 11:50:47 +00:00
|
|
|
* Checks a User object for a blacklisted email 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;
|
|
|
|
}
|
|
|
|
|
2013-02-27 11:50:47 +00:00
|
|
|
// Check for whitelisted email addresses
|
2012-01-18 23:29:37 +00:00
|
|
|
if ( is_array( $whitelists ) ) {
|
2017-06-02 16:02:09 +00:00
|
|
|
wfDebugLog( 'SpamBlacklist', "Excluding whitelisted email addresses from " .
|
|
|
|
count( $whitelists ) . " regexes: " . implode( ', ', $whitelists ) . "\n" );
|
2012-01-18 23:29:37 +00:00
|
|
|
foreach ( $whitelists as $regex ) {
|
2022-02-24 21:15:28 +00:00
|
|
|
AtEase::suppressWarnings();
|
2019-11-07 22:08:16 +00:00
|
|
|
$match = preg_match( $regex, $email );
|
2022-02-24 21:15:28 +00:00
|
|
|
AtEase::restoreWarnings();
|
2019-11-07 22:08:16 +00:00
|
|
|
if ( $match ) {
|
2012-01-18 23:29:37 +00:00
|
|
|
// 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 ) {
|
2022-02-24 21:15:28 +00:00
|
|
|
AtEase::suppressWarnings();
|
2019-11-07 22:08:16 +00:00
|
|
|
$match = preg_match( $regex, $email );
|
2022-02-24 21:15:28 +00:00
|
|
|
AtEase::restoreWarnings();
|
2019-11-07 22:08:16 +00:00
|
|
|
if ( $match ) {
|
2012-01-18 23:29:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|