function notifyOnPageChangeOrNewpage(&$title, $timestamp, $summary, $minorEdit, $oldid = false) { # we use $wgEmergencyContact as sender's address global $wgUser, $wgLang, $wgEmergencyContact; global $wgEnotifWatchlist, $wgEnotifMinorEdits; global $wgEnotifUserTalk; global $wgEnotifNewPages; global $wgEnotifForAnyChange; global $wgEnotifRevealEditorAddress; global $wgEnotifFromEditor; global $wgShowUpdatedMarker; $initialised = false; $fname = 'UserMailer::notifyOnPageChangeOrNewpage'; wfProfileIn($fname); # 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 $isUserTalkPage = $title->getNamespace() == NS_USER_TALK; $enotifusertalkpage = $isUserTalkPage && $wgEnotifUserTalk; $enotifwatchlistpage = !$isUserTalkPage && $wgEnotifWatchlist; if (($enotifusertalkpage || $enotifwatchlistpage) && (!$minorEdit || $wgEnotifMinorEdits)) { $dbr =& wfGetDB(DB_MASTER); if ($wgEnotifForAnyChange) { $res = $dbr->select('watchlist', array('wl_user'), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user <> ' . $wgUser->getID()), $fname); } else { $res = $dbr->select('watchlist', array('wl_user'), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user <> ' . $wgUser->getID(), $dbr->wl_notificationtimestampIsNULL()), $fname); } # if anyone is watching ... set up the email message text which is # common for all receipients ... if ($dbr->numRows($res) > 0) { $this->user &= $wgUser; $this->title =& $title; $this->timestamp = $timestamp; $this->summary = $summary; $this->minorEdit = $minorEdit; $this->oldid = $oldid; $mail = $this->composeCommonMailtext(); $watchingUser = new User(); $initialised = true; # ... 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')) && (!$minorEdit || $wgEnotifMinorEdits && $watchingUser->getOption('enotifminoredits')) && $watchingUser->canReceiveEmail()) { # ... 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 # see remark below regard the Tim-Starling improvement # 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 # save also the last seen revision of that page for (lvr) links $dbw =& wfGetDB(DB_MASTER); $succes = $dbw->update('watchlist', array('wl_notificationtimestamp' => wfTimestamp(TS_MW, $timestamp), 'wl_lastvisitedrevision' => $oldid), array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user' => $wuser->wl_user), $fname); } # for every watching user } # if anyone is watching } # if $wgEnotifWatchlist = true if ($wgEnotifNewPages && isset($oldid) && $oldid == 0) { $dbr =& wfGetDB(DB_MASTER); $res = $dbr->select('user', 'user_id', 'user_enotif_newpages=1 AND user_id<>' . $wgUser->getID(), $fname); for ($i = 1; $i <= $dbr->numRows($res); $i++) { if (!$initialised) { # initialise if not yet done $this->user &= $wgUser; $this->title =& $title; $this->timestamp = $timestamp; $this->summary = $summary; $this->minorEdit = $minorEdit; $this->oldid = $oldid; $mail = $this->composeCommonMailtext(); $watchingUser = new User(); } $wuser = $dbr->fetchObject($res); $watchingUser->setID($wuser->user_id); # We must not send new page notification to users, who already received an enotif # during the first loop when notifs for watched pages were sent $enotiftimestamp = $dbr->selectField('watchlist', 'wl_notificationtimestamp', array('wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace(), 'wl_user' => $wuser->user_id), $fname); # two possibilities exist, where an enotif is sent now # a) page is not watched (query failed) # b) page is watched and not yet notified (should not happen here) if (!$enotiftimestamp || $enotiftimestamp == wfTimestampOrNull()) { $this->composeAndSendPersonalisedMail($watchingUser); } } } # notifications for a new page # This is the Tim Starling improvement: # he updates all pages in one go, what is correct as suchn and should be the preferred solution. # # However, it needs that the timestamp is no longer determining where the updated marker is shown # on revisions in recent changes lists (which is currently still time-based, based on a comparison with the # exact notification time. # # This is very efficient and should be reactivated at the soonest. # <FIXME> Tom 26.06.2005 # # if ( $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, ... # $dbw =& wfGetDB( DB_MASTER ); # $success = $dbw->update( 'watchlist', # array( /* SET */ # 'wl_notificationtimestamp' => $timestamp # ), array( /* WHERE */ # 'wl_title' => $title->getDBkey(), # 'wl_namespace' => $title->getNamespace(), # ), 'UserMailer::NotifyOnChange' # ); # } }