Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks
[lhc/web/wiklou.git] / includes / mail / EmailNotification.php
index 9219c3a..81c4e38 100644 (file)
@@ -57,6 +57,57 @@ class EmailNotification {
         */
        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 @@ class EmailNotification {
        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
@@ -187,8 +205,6 @@ class EmailNotification {
                global $wgEnotifWatchlist;
                global $wgEnotifMinorEdits, $wgEnotifUserTalk;
 
-               wfProfileIn( __METHOD__ );
-
                # The following code is only run, if several conditions are met:
                # 1. EmailNotification for pages (other than user_talk pages) must be enabled
                # 2. minor edits (changes) are only regarded if the global flag indicates so
@@ -206,9 +222,8 @@ class EmailNotification {
 
                $formattedPageStatus = array( 'deleted', 'created', 'moved', 'restored', 'changed' );
 
-               wfRunHooks( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) );
+               Hooks::run( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) );
                if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
-                       wfProfileOut( __METHOD__ );
                        throw new MWException( 'Not a valid page status!' );
                }
 
@@ -233,7 +248,7 @@ class EmailNotification {
                                                && $watchingUser->isEmailConfirmed()
                                                && $watchingUser->getID() != $userTalkId
                                        ) {
-                                               if ( wfRunHooks( 'SendWatchlistEmailNotification', array( $watchingUser, $title, $this ) ) ) {
+                                               if ( Hooks::run( 'SendWatchlistEmailNotification', array( $watchingUser, $title, $this ) ) ) {
                                                        $this->compose( $watchingUser );
                                                }
                                        }
@@ -252,7 +267,6 @@ class EmailNotification {
                }
 
                $this->sendMails();
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -277,7 +291,7 @@ class EmailNotification {
                        ) {
                                if ( !$targetUser->isEmailConfirmed() ) {
                                        wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
-                               } elseif ( !wfRunHooks( 'AbortTalkPageEmailNotification', array( $targetUser, $title ) ) ) {
+                               } elseif ( !Hooks::run( 'AbortTalkPageEmailNotification', array( $targetUser, $title ) ) ) {
                                        wfDebug( __METHOD__ . ": talk page update notification is aborted for this user\n" );
                                } else {
                                        wfDebug( __METHOD__ . ": sending talk page update notification\n" );