| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter; |
| 4 |
|
| 5 |
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesRegistry; |
| 6 |
use MediaWiki\Extension\AbuseFilter\Filter\ExistingFilter; |
| 7 |
use MediaWiki\Extension\AbuseFilter\Special\SpecialAbuseFilter; |
| 8 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 9 |
use MediaWiki\Title\Title; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class EchoNotifier { |
| 16 |
public const SERVICE_NAME = 'AbuseFilterEchoNotifier'; |
| 17 |
public const EVENT_TYPE = 'throttled-filter'; |
| 18 |
|
| 19 |
|
| 20 |
private $filterLookup; |
| 21 |
|
| 22 |
private $consequencesRegistry; |
| 23 |
|
| 24 |
private $isEchoLoaded; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function __construct( |
| 32 |
FilterLookup $filterLookup, |
| 33 |
ConsequencesRegistry $consequencesRegistry, |
| 34 |
bool $isEchoLoaded |
| 35 |
) { |
| 36 |
$this->filterLookup = $filterLookup; |
| 37 |
$this->consequencesRegistry = $consequencesRegistry; |
| 38 |
$this->isEchoLoaded = $isEchoLoaded; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private function getTitleForFilter( int $filter ): Title { |
| 46 |
return SpecialAbuseFilter::getTitleForSubpage( (string)$filter ); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
private function getFilterObject( int $filter ): ExistingFilter { |
| 54 |
return $this->filterLookup->getFilter( $filter, false ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public function getDataForEvent( int $filter ): array { |
| 63 |
$filterObj = $this->getFilterObject( $filter ); |
| 64 |
$throttledActionNames = array_intersect( |
| 65 |
$filterObj->getActionsNames(), |
| 66 |
$this->consequencesRegistry->getDangerousActionNames() |
| 67 |
); |
| 68 |
return [ |
| 69 |
'type' => self::EVENT_TYPE, |
| 70 |
'title' => $this->getTitleForFilter( $filter ), |
| 71 |
'extra' => [ |
| 72 |
'user' => $filterObj->getUserID(), |
| 73 |
'throttled-actions' => $throttledActionNames, |
| 74 |
], |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public function notifyForFilter( int $filter ) { |
| 85 |
if ( $this->isEchoLoaded ) { |
| 86 |
return Event::create( $this->getDataForEvent( $filter ) ); |
| 87 |
} |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
} |