EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/159395

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

Move EmailNotification watchlist handling into helper methods

Pulls two pure methods with no state from EmailNotification into public
static methods.  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 extracate watchlist and email notifications,
but this seems like a reasonable first step.

Bug: 66876
Change-Id: Iae213b87706c447b880244711e7747954423bb69
---
M includes/UserMailer.php
1 file changed, 52 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/95/159395/1

diff --git a/includes/UserMailer.php b/includes/UserMailer.php
index 0ce9b5a..b7e2fc6 100644
--- a/includes/UserMailer.php
+++ b/includes/UserMailer.php
@@ -512,6 +512,53 @@
         */
        protected $editor;
 
+       static public function getWatchers( DatabaseBase $dbw, User $editor, 
Title $title ) {
+               global $wgEnotifWatchlist, $wgShowUpdatedMarker;
+
+               if ( !$wgEnotifWatchlist && !$wgShowUpdatedMarker ) {
+                       return array();
+               }
+
+               $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 );
+               }
+
+               return $watchers;
+       }
+
+       static public function updateWatchlist( DatabaseBase $dbw, $timestamp, 
array $watchers, Title $title ) {
+               if ( !$watchers ) {
+                       return;
+               }
+
+               // 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
+                               );
+                       }
+               );
+       }
+
        /**
         * Send emails corresponding to the user $editor editing the page 
$title.
         * Also updates wl_notificationtimestamp.
@@ -529,47 +576,18 @@
        public function notifyOnPageChange( $editor, $title, $timestamp, 
$summary,
                $minorEdit, $oldid = false, $pageStatus = 'changed'
        ) {
-               global $wgEnotifUseJobQ, $wgEnotifWatchlist, 
$wgShowUpdatedMarker, $wgEnotifMinorEdits,
+               global $wgEnotifUseJobQ, $wgEnotifMinorEdits,
                        $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
 
                if ( $title->getNamespace() < 0 ) {
                        return;
                }
 
+               $dbw = wfGetDB( DB_MASTER );
                // 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
-                                               );
-                                       }
-                               );
-                       }
-               }
+               $watchers = $this->getWatchers( $dbw, $editor, $title );
+               // update wl_notificationtimestamp for those users
+               $this->updateWatchlist( $dbw, $timestamp, $watchers, $title );
 
                $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: newchange
Gerrit-Change-Id: Iae213b87706c447b880244711e7747954423bb69
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to