jenkins-bot has submitted this change and it was merged.

Change subject: Move EmailNotification watchlist handling into helper method
......................................................................


Move EmailNotification watchlist handling into helper method

Pulls one pure method with no state from EmailNotification into a 
public static method.  This is done so that extensions (Flow, maybe
others) can replace the Email notifications with alternative ones (Echo)
while still updating the watchlist.

A better solution might be to extricate watchlist update from email
notifications, but this seems like a reasonable first step.

Bug: 66876
Change-Id: Iae213b87706c447b880244711e7747954423bb69
---
M includes/mail/EmailNotification.php
1 file changed, 54 insertions(+), 36 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/mail/EmailNotification.php 
b/includes/mail/EmailNotification.php
index 9219c3a..8215403 100644
--- a/includes/mail/EmailNotification.php
+++ b/includes/mail/EmailNotification.php
@@ -58,6 +58,57 @@
        protected $editor;
 
        /**
+        * @param User $editor The editor that triggered the update.  Their 
notification
+        *  timestamp will not be updated(they have already seen it)
+        * @param Title $title The title to update timestamps for
+        * @param string $timestamp Set the upate timestamp to this value
+        * @return int[]
+        */
+       public static function updateWatchlistTimestamp( User $editor, Title 
$title, $timestamp ) {
+               global $wgEnotifWatchlist, $wgShowUpdatedMarker;
+
+               if ( !$wgEnotifWatchlist && !$wgShowUpdatedMarker ) {
+                       return array();
+               }
+
+               $dbw = wfGetDB( DB_MASTER );
+               $res = $dbw->select( array( 'watchlist' ),
+                       array( 'wl_user' ),
+                       array(
+                               'wl_user != ' . intval( $editor->getID() ),
+                               'wl_namespace' => $title->getNamespace(),
+                               'wl_title' => $title->getDBkey(),
+                               'wl_notificationtimestamp IS NULL',
+                       ), __METHOD__
+               );
+
+               $watchers = array();
+               foreach ( $res as $row ) {
+                       $watchers[] = intval( $row->wl_user );
+               }
+
+               if ( $watchers ) {
+                       // Update wl_notificationtimestamp for all watching 
users except the editor
+                       $fname = __METHOD__;
+                       $dbw->onTransactionIdle(
+                               function () use ( $dbw, $timestamp, $watchers, 
$title, $fname ) {
+                                       $dbw->update( 'watchlist',
+                                               array( /* SET */
+                                                       
'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
+                                               ), array( /* WHERE */
+                                                       'wl_user' => $watchers,
+                                                       'wl_namespace' => 
$title->getNamespace(),
+                                                       'wl_title' => 
$title->getDBkey(),
+                                               ), $fname
+                                       );
+                               }
+                       );
+               }
+
+               return $watchers;
+       }
+
+       /**
         * Send emails corresponding to the user $editor editing the page 
$title.
         * Also updates wl_notificationtimestamp.
         *
@@ -74,47 +125,14 @@
        public function notifyOnPageChange( $editor, $title, $timestamp, 
$summary,
                $minorEdit, $oldid = false, $pageStatus = 'changed'
        ) {
-               global $wgEnotifUseJobQ, $wgEnotifWatchlist, 
$wgShowUpdatedMarker, $wgEnotifMinorEdits,
-                      $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
+               global $wgEnotifUseJobQ, $wgEnotifMinorEdits, 
$wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
 
                if ( $title->getNamespace() < 0 ) {
                        return;
                }
 
-               // Build a list of users to notify
-               $watchers = array();
-               if ( $wgEnotifWatchlist || $wgShowUpdatedMarker ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       $res = $dbw->select( array( 'watchlist' ),
-                               array( 'wl_user' ),
-                               array(
-                                       'wl_user != ' . intval( 
$editor->getID() ),
-                                       'wl_namespace' => 
$title->getNamespace(),
-                                       'wl_title' => $title->getDBkey(),
-                                       'wl_notificationtimestamp IS NULL',
-                               ), __METHOD__
-                       );
-                       foreach ( $res as $row ) {
-                               $watchers[] = intval( $row->wl_user );
-                       }
-                       if ( $watchers ) {
-                               // Update wl_notificationtimestamp for all 
watching users except the editor
-                               $fname = __METHOD__;
-                               $dbw->onTransactionIdle(
-                                       function () use ( $dbw, $timestamp, 
$watchers, $title, $fname ) {
-                                               $dbw->update( 'watchlist',
-                                                       array( /* SET */
-                                                               
'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
-                                                       ), array( /* WHERE */
-                                                               'wl_user' => 
$watchers,
-                                                               'wl_namespace' 
=> $title->getNamespace(),
-                                                               'wl_title' => 
$title->getDBkey(),
-                                                       ), $fname
-                                               );
-                                       }
-                               );
-                       }
-               }
+               // update wl_notificationtimestamp for watchers
+               $watchers = self::updateWatchlistTimestamp( $editor, $title, 
$timestamp );
 
                $sendEmail = true;
                // If nobody is watching the page, and there are no users 
notified on all changes

-- 
To view, visit https://gerrit.wikimedia.org/r/159395
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iae213b87706c447b880244711e7747954423bb69
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to