Inject ChangeTagsManager to ChangeTagger

We decided to have the tag name provided by ChangeTagsManager,
so make ChangeTagger depend on it.

Change-Id: If3cbfd992f45651f47477031befffc0fd30f4a28
This commit is contained in:
Matěj Suchánek 2020-10-21 16:30:43 +02:00
parent 85e000c6ed
commit 93556284a0
3 changed files with 20 additions and 3 deletions

View file

@ -17,6 +17,18 @@ class ChangeTagger {
/** @var array (Persistent) map of (action ID => string[]) */
private static $tagsToSet = [];
/**
* @var ChangeTagsManager
*/
private $changeTagsManager;
/**
* @param ChangeTagsManager $changeTagsManager
*/
public function __construct( ChangeTagsManager $changeTagsManager ) {
$this->changeTagsManager = $changeTagsManager;
}
/**
* Clear any buffered tag
*/
@ -29,7 +41,7 @@ class ChangeTagger {
* @phan-param array{action:string,username:string,target:LinkTarget,accountname?:?string} $actionSpecs
*/
public function addConditionsLimitTag( array $actionSpecs ) : void {
$this->addTags( $actionSpecs, [ 'abusefilter-condition-limit' ] );
$this->addTags( $actionSpecs, [ $this->changeTagsManager->getCondsLimitTag() ] );
}
/**

View file

@ -32,7 +32,9 @@ return [
return new PermManager( $services->getPermissionManager() );
},
ChangeTagger::SERVICE_NAME => function ( MediaWikiServices $services ) : ChangeTagger {
return new ChangeTagger();
return new ChangeTagger(
$services->getService( ChangeTagsManager::SERVICE_NAME )
);
},
ChangeTagsManager::SERVICE_NAME => function ( MediaWikiServices $services ): ChangeTagsManager {
return new ChangeTagsManager(

View file

@ -1,6 +1,7 @@
<?php
use MediaWiki\Extension\AbuseFilter\ChangeTagger;
use MediaWiki\Extension\AbuseFilter\ChangeTagsManager;
/**
* @group Test
@ -12,7 +13,9 @@ class AbuseFilterChangeTaggerTest extends MediaWikiUnitTestCase {
* @return ChangeTagger
*/
private function getTagger() : ChangeTagger {
return new ChangeTagger();
$manager = $this->createMock( ChangeTagsManager::class );
$manager->method( 'getCondsLimitTag' )->willReturn( 'tag' );
return new ChangeTagger( $manager );
}
/**