mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-14 09:44:44 +00:00
5377ebe819
composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 npm: * postcss: 7.0.35 → 7.0.36 * https://npmjs.com/advisories/1693 (CVE-2021-23368) Change-Id: I2b382f3bb236fb44eb24c6a257b13b8fd886541c
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
use EchoEvent;
|
|
use MediaWiki\Extension\AbuseFilter\Special\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;
|
|
}
|
|
|
|
}
|