Skip to content

Commit

Permalink
chore: Remove forward-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed May 26, 2024
1 parent c7e8323 commit 6285f83
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions includes/HookHandlers/SpamEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Config;
use MediaWiki\Block\DatabaseBlockStore;
use MediaWiki\Extension\SpamBlacklist\BaseBlacklist;
use MediaWiki\User\User;
use WANObjectCache;
use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\ILoadBalancer;
Expand Down Expand Up @@ -63,34 +62,27 @@ public function onIsValidEmailAddr( $addr, &$result ) {
}

// Check email addresses of block users
if ( version_compare( '1.42', MW_VERSION, '<=' ) ) {
$emails = array_filter( array_unique( array_map(
static fn( $block ) => User::newFromIdentity( $block->getBlocker() )->getEmail(),
$this->databaseBlockStore->newListFromConds( [ 'bt_user IS NOT NULL' ] )
) ) );
} else {
$loadBalancer = $this->loadBalancer;
$emails = $this->wanCache->getWithSetCallback(
$this->wanCache->makeKey( 'unified-femiwiki-extension-blocked-email' ),
WANObjectCache::TTL_HOUR,
static function ( $old, &$ttl, array &$setOpts ) use ( $loadBalancer ) {
$dbr = $loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
return $dbr->newSelectQueryBuilder()
->distinct()
->fields( [ 'user_email' ] )
->tables( [ 'ipblocks' ] )
->join( 'user', null, ['user_id = ipb_user'] )
->conds( [
'user_email_authenticated IS NOT NULL',
'user_email != ' . $dbr->addQuotes( '' ),
'ipb_expiry > ' . $dbr->addQuotes( $dbr->timestamp() ),
] )
->fetchFieldValues();
}
);
if ( !is_array( $emails ) ) {
$emails = [];
$loadBalancer = $this->loadBalancer;
$emails = $this->wanCache->getWithSetCallback(
$this->wanCache->makeKey( 'unified-femiwiki-extension-blocked-email' ),
WANObjectCache::TTL_HOUR,
static function ( $old, &$ttl, array &$setOpts ) use ( $loadBalancer ) {
$dbr = $loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
return $dbr->newSelectQueryBuilder()
->distinct()
->fields( [ 'user_email' ] )
->tables( [ 'ipblocks' ] )
->join( 'user', null, [ 'user_id = ipb_user' ] )
->conds( [
'user_email_authenticated IS NOT NULL',
'user_email != ' . $dbr->addQuotes( '' ),
'ipb_expiry > ' . $dbr->addQuotes( $dbr->timestamp() ),
] )
->fetchFieldValues();
}
);
if ( !is_array( $emails ) ) {
$emails = [];
}
if ( in_array( $addr, $emails ) ) {
return false;
Expand Down

0 comments on commit 6285f83

Please sign in to comment.