mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-14 19:28:31 +00:00
Don't send page-linked notifications for pages created by bot users
Bug: T318523 Change-Id: I704a2912e0a8b0e996d4e4e0a73f4ed3b9ccf6be
This commit is contained in:
parent
016b25b43a
commit
53efddc825
|
@ -131,6 +131,10 @@ class EchoUserLocator {
|
||||||
|
|
||||||
$user = User::newFromId( $res->rev_user );
|
$user = User::newFromId( $res->rev_user );
|
||||||
if ( $user ) {
|
if ( $user ) {
|
||||||
|
// T318523: Don't send page-linked notifications for pages created by bot users.
|
||||||
|
if ( $event->getType() === 'page-linked' && $user->isBot() ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
return [ $user->getId() => $user ];
|
return [ $user->getId() => $user ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,37 @@ class UserLocatorTest extends MediaWikiIntegrationTestCase {
|
||||||
$this->assertEquals( $expect, array_keys( $users ), $message );
|
$this->assertEquals( $expect, array_keys( $users ), $message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDontSendPageLinkedNotificationsForPagesCreatedByBotUsers() {
|
||||||
|
$botUser = $this->getTestUser( [ 'bot' ] )->getUser();
|
||||||
|
$botUser->addToDatabase();
|
||||||
|
$this->editPage( 'TestBotCreatedPage', 'Test', '', NS_MAIN, $botUser );
|
||||||
|
$this->editPage( 'SomeOtherPage', '[[TestBotCreatedPage]]' );
|
||||||
|
$event = $this->createMock( Event::class );
|
||||||
|
$event->method( 'getTitle' )
|
||||||
|
->willReturn( Title::newFromText( 'TestBotCreatedPage' ) );
|
||||||
|
$event->method( 'getAgent' )
|
||||||
|
->willReturn( User::newFromId( 123 ) );
|
||||||
|
$event->method( 'getType' )
|
||||||
|
->willReturn( 'page-linked' );
|
||||||
|
$this->assertEquals( [], EchoUserLocator::locateArticleCreator( $event ) );
|
||||||
|
|
||||||
|
$normalUser = $this->getTestUser()->getUser();
|
||||||
|
$normalUser->addToDatabase();
|
||||||
|
$this->editPage( 'NormalCreatedPage', 'Test', '', NS_MAIN, $normalUser );
|
||||||
|
$this->editPage( 'AnotherPage', '[[NormalCreatedPage]]' );
|
||||||
|
$event = $this->createMock( Event::class );
|
||||||
|
$event->method( 'getTitle' )
|
||||||
|
->willReturn( Title::newFromText( 'NormalCreatedPage' ) );
|
||||||
|
$event->method( 'getAgent' )
|
||||||
|
->willReturn( User::newFromId( 456 ) );
|
||||||
|
$event->method( 'getType' )
|
||||||
|
->willReturn( 'page-linked' );
|
||||||
|
$this->assertEquals(
|
||||||
|
$normalUser->getUser()->getId(),
|
||||||
|
array_key_first( EchoUserLocator::locateArticleCreator( $event ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function locateEventAgentProvider() {
|
public static function locateEventAgentProvider() {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in a new issue