]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/UserMailer.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / UserMailer.php
index ab1a740b98766f80a6fe7a5de6c9e6a7680fafae..b6484935d186fa61764d48c1837cdf1ebf206f8e 100644 (file)
@@ -40,7 +40,7 @@ class MailAddress {
                } else {
                        $this->address = strval( $address );
                        $this->name = strval( $name );
-                       $this->reaName = strval( $realName );
+                       $this->realName = strval( $realName );
                }
        }
 
@@ -101,7 +101,7 @@ class UserMailer {
         * @param $from MailAddress: sender's email
         * @param $subject String: email's subject.
         * @param $body String: email's text.
-        * @param $replyto String: optional reply-to email (default: null).
+        * @param $replyto MailAddress: optional reply-to email (default: null).
         * @param $contentType String: optional custom Content-Type
         * @return mixed True on success, a WikiError object on failure.
         */
@@ -281,11 +281,44 @@ class EmailNotification {
         * @param $oldid (default: false)
         */
        function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) {
-               global $wgEnotifUseJobQ;
+               global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
 
-               if( $title->getNamespace() < 0 )
+               if ($title->getNamespace() < 0)
                        return;
 
+               // Build a list of users to notfiy
+               $watchers = array();
+               if ($wgEnotifWatchlist || $wgShowUpdatedMarker) {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $res = $dbw->select( array( 'watchlist' ),
+                               array( 'wl_user' ),
+                               array(
+                                       'wl_title' => $title->getDBkey(),
+                                       'wl_namespace' => $title->getNamespace(),
+                                       'wl_user != ' . intval( $editor->getID() ),
+                                       'wl_notificationtimestamp IS NULL',
+                               ), __METHOD__
+                       );
+                       while ($row = $dbw->fetchObject( $res ) ) {
+                               $watchers[] = intval( $row->wl_user );
+                       }
+                       if ($watchers) {
+                               // Update wl_notificationtimestamp for all watching users except
+                               // the editor
+                               $dbw->begin();
+                               $dbw->update( 'watchlist',
+                                       array( /* SET */
+                                               'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
+                                       ), array( /* WHERE */
+                                               'wl_title' => $title->getDBkey(),
+                                               'wl_namespace' => $title->getNamespace(),
+                                               'wl_user' => $watchers
+                                       ), __METHOD__
+                               );
+                               $dbw->commit();
+                       }
+               }
+
                if ($wgEnotifUseJobQ) {
                        $params = array(
                                "editor" => $editor->getName(),
@@ -293,11 +326,12 @@ class EmailNotification {
                                "timestamp" => $timestamp,
                                "summary" => $summary,
                                "minorEdit" => $minorEdit,
-                               "oldid" => $oldid);
+                               "oldid" => $oldid,
+                               "watchers" => $watchers);
                        $job = new EnotifNotifyJob( $title, $params );
                        $job->insert();
                } else {
-                       $this->actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid);
+                       $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
                }
 
        }
@@ -310,16 +344,16 @@ class EmailNotification {
         *
         * @param $editor User object
         * @param $title Title object
-        * @param $timestamp
-        * @param $summary
-        * @param $minorEdit
-        * @param $oldid (default: false)
+        * @param $timestamp string Edit timestamp
+        * @param $summary string Edit summary
+        * @param $minorEdit bool
+        * @param $oldid int Revision ID
+        * @param $watchers array of user IDs
         */
-       function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid=false) {
-
+       function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers) {
                # we use $wgPasswordSender as sender's address
                global $wgEnotifWatchlist;
-               global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
+               global $wgEnotifMinorEdits, $wgEnotifUserTalk;
                global $wgEnotifImpersonal;
 
                wfProfileIn( __METHOD__ );
@@ -364,30 +398,12 @@ class EmailNotification {
 
                        if ( $wgEnotifWatchlist ) {
                                // Send updates to watchers other than the current editor
-                               $userCondition = 'wl_user != ' . $editor->getID();
-                               if ( $userTalkId !== false ) {
-                                       // Already sent an email to this person
-                                       $userCondition .= ' AND wl_user != ' . intval( $userTalkId );
-                               }
-                               $dbr = wfGetDB( DB_SLAVE );
-
-                               list( $user ) = $dbr->tableNamesN( 'user' );
-
-                               $res = $dbr->select( array( 'watchlist', 'user' ),
-                                       array( "$user.*" ),
-                                       array(
-                                               'wl_user=user_id',
-                                               'wl_title' => $title->getDBkey(),
-                                               'wl_namespace' => $title->getNamespace(),
-                                               $userCondition,
-                                               'wl_notificationtimestamp IS NULL',
-                                       ), __METHOD__ );
-                               $userArray = UserArray::newFromResult( $res );
-
+                               $userArray = UserArray::newFromIDs( $watchers );
                                foreach ( $userArray as $watchingUser ) {
                                        if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
                                                ( !$minorEdit || $watchingUser->getOption('enotifminoredits') ) &&
-                                               $watchingUser->isEmailConfirmed() )
+                                               $watchingUser->isEmailConfirmed() &&
+                                               $watchingUser->getID() != $userTalkId )
                                        {
                                                $this->compose( $watchingUser );
                                        }
@@ -402,28 +418,8 @@ class EmailNotification {
                }
 
                $this->sendMails();
-
-               $latestTimestamp = Revision::getTimestampFromId( $title, $title->getLatestRevID() );
-               // Do not update watchlists if something else already did.
-               if ( $timestamp >= $latestTimestamp && ($wgShowUpdatedMarker || $wgEnotifWatchlist) ) {
-                       # Mark the changed watch-listed page with a timestamp, so that the page is
-                       # listed with an "updated since your last visit" icon in the watch list. Do
-                       # not do this to users for their own edits.
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->update( 'watchlist',
-                               array( /* SET */
-                                       'wl_notificationtimestamp' => $dbw->timestamp($timestamp)
-                               ), array( /* WHERE */
-                                       'wl_title' => $title->getDBkey(),
-                                       'wl_namespace' => $title->getNamespace(),
-                                       'wl_notificationtimestamp IS NULL',
-                                       'wl_user != ' . $editor->getID()
-                               ), __METHOD__
-                       );
-               }
-
                wfProfileOut( __METHOD__ );
-       } # function NotifyOnChange
+       }
 
        /**
         * @private
@@ -563,7 +559,7 @@ class EmailNotification {
         * @private
         */
        function sendPersonalised( $watchingUser ) {
-               global $wgLang, $wgEnotifUseRealName;
+               global $wgContLang, $wgEnotifUseRealName;
                // From the PHP manual:
                //     Note:  The to parameter cannot be an address in the form of "Something <someone@example.com>".
                //     The mail command will not parse this properly while talking with the MTA.
@@ -577,7 +573,7 @@ class EmailNotification {
                # expressed in terms of individual local time of the notification
                # recipient, i.e. watching user
                $body = str_replace('$PAGEEDITDATE',
-                       $wgLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
+                       $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ),
                        $body);
 
                return UserMailer::send($to, $this->from, $this->subject, $body, $this->replyto);
@@ -588,7 +584,7 @@ class EmailNotification {
         * mailing.  Takes an array of MailAddress objects.
         */
        function sendImpersonal( $addresses ) {
-               global $wgLang;
+               global $wgContLang;
 
                if (empty($addresses))
                        return;
@@ -597,7 +593,7 @@ class EmailNotification {
                                array(  '$WATCHINGUSERNAME',
                                        '$PAGEEDITDATE'),
                                array(  wfMsgForContent('enotif_impersonal_salutation'),
-                                       $wgLang->timeanddate($this->timestamp, true, false, false)),
+                                       $wgContLang->timeanddate($this->timestamp, true, false, false)),
                                $this->body);
 
                return UserMailer::send($addresses, $this->from, $this->subject, $body, $this->replyto);