-
- $isUserTalkPage = ($currentNs == NS_USER_TALK);
- $enotifusertalkpage = ($isUserTalkPage && $wgEmailNotificationForUserTalkPages);
- $enotifwatchlistpage = (!$isUserTalkPage && $wgEmailNotificationForWatchlistPages);
-
- if ( ($enotifusertalkpage || $enotifwatchlistpage)
- && (!$currentMinorEdit || $wgEmailNotificationForMinorEdits) ) {
-
- $dbr =& wfGetDB( DB_MASTER );
- extract( $dbr->tableNames( 'watchlist' ) );
- $sql = "SELECT wl_user FROM $watchlist
- WHERE wl_title='" . $dbr->strencode($currentPage)."' AND wl_namespace = " . $currentNs .
- " AND wl_user <>" . $currentUser . " AND wl_notificationtimestamp <= 1";
- $res = $dbr->query( $sql,'UserMailer::NotifyOnChange');
-
- # if anyone is watching ... set up the email message text which is
- # common for all receipients ...
- if ( $dbr->numRows( $res ) > 0 ) {
-
- # This is a switch for one beep on the server when sending notification mails
- $beeped = false;
-
- $article->mTimestamp = $timestamp;
- $article->mSummary = $currentSummary;
- $article->mMinorEdit = $currentMinorEdit;
- $article->mNamespace = $currentNs;
- $article->mTitle = $currentPage;
- $article->mOldid = $oldid;
-
- $mail = $this->composeCommonMailtext( $wgUser, $article );
- $watchingUser = new User();
-
- # ... now do for all watching users ... if the options fit
- for ($i = 1; $i <= $dbr->numRows( $res ); $i++) {
-
- $wuser = $dbr->fetchObject( $res );
- $watchingUser->setID($wuser->wl_user);
- if ( ( $enotifwatchlistpage && $watchingUser->getOption('enotifwatchlistpages') ) ||
- ( $enotifusertalkpage && $watchingUser->getOption('enotifusertalkpages') )
- && (!$currentMinorEdit || ($wgEmailNotificationForMinorEdits && $watchingUser->getOption('enotifminoredits') ) )
- && ($watchingUser->isEmailConfirmed() ) ) {
- # ... adjust remaining text and page edit time placeholders
- # which needs to be personalized for each user
- $sent = $this->composeAndSendPersonalisedMail( $watchingUser, $mail, $article );
- /* the beep here beeps once when a watched-listed page is changed */
- if ($sent && !$beeped && ($wgEmailNotificationSystembeep != '') ) {
- $last_line = system($wgEmailNotificationSystembeep);
- $beeped=true;
- }
- } # if the watching user has an email address in the preferences
- # 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, ...
- # ... no matter, if the watching user has or has not indicated an email address in his/her preferences.
- # We memorise the event of sending out a notification and use this as a flag to suppress further mails for changes on the same page for that watching user
- $dbw =& wfGetDB( DB_MASTER );
- $succes = $dbw->update( 'watchlist',
- array( /* SET */
- 'wl_notificationtimestamp' => $article->mTimestamp
- ), array( /* WHERE */
- 'wl_title' => $currentPage,
- 'wl_namespace' => $currentNs,
- 'wl_user' => $wuser->wl_user
- ), 'UserMailer::NotifyOnChange'
- );
- } # for every watching user
+
+ $isUserTalkPage = ($title->getNamespace() == NS_USER_TALK);
+ $enotifusertalkpage = ($isUserTalkPage && $wgEnotifUserTalk);
+ $enotifwatchlistpage = $wgEnotifWatchlist;
+
+ if ( (!$minorEdit || $wgEnotifMinorEdits) ) {
+ if( $wgEnotifWatchlist ) {
+ // Send updates to watchers other than the current editor
+ $userCondition = 'wl_user <> ' . intval( $wgUser->getId() );
+ } elseif( $wgEnotifUserTalk && $title->getNamespace() == NS_USER_TALK ) {
+ $targetUser = User::newFromName( $title->getText() );
+ if( is_null( $targetUser ) ) {
+ wfDebug( "$fname: user-talk-only mode; no such user\n" );
+ $userCondition = false;
+ } elseif( $targetUser->getId() == $wgUser->getId() ) {
+ wfDebug( "$fname: user-talk-only mode; editor is target user\n" );
+ $userCondition = false;
+ } else {
+ // Don't notify anyone other than the owner of the talk page
+ $userCondition = 'wl_user = ' . intval( $targetUser->getId() );
+ }
+ } else {
+ // Notifications disabled
+ $userCondition = false;
+ }
+ if( $userCondition ) {
+ $dbr =& wfGetDB( DB_MASTER );
+ extract( $dbr->tableNames( 'watchlist' ) );
+
+ $res = $dbr->select( 'watchlist', array( 'wl_user' ),
+ array(
+ 'wl_title' => $title->getDBkey(),
+ 'wl_namespace' => $title->getNamespace(),
+ $userCondition,
+ 'wl_notificationtimestamp IS NULL',
+ ), $fname );
+
+ # if anyone is watching ... set up the email message text which is
+ # common for all receipients ...
+ if ( $dbr->numRows( $res ) > 0 ) {
+ $this->title =& $title;
+ $this->timestamp = $timestamp;
+ $this->summary = $summary;
+ $this->minorEdit = $minorEdit;
+ $this->oldid = $oldid;
+
+ $this->composeCommonMailtext();
+ $watchingUser = new User();
+
+ # ... now do for all watching users ... if the options fit
+ for ($i = 1; $i <= $dbr->numRows( $res ); $i++) {
+
+ $wuser = $dbr->fetchObject( $res );
+ $watchingUser->setID($wuser->wl_user);
+
+ if ( ( $enotifwatchlistpage && $watchingUser->getOption('enotifwatchlistpages') ) ||
+ ( $enotifusertalkpage
+ && $watchingUser->getOption('enotifusertalkpages')
+ && $title->equals( $watchingUser->getTalkPage() ) )
+ && (!$minorEdit || ($wgEnotifMinorEdits && $watchingUser->getOption('enotifminoredits') ) )
+ && ($watchingUser->isEmailConfirmed() ) ) {
+ # ... adjust remaining text and page edit time placeholders
+ # which needs to be personalized for each user
+ $this->composeAndSendPersonalisedMail( $watchingUser );
+
+ } # if the watching user has an email address in the preferences
+ }
+ }