X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUserMailer.php;h=d7dbff9b26d3c13b9524e7d456e9b72733d13468;hb=3d6c4a9b2126876c87ebc3f041a68e097a3ecca4;hp=831f53b8d43bc69a3aa9b0b17fa434f6f891af23;hpb=9d67504d76d97ca92cfc5d20d94b1f1aa0b28784;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/UserMailer.php b/includes/UserMailer.php index 831f53b8d4..d7dbff9b26 100644 --- a/includes/UserMailer.php +++ b/includes/UserMailer.php @@ -188,11 +188,12 @@ class UserMailer { $headers .= "{$endl}Reply-To: " . $replyto->toString(); } + wfDebug( "Sending mail via internal mail() function\n" ); + $wgErrorString = ''; $html_errors = ini_get( 'html_errors' ); ini_set( 'html_errors', '0' ); set_error_handler( array( 'UserMailer', 'errorHandler' ) ); - wfDebug( "Sending mail via internal mail() function\n" ); if (function_exists('mail')) { if (is_array($to)) { @@ -263,9 +264,9 @@ class UserMailer { * */ class EmailNotification { - private $to, $subject, $body, $replyto, $from; - private $user, $title, $timestamp, $summary, $minorEdit, $oldid, $composed_common, $editor; - private $mailTargets = array(); + protected $to, $subject, $body, $replyto, $from; + protected $user, $title, $timestamp, $summary, $minorEdit, $oldid, $composed_common, $editor; + protected $mailTargets = array(); /** * Send emails corresponding to the user $editor editing the page $title. @@ -280,12 +281,45 @@ class EmailNotification { * @param $minorEdit * @param $oldid (default: false) */ - function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) { - global $wgEnotifUseJobQ; + function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $deleted = false ) { + 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,16 +327,19 @@ class EmailNotification { "timestamp" => $timestamp, "summary" => $summary, "minorEdit" => $minorEdit, - "oldid" => $oldid); + "oldid" => $oldid, + "watchers" => $watchers, + "deleted" => $deleted + ); $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, $deleted ); } } - /* + /** * Immediate version of notifyOnPageChange(). * * Send emails corresponding to the user $editor editing the page $title. @@ -310,16 +347,17 @@ 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 + * @param $deleted boolean If page was deleted */ - function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid=false) { - + function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $deleted ) { # we use $wgPasswordSender as sender's address global $wgEnotifWatchlist; - global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker; + global $wgEnotifMinorEdits, $wgEnotifUserTalk; global $wgEnotifImpersonal; wfProfileIn( __METHOD__ ); @@ -338,6 +376,7 @@ class EmailNotification { $this->minorEdit = $minorEdit; $this->oldid = $oldid; $this->editor = $editor; + $this->deleted = $deleted; $this->composed_common = false; $userTalkId = false; @@ -364,30 +403,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 +423,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 @@ -453,6 +454,10 @@ class EmailNotification { $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastvisited', $difflink ); $keys['$OLDID'] = $this->oldid; $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' ); + } else if( $this->deleted ) { + $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_deletedpagetext' ); + $keys['$OLDID'] = ''; + $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'deleted' ); } else { $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' ); # clear $OLDID placeholder in the message template @@ -471,7 +476,8 @@ class EmailNotification { $body = strtr( $body, $keys ); $pagetitle = $this->title->getPrefixedText(); $keys['$PAGETITLE'] = $pagetitle; - $keys['$PAGETITLE_URL'] = $this->title->getFullUrl(); + $keys['$REVINFO'] = $this->deleted ? '' : + wfMsgForContent( 'enotif_rev_info', $this->title->getFullUrl() ); $keys['$PAGEMINOREDIT'] = $medit; $keys['$PAGESUMMARY'] = $summary; @@ -563,7 +569,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 ". // The mail command will not parse this properly while talking with the MTA. @@ -576,8 +582,13 @@ class EmailNotification { # $PAGEEDITDATE is the time and date of the page change # 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 ), + $body = str_replace( + array( '$PAGEEDITDATEANDTIME', + '$PAGEEDITDATE', + '$PAGEEDITTIME' ), + array( $wgContLang->timeanddate( $this->timestamp, true, false, $timecorrection ), + $wgContLang->date( $this->timestamp, true, false, $timecorrection ), + $wgContLang->time( $this->timestamp, true, false, $timecorrection ) ), $body); return UserMailer::send($to, $this->from, $this->subject, $body, $this->replyto); @@ -588,7 +599,7 @@ class EmailNotification { * mailing. Takes an array of MailAddress objects. */ function sendImpersonal( $addresses ) { - global $wgLang; + global $wgContLang; if (empty($addresses)) return; @@ -597,7 +608,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);