mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SpamBlacklist
synced 2024-12-18 09:41:48 +00:00
da1af447e2
There are some usages outside of SpamBlacklist that must be fixed. After doing that, the signature should be updated to make the user non-optional. Note: I've changed the signature because external callers only pass the first two parameters. Hence, it's easier to change it now, add a User parameter to the callers and then make it non-optional, than having to pass $preserveLog and $mode in all callers and then swapping the order (as that would break the world). Change-Id: I0714eb9dbc6af3c775ab7a81cb4b59e687183f77
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Email Blacklisting
|
|
*/
|
|
class EmailBlacklist extends BaseBlacklist {
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function filter( array $links, ?Title $title, User $user = null, $preventLog = false ) {
|
|
throw new LogicException( __CLASS__ . ' cannot be used to filter links.' );
|
|
}
|
|
|
|
/**
|
|
* Returns the code for the blacklist implementation
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function getBlacklistType() {
|
|
return 'email';
|
|
}
|
|
|
|
/**
|
|
* Checks a User object for a blacklisted email address
|
|
*
|
|
* @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;
|
|
}
|
|
|
|
// Check for whitelisted email addresses
|
|
if ( is_array( $whitelists ) ) {
|
|
wfDebugLog( 'SpamBlacklist', "Excluding whitelisted email addresses from " .
|
|
count( $whitelists ) . " regexes: " . implode( ', ', $whitelists ) . "\n" );
|
|
foreach ( $whitelists as $regex ) {
|
|
Wikimedia\suppressWarnings();
|
|
$match = preg_match( $regex, $email );
|
|
Wikimedia\restoreWarnings();
|
|
if ( $match ) {
|
|
// Whitelisted email
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Do the match
|
|
wfDebugLog( 'SpamBlacklist', "Checking e-mail address against " . count( $blacklists ) .
|
|
" regexes: " . implode( ', ', $blacklists ) . "\n" );
|
|
foreach ( $blacklists as $regex ) {
|
|
Wikimedia\suppressWarnings();
|
|
$match = preg_match( $regex, $email );
|
|
Wikimedia\restoreWarnings();
|
|
if ( $match ) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|