aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Miazga <pmiazga@wikimedia.org>2025-03-28 18:46:40 +0100
committerPiotr Miazga <pmiazga@wikimedia.org>2025-03-31 14:38:58 +0200
commitd66747fae78e44116e8f1feb699431763339be33 (patch)
tree844f4a8887f78b1d6971ee18a48d437fb1dd9e6a
parent457e8b521567e3851456b25345c60c941852c246 (diff)
downloadmediawikicore-d66747fae78e44116e8f1feb699431763339be33.tar.gz
mediawikicore-d66747fae78e44116e8f1feb699431763339be33.zip
enotif: Handle Talk notifications via new Notifications system
Migrated second ENotif Talk mail into Notification system. This is a third iteration. At the end all different notifications cause exactly the same Email. To future proof the system, we can pass the Source, which means what triggered this notification. Is it Talk, is it Watchlist or is caused by fact that Recipient is on the ENotifAll list. Bug: T387995 Change-Id: I1993208882097c591f93fb47d80076a93c34fcd9
-rw-r--r--includes/Notification/Handlers/RecentChangeNotificationHandler.php9
-rw-r--r--includes/mail/EmailNotification.php33
-rw-r--r--includes/watchlist/RecentChangeNotification.php10
3 files changed, 39 insertions, 13 deletions
diff --git a/includes/Notification/Handlers/RecentChangeNotificationHandler.php b/includes/Notification/Handlers/RecentChangeNotificationHandler.php
index 1f874c8be215..885d01d96326 100644
--- a/includes/Notification/Handlers/RecentChangeNotificationHandler.php
+++ b/includes/Notification/Handlers/RecentChangeNotificationHandler.php
@@ -39,6 +39,11 @@ class RecentChangeNotificationHandler implements NotificationHandler {
return;
}
$properties = $notification->getProperties();
+ $sourceMap = [
+ RecentChangeNotification::ADMIN_NOTIFICATION => RecentChangeMailComposer::ALL_CHANGES,
+ RecentChangeNotification::TALK_NOTIFICATION => RecentChangeMailComposer::USER_TALK,
+ ];
+ $source = $sourceMap[ $properties['source'] ] ?? RecentChangeMailComposer::ALL_CHANGES;
$composer = new RecentChangeMailComposer(
$this->userFactory->newFromUserIdentity( $notification->getAgent() ),
@@ -52,9 +57,7 @@ class RecentChangeNotificationHandler implements NotificationHandler {
foreach ( $recipients as $recipient ) {
$user = $this->userFactory->newFromUserIdentity( $recipient );
if ( $this->checkNotificationRequirements( $notification, $user ) ) {
- // TODO - for now it handles only ALL changes, future patches will provide support
- // for WATCHLIST and USER_TALK
- $composer->compose( $recipient, RecentChangeMailComposer::ALL_CHANGES );
+ $composer->compose( $recipient, $source );
}
}
// TODO - sendEmails is deprecated, remove it in 1.45. need to keep it in parity in case
diff --git a/includes/mail/EmailNotification.php b/includes/mail/EmailNotification.php
index af4b1d2445c0..d065791cfa11 100644
--- a/includes/mail/EmailNotification.php
+++ b/includes/mail/EmailNotification.php
@@ -26,12 +26,14 @@ use MediaWiki\HookContainer\HookRunner;
use MediaWiki\Mail\RecentChangeMailComposer;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Notification\RecipientSet;
use MediaWiki\Permissions\Authority;
use MediaWiki\RecentChanges\RecentChange;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
use MediaWiki\User\UserArray;
use MediaWiki\User\UserIdentity;
+use MediaWiki\Watchlist\RecentChangeNotification;
/**
* Find watchers and create email notifications after a page is changed.
@@ -196,6 +198,8 @@ class EmailNotification {
# we use $wgPasswordSender as sender's address
$mwServices = MediaWikiServices::getInstance();
$config = $mwServices->getMainConfig();
+ $notifService = $mwServices->getNotificationService();
+ $userFactory = $mwServices->getUserFactory();
# The following code is only run, if several conditions are met:
# 1. EmailNotification for pages (other than user_talk pages) must be enabled
@@ -230,9 +234,21 @@ class EmailNotification {
&& $title->getNamespace() === NS_USER_TALK
&& $this->canSendUserTalkEmail( $editor->getUser(), $title, $minorEdit )
) {
- $targetUser = User::newFromName( $title->getText() );
- $composer->compose( $targetUser, RecentChangeMailComposer::USER_TALK );
- $userTalkId = $targetUser->getId();
+ $targetUser = $userFactory->newFromName( $title->getText() );
+ if ( $targetUser ) {
+ $talkNotification = new RecentChangeNotification(
+ $mwServices->getUserFactory()->newFromAuthority( $editor ),
+ $title,
+ $summary,
+ $minorEdit,
+ $oldid,
+ $timestamp,
+ $pageStatus,
+ RecentChangeNotification::TALK_NOTIFICATION
+ );
+ $notifService->notify( $talkNotification, new RecipientSet( [ $targetUser ] ) );
+ $userTalkId = $targetUser->getId();
+ }
}
if ( $config->get( MainConfigNames::EnotifWatchlist ) ) {
@@ -265,21 +281,22 @@ class EmailNotification {
// No point notifying the user that actually made the change!
continue;
}
- $user = User::newFromName( $name );
+ $user = $userFactory->newFromName( $name );
if ( $user instanceof User ) {
$admins[] = $user;
}
- MediaWikiServices::getInstance()->getNotificationService()->notify(
- new \MediaWiki\Watchlist\RecentChangeNotification(
+ $notifService->notify(
+ new RecentChangeNotification(
$mwServices->getUserFactory()->newFromAuthority( $editor ),
$title,
$summary,
$minorEdit,
$oldid,
$timestamp,
- $pageStatus
+ $pageStatus,
+ RecentChangeNotification::ADMIN_NOTIFICATION
),
- new \MediaWiki\Notification\RecipientSet( $admins )
+ new RecipientSet( $admins )
);
}
diff --git a/includes/watchlist/RecentChangeNotification.php b/includes/watchlist/RecentChangeNotification.php
index 9e5c0a6d952a..afdc1f3bfe3b 100644
--- a/includes/watchlist/RecentChangeNotification.php
+++ b/includes/watchlist/RecentChangeNotification.php
@@ -35,6 +35,9 @@ class RecentChangeNotification extends WikiNotification {
public const TYPE = 'mediawiki.recent_change';
+ public const TALK_NOTIFICATION = 'talk';
+ public const ADMIN_NOTIFICATION = 'admin';
+
/**
* @todo Pass the RecentChange object
*
@@ -45,6 +48,7 @@ class RecentChangeNotification extends WikiNotification {
* @param int|null $oldid
* @param string $timestamp
* @param string $pageStatus
+ * @param string $source one of types talk, admin or watchlist
*/
public function __construct(
UserIdentity $editor,
@@ -53,7 +57,8 @@ class RecentChangeNotification extends WikiNotification {
bool $minorEdit,
$oldid,
$timestamp,
- string $pageStatus
+ string $pageStatus,
+ string $source
) {
parent::__construct(
self::TYPE, $title, $editor, [
@@ -61,7 +66,8 @@ class RecentChangeNotification extends WikiNotification {
'minorEdit' => $minorEdit,
'oldid' => $oldid,
'timestamp' => $timestamp,
- 'pageStatus' => $pageStatus
+ 'pageStatus' => $pageStatus,
+ 'source' => $source
]
);
}