MediaWiki  master
EmailNotification Class Reference

This module processes the email notifications when the current page is changed. More...

Collaboration diagram for EmailNotification:

Public Member Functions

 actuallyNotifyOnPageChange (Authority $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus='changed')
 Immediate version of notifyOnPageChange(). More...
 
 getPageStatus ()
 Extensions that have hooks for UpdateUserMailerFormattedPageStatus (to provide additional pageStatus indicators) need a way to make sure that, when their hook is called in SendWatchlistemailNotification, they only handle notifications using their pageStatus indicator. More...
 
 notifyOnPageChange (Authority $editor, $title, $timestamp, $summary, $minorEdit, $oldid=false, $pageStatus='changed')
 Send emails corresponding to the user $editor editing the page $title. More...
 

Protected Attributes

string $body = ''
 
bool $composed_common = false
 
User $editor
 
MailAddress null $from
 
MailAddress[] $mailTargets = []
 
bool null $minorEdit
 
int null bool $oldid
 
string $pageStatus = ''
 
MailAddress null $replyto
 
string $subject = ''
 
string $summary = ''
 
string null $timestamp
 
Title $title
 

Private Member Functions

 canSendUserTalkEmail (UserIdentity $editor, $title, $minorEdit)
 
 compose (UserEmailContact $user, $source, MessageCache $messageCache)
 Compose a mail to a given user and either queue it for sending, or send it now, depending on settings. More...
 
 composeCommonMailtext (MessageCache $messageCache)
 Generate the generic "this page has been changed" e-mail text. More...
 
 sendImpersonal ( $addresses)
 Same as sendPersonalised but does impersonal mail suitable for bulk mailing. More...
 
 sendMails ()
 Send any queued mails. More...
 
 sendPersonalised (UserEmailContact $watchingUser, $source)
 Does the per-user customizations to a notification e-mail (name, timestamp in proper timezone, etc) and sends it out. More...
 

Private Attributes

const ALL_CHANGES = 'all_changes'
 Notification because user is notified for all changes. More...
 
const USER_TALK = 'user_talk'
 Notification is due to user's user talk being edited. More...
 
const WATCHLIST = 'watchlist'
 Notification is due to a watchlisted page being edited. More...
 

Detailed Description

This module processes the email notifications when the current page is changed.

It looks up the table watchlist to find out which users are watching that page.

The current implementation sends independent emails to each watching user for the following reason:

  • Each watching user will be notified about the page edit time expressed in his/her local time (UTC is shown additionally). To achieve this, we need to find the individual timeoffset of each watching user from the preferences..

Suggested improvement to slack down the number of sent emails: We could think of sending out bulk mails (bcc:user1,user2...) for all these users having the same timeoffset in their preferences.

Visit the documentation pages under https://www.mediawiki.org/wiki/Help:Watching_pages

TODO use UserOptionsLookup and other services, consider converting this to a service

Definition at line 53 of file EmailNotification.php.

Member Function Documentation

◆ actuallyNotifyOnPageChange()

EmailNotification::actuallyNotifyOnPageChange ( Authority  $editor,
  $title,
  $timestamp,
  $summary,
  $minorEdit,
  $oldid,
  $watchers,
  $pageStatus = 'changed' 
)

Immediate version of notifyOnPageChange().

Send emails corresponding to the user $editor editing the page $title.

Note
Do not call directly. Use notifyOnPageChange so that wl_notificationtimestamp is updated.
Parameters
Authority$editor
Title$title
string$timestampEdit timestamp
string$summaryEdit summary
bool$minorEdit
int$oldidRevision ID
array$watchersArray of user IDs
string$pageStatus
Exceptions
MWException

Definition at line 218 of file EmailNotification.php.

References $editor, $minorEdit, $oldid, $pageStatus, $summary, $timestamp, $title, compose(), Title\getNamespace(), Title\getText(), User\getUser(), User\isAllowed(), UserArray\newFromIDs(), User\newFromName(), NS_USER_TALK, Hooks\runner(), and sendMails().

◆ canSendUserTalkEmail()

EmailNotification::canSendUserTalkEmail ( UserIdentity  $editor,
  $title,
  $minorEdit 
)
private
Parameters
UserIdentity$editor
Title$title
bool$minorEdit
Returns
bool

Definition at line 309 of file EmailNotification.php.

References $editor, $minorEdit, $title, User\getId(), Title\getNamespace(), Title\getText(), User\newFromName(), NS_USER_TALK, Hooks\runner(), and wfDebug().

Referenced by notifyOnPageChange().

◆ compose()

EmailNotification::compose ( UserEmailContact  $user,
  $source,
MessageCache  $messageCache 
)
private

Compose a mail to a given user and either queue it for sending, or send it now, depending on settings.

Call sendMails() to send any mails that were queued.

Parameters
UserEmailContact$user
string$source
MessageCache$messageCache

Definition at line 472 of file EmailNotification.php.

References $source, composeCommonMailtext(), MailAddress\newFromUser(), and sendPersonalised().

Referenced by actuallyNotifyOnPageChange().

◆ composeCommonMailtext()

EmailNotification::composeCommonMailtext ( MessageCache  $messageCache)
private

Generate the generic "this page has been changed" e-mail text.

Parameters
MessageCache$messageCache

Definition at line 348 of file EmailNotification.php.

References $body, $keys, $oldid, $summary, SpecialPage\getSafeTitleFor(), Skin\makeInternalOrExternalUrl(), MailAddress\newFromUser(), MessageCache\transform(), wfExpandUrl(), and wfMessage().

Referenced by compose().

◆ getPageStatus()

EmailNotification::getPageStatus ( )

Extensions that have hooks for UpdateUserMailerFormattedPageStatus (to provide additional pageStatus indicators) need a way to make sure that, when their hook is called in SendWatchlistemailNotification, they only handle notifications using their pageStatus indicator.

Since
1.33
Returns
string

Definition at line 117 of file EmailNotification.php.

References $pageStatus.

◆ notifyOnPageChange()

EmailNotification::notifyOnPageChange ( Authority  $editor,
  $title,
  $timestamp,
  $summary,
  $minorEdit,
  $oldid = false,
  $pageStatus = 'changed' 
)

Send emails corresponding to the user $editor editing the page $title.

May be deferred via the job queue.

Parameters
Authority$editor
Title$title
string$timestamp
string$summary
bool$minorEdit
bool$oldid(default: false)
string$pageStatus(default: 'changed')
Returns
bool Whether an email job was created or not.
Since
1.35 returns a boolean indicating whether an email job was created.

Definition at line 136 of file EmailNotification.php.

References $editor, $minorEdit, $oldid, $pageStatus, $summary, $timestamp, $title, canSendUserTalkEmail(), Title\getNamespace(), MediaWiki\Permissions\Authority\getUser(), User\getUser(), User\isAllowed(), NS_USER_TALK, and JobQueueGroup\singleton().

◆ sendImpersonal()

EmailNotification::sendImpersonal (   $addresses)
private

Same as sendPersonalised but does impersonal mail suitable for bulk mailing.

Takes an array of MailAddress objects.

Parameters
MailAddress[]$addresses
Returns
Status|null

Definition at line 550 of file EmailNotification.php.

References $body, UserMailer\send(), and wfMessage().

Referenced by sendMails().

◆ sendMails()

EmailNotification::sendMails ( )
private

Send any queued mails.

Definition at line 487 of file EmailNotification.php.

References sendImpersonal().

Referenced by actuallyNotifyOnPageChange().

◆ sendPersonalised()

EmailNotification::sendPersonalised ( UserEmailContact  $watchingUser,
  $source 
)
private

Does the per-user customizations to a notification e-mail (name, timestamp in proper timezone, etc) and sends it out.

Returns Status if email was sent successfully or not (Status::newGood() or Status::newFatal() respectively).

Parameters
UserEmailContact$watchingUser
string$source
Returns
Status

Definition at line 503 of file EmailNotification.php.

References $body, $source, MediaWiki\Mail\UserEmailContact\getRealName(), MediaWiki\Mail\UserEmailContact\getUser(), MailAddress\newFromUser(), and UserMailer\send().

Referenced by compose().

Member Data Documentation

◆ $body

string EmailNotification::$body = ''
protected

Definition at line 72 of file EmailNotification.php.

Referenced by composeCommonMailtext(), sendImpersonal(), and sendPersonalised().

◆ $composed_common

bool EmailNotification::$composed_common = false
protected

Definition at line 93 of file EmailNotification.php.

◆ $editor

User EmailNotification::$editor
protected

◆ $from

MailAddress null EmailNotification::$from
protected

Definition at line 78 of file EmailNotification.php.

◆ $mailTargets

MailAddress [] EmailNotification::$mailTargets = []
protected

Definition at line 99 of file EmailNotification.php.

◆ $minorEdit

bool null EmailNotification::$minorEdit
protected

◆ $oldid

int null bool EmailNotification::$oldid
protected

◆ $pageStatus

string EmailNotification::$pageStatus = ''
protected

◆ $replyto

MailAddress null EmailNotification::$replyto
protected

Definition at line 75 of file EmailNotification.php.

◆ $subject

string EmailNotification::$subject = ''
protected

Definition at line 69 of file EmailNotification.php.

◆ $summary

string EmailNotification::$summary = ''
protected

◆ $timestamp

string null EmailNotification::$timestamp
protected

Definition at line 81 of file EmailNotification.php.

Referenced by actuallyNotifyOnPageChange(), and notifyOnPageChange().

◆ $title

Title EmailNotification::$title
protected

◆ ALL_CHANGES

const EmailNotification::ALL_CHANGES = 'all_changes'
private

Notification because user is notified for all changes.

Definition at line 66 of file EmailNotification.php.

◆ USER_TALK

const EmailNotification::USER_TALK = 'user_talk'
private

Notification is due to user's user talk being edited.

Definition at line 58 of file EmailNotification.php.

◆ WATCHLIST

const EmailNotification::WATCHLIST = 'watchlist'
private

Notification is due to a watchlisted page being edited.

Definition at line 62 of file EmailNotification.php.


The documentation for this class was generated from the following file: