mediawiki-extensions-SpamBl.../includes/EmailBlacklist.php
libraryupgrader 5cf47545c7 build: Updating composer dependencies
* mediawiki/mediawiki-phan-config: 0.10.6 → 0.11.0
* php-parallel-lint/php-parallel-lint: 1.3.0 → 1.3.1

Change-Id: Ib6db3984f5892a13461defbbe9f191ceb75853c8
2021-09-09 11:41:40 +00:00

72 lines
1.7 KiB
PHP

<?php
/**
* Email Blacklisting
*/
class EmailBlacklist extends BaseBlacklist {
/**
* @inheritDoc
* @suppress PhanPluginNeverReturnMethod LSP/ISP violation
*/
public function filter( array $links, ?Title $title, User $user, $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;
}
}