Debian Codegraph @

extensions/AbuseFilter/includes/Hooks/Handlers/AutoPromoteGroupsHandler.php

raw symbols SCIP
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 /** @var BagOStuff */
15 private $cache;
16
17 /** @var ConsequencesRegistry */
18 private $consequencesRegistry;
19
20 /** @var BlockAutopromoteStore */
21 private $blockAutopromoteStore;
22
23 /**
24 * @param ConsequencesRegistry $consequencesRegistry
25 * @param BlockAutopromoteStore $blockAutopromoteStore
26 * @param BagOStuff|null $cache
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 * @param UserIdentity $user
40 * @param string[] &$promote
41 */
42 public function onGetAutoPromoteGroups( $user, &$promote ): void {
43 if (
44 in_array( 'blockautopromote', $this->consequencesRegistry->getAllEnabledActionNames() )
45 && $promote
46 ) {
47 // Proxy the blockautopromote data to a faster backend, using an appropriate key
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 }