| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; |
| 4 |
|
| 5 |
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore; |
| 6 |
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesRegistry; |
| 7 |
use MediaWiki\User\Hook\GetAutoPromoteGroupsHook; |
| 8 |
use MediaWiki\User\UserIdentity; |
| 9 |
use Wikimedia\ObjectCache\BagOStuff; |
| 10 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 11 |
|
| 12 |
class AutoPromoteGroupsHandler implements GetAutoPromoteGroupsHook { |
| 13 |
|
| 14 |
|
| 15 |
private $cache; |
| 16 |
|
| 17 |
|
| 18 |
private $consequencesRegistry; |
| 19 |
|
| 20 |
|
| 21 |
private $blockAutopromoteStore; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function __construct( |
| 29 |
ConsequencesRegistry $consequencesRegistry, |
| 30 |
BlockAutopromoteStore $blockAutopromoteStore, |
| 31 |
?BagOStuff $cache = null |
| 32 |
) { |
| 33 |
$this->cache = $cache ?? new HashBagOStuff(); |
| 34 |
$this->consequencesRegistry = $consequencesRegistry; |
| 35 |
$this->blockAutopromoteStore = $blockAutopromoteStore; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function onGetAutoPromoteGroups( $user, &$promote ): void { |
| 43 |
if ( |
| 44 |
in_array( 'blockautopromote', $this->consequencesRegistry->getAllEnabledActionNames() ) |
| 45 |
&& $promote |
| 46 |
) { |
| 47 |
|
| 48 |
$quickCacheKey = $this->cache->makeKey( |
| 49 |
'abusefilter', |
| 50 |
'blockautopromote', |
| 51 |
'quick', |
| 52 |
$user->getId() |
| 53 |
); |
| 54 |
$blocked = (bool)$this->cache->getWithSetCallback( |
| 55 |
$quickCacheKey, |
| 56 |
BagOStuff::TTL_PROC_LONG, |
| 57 |
function () use ( $user ) { |
| 58 |
return $this->blockAutopromoteStore->getAutoPromoteBlockStatus( $user ); |
| 59 |
} |
| 60 |
); |
| 61 |
|
| 62 |
if ( $blocked ) { |
| 63 |
$promote = []; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |