mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 02:03:53 +00:00
352a207c70
Bug: T201193 Change-Id: Ie086fd525bec19c63c13f8710a27897229cc33c8
80 lines
1.6 KiB
PHP
80 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
use EchoEvent;
|
|
use SpecialAbuseFilter;
|
|
use Title;
|
|
|
|
/**
|
|
* Helper service for EmergencyWatcher to notify filter maintainers of throttled filters
|
|
* @todo DI not possible due to Echo
|
|
*/
|
|
class EchoNotifier {
|
|
public const SERVICE_NAME = 'AbuseFilterEchoNotifier';
|
|
public const EVENT_TYPE = 'throttled-filter';
|
|
|
|
/** @var FilterLookup */
|
|
private $filterLookup;
|
|
|
|
/** @var bool */
|
|
private $isEchoLoaded;
|
|
|
|
/**
|
|
* @param FilterLookup $filterLookup
|
|
* @param bool $isEchoLoaded
|
|
*/
|
|
public function __construct(
|
|
FilterLookup $filterLookup,
|
|
bool $isEchoLoaded
|
|
) {
|
|
$this->filterLookup = $filterLookup;
|
|
$this->isEchoLoaded = $isEchoLoaded;
|
|
}
|
|
|
|
/**
|
|
* @param int $filter
|
|
* @return Title
|
|
*/
|
|
private function getTitleForFilter( int $filter ) : Title {
|
|
return SpecialAbuseFilter::getTitleForSubpage( (string)$filter );
|
|
}
|
|
|
|
/**
|
|
* @param int $filter
|
|
* @return int
|
|
*/
|
|
private function getLastUserIDForFilter( int $filter ) : int {
|
|
return $this->filterLookup->getFilter( $filter, false )->getUserID();
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
* @param int $filter
|
|
* @return array
|
|
*/
|
|
public function getDataForEvent( int $filter ) : array {
|
|
return [
|
|
'type' => self::EVENT_TYPE,
|
|
'title' => $this->getTitleForFilter( $filter ),
|
|
'extra' => [
|
|
'user' => $this->getLastUserIDForFilter( $filter ),
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Send notification about a filter being throttled
|
|
*
|
|
* @param int $filter
|
|
* @return EchoEvent|false
|
|
*/
|
|
public function notifyForFilter( int $filter ) {
|
|
if ( $this->isEchoLoaded ) {
|
|
return EchoEvent::create( $this->getDataForEvent( $filter ) );
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|