LinksUpdate: Don't send page-linked notifications for pages created by bot users

Follows-up: I704a2912e0a8b0e996d4e4e0a73f4ed3b9ccf6be
Bug: T318523
Change-Id: I32edf044b858956d030d318994d799071cde521b
This commit is contained in:
Kosta Harlan 2023-05-16 14:43:49 +02:00
parent 2686d9ceb1
commit 61a656ac27
No known key found for this signature in database
GPG key ID: BC3D8915606A5ED9
2 changed files with 29 additions and 15 deletions

View file

@ -13,6 +13,7 @@ use EchoEmailFormat;
use EchoEmailFrequency;
use EchoSeenTime;
use EchoServices;
use EchoUserLocator;
use EmailNotification;
use ExtensionRegistry;
use HTMLCheckMatrix;
@ -945,6 +946,11 @@ class Hooks implements
}
$linkFromPageId = $linksUpdate->getTitle()->getArticleID();
// T318523: Don't send page-linked notifications for pages created by bot users.
$articleAuthor = EchoUserLocator::getArticleAuthorByArticleId( $title->getArticleID() );
if ( $articleAuthor && $articleAuthor->isBot() ) {
continue;
}
Event::create( [
'type' => 'page-linked',
'title' => $title,

View file

@ -115,21 +115,7 @@ class EchoUserLocator {
return [];
}
$dbr = wfGetDB( DB_REPLICA );
$revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
$res = $dbr->selectRow(
$revQuery['tables'],
[ 'rev_user' => $revQuery['fields']['rev_user'] ],
[ 'rev_page' => $title->getArticleID() ],
__METHOD__,
[ 'LIMIT' => 1, 'ORDER BY' => 'rev_timestamp, rev_id' ],
$revQuery['joins']
);
if ( !$res || !$res->rev_user ) {
return [];
}
$user = User::newFromId( $res->rev_user );
$user = self::getArticleAuthorByArticleId( $title->getArticleID() );
if ( $user ) {
// T318523: Don't send page-linked notifications for pages created by bot users.
if ( $event->getType() === 'page-linked' && $user->isBot() ) {
@ -141,6 +127,28 @@ class EchoUserLocator {
return [];
}
/**
* @param int $articleId
* @return User|null
*/
public static function getArticleAuthorByArticleId( int $articleId ): ?User {
$dbr = wfGetDB( DB_REPLICA );
$revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
$res = $dbr->selectRow(
$revQuery['tables'],
[ 'rev_user' => $revQuery['fields']['rev_user'] ],
[ 'rev_page' => $articleId ],
__METHOD__,
[ 'LIMIT' => 1, 'ORDER BY' => 'rev_timestamp, rev_id' ],
$revQuery['joins']
);
if ( !$res || !$res->rev_user ) {
return null;
}
return User::newFromId( $res->rev_user );
}
/**
* Fetch user ids from the event extra data. Requires additional
* parameter. Example $wgEchoNotifications parameter: