150 $mwServices = MediaWikiServices::getInstance();
151 $config = $mwServices->getMainConfig();
155 if ( $config->get( MainConfigNames::EnotifWatchlist ) ||
156 $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
157 $watchers = $mwServices->getWatchedItemStore()->updateNotificationTimestamp(
169 if ( $watchers === [] &&
170 !count( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) ) ) {
174 ( $config->get( MainConfigNames::EnotifMinorEdits ) &&
178 if ( $config->get( MainConfigNames::EnotifUserTalk )
197 'watchers' => $watchers,
230 $pageStatus =
'changed'
232 # we use $wgPasswordSender as sender's address
234 $mwServices = MediaWikiServices::getInstance();
235 $messageCache = $mwServices->getMessageCache();
236 $config = $mwServices->getMainConfig();
238 # The following code is only run, if several conditions are met:
239 # 1. EmailNotification for pages (other than user_talk pages) must be enabled
240 # 2. minor edits (changes) are only regarded if the global flag indicates so
245 $this->timestamp = $timestamp;
246 $this->summary = $summary;
247 $this->minorEdit = $minorEdit;
248 $this->oldid = $oldid;
249 $this->editor = MediaWikiServices::getInstance()->getUserFactory()->newFromAuthority( $editor );
250 $this->composed_common =
false;
251 $this->pageStatus = $pageStatus;
253 $formattedPageStatus = [
'deleted',
'created',
'moved',
'restored',
'changed' ];
255 Hooks::runner()->onUpdateUserMailerFormattedPageStatus( $formattedPageStatus );
256 if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
257 throw new MWException(
'Not a valid page status!' );
263 ( $config->get( MainConfigNames::EnotifMinorEdits ) &&
264 !$editor->
isAllowed(
'nominornewtalk' ) )
266 if ( $config->get( MainConfigNames::EnotifUserTalk )
268 && $this->canSendUserTalkEmail( $editor->
getUser(),
$title, $minorEdit )
271 $this->compose( $targetUser, self::USER_TALK, $messageCache );
272 $userTalkId = $targetUser->getId();
275 if ( $config->get( MainConfigNames::EnotifWatchlist ) ) {
279 foreach ( $userArray as $watchingUser ) {
280 if ( $watchingUser->getOption(
'enotifwatchlistpages' )
281 && ( !$minorEdit || $watchingUser->getOption(
'enotifminoredits' ) )
282 && $watchingUser->isEmailConfirmed()
283 && $watchingUser->getId() != $userTalkId
284 && !in_array( $watchingUser->getName(),
285 $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) )
288 && !( $config->get( MainConfigNames::BlockDisablesLogin ) &&
289 $watchingUser->getBlock() )
292 $this->compose( $watchingUser, self::WATCHLIST, $messageCache );
298 foreach ( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) as $name ) {
299 if ( $editor->
getUser()->getName() == $name ) {
304 $this->compose( $user, self::ALL_CHANGES, $messageCache );
317 $config = MediaWikiServices::getInstance()->getMainConfig();
320 if ( !$config->get( MainConfigNames::EnotifUserTalk ) || !$isUserTalkPage ) {
326 if ( !$targetUser || $targetUser->isAnon() ) {
327 wfDebug( __METHOD__ .
": user talk page edited, but user does not exist" );
328 } elseif ( $targetUser->getId() == $editor->
getId() ) {
329 wfDebug( __METHOD__ .
": user edited their own talk page, no notification sent" );
330 } elseif ( $config->get( MainConfigNames::BlockDisablesLogin ) &&
331 $targetUser->getBlock() ) {
334 wfDebug( __METHOD__ .
": talk page owner is blocked and cannot login, no notification sent" );
335 } elseif ( $targetUser->getOption(
'enotifusertalkpages' )
336 && ( !$minorEdit || $targetUser->getOption(
'enotifminoredits' ) )
338 if ( !$targetUser->isEmailConfirmed() ) {
339 wfDebug( __METHOD__ .
": talk page owner doesn't have validated email" );
341 wfDebug( __METHOD__ .
": talk page update notification is aborted for this user" );
343 wfDebug( __METHOD__ .
": sending talk page update notification" );
347 wfDebug( __METHOD__ .
": talk page owner doesn't want notifications" );
357 $config = MediaWikiServices::getInstance()->getMainConfig();
359 $this->composed_common =
true;
361 # You as the WikiAdmin and Sysops can make use of plenty of
362 # named variables when composing your notification emails while
363 # simply editing the Meta pages
366 $postTransformKeys = [];
367 $pageTitleUrl = $this->title->getCanonicalURL();
368 $pageTitle = $this->title->getPrefixedText();
370 if ( $this->oldid ) {
374 $this->title->getCanonicalURL( [
'diff' =>
'next',
'oldid' => $this->oldid ] )
375 )->inContentLanguage()->text();
377 if ( !$config->get( MainConfigNames::EnotifImpersonal ) ) {
381 'enotif_lastvisited',
382 $this->title->getCanonicalURL( [
'diff' =>
'0',
'oldid' => $this->oldid ] )
383 )->inContentLanguage()->text();
385 $keys[
'$OLDID'] = $this->oldid;
387 $keys[
'$CHANGEDORCREATED'] =
wfMessage(
'changed' )->inContentLanguage()->text();
389 # clear $OLDID placeholder in the message template
390 $keys[
'$OLDID'] =
'';
391 $keys[
'$NEWPAGE'] =
'';
393 $keys[
'$CHANGEDORCREATED'] =
wfMessage(
'created' )->inContentLanguage()->text();
396 $keys[
'$PAGETITLE'] = $this->title->getPrefixedText();
397 $keys[
'$PAGETITLE_URL'] = $this->title->getCanonicalURL();
398 $keys[
'$PAGEMINOREDIT'] = $this->minorEdit ?
399 "\n\n" .
wfMessage(
'enotif_minoredit' )->inContentLanguage()->text() :
401 $keys[
'$UNWATCHURL'] = $this->title->getCanonicalURL(
'action=unwatch' );
403 if ( !$this->editor->isRegistered() ) {
404 # real anon (user:xxx.xxx.xxx.xxx)
405 $keys[
'$PAGEEDITOR'] =
wfMessage(
'enotif_anon_editor', $this->editor->getName() )
406 ->inContentLanguage()->text();
407 $keys[
'$PAGEEDITOR_EMAIL'] =
wfMessage(
'noemailtitle' )->inContentLanguage()->text();
410 $keys[
'$PAGEEDITOR'] = $config->get( MainConfigNames::EnotifUseRealName ) &&
411 $this->editor->getRealName() !==
''
412 ? $this->editor->getRealName() : $this->editor->getName();
414 $keys[
'$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL();
417 $keys[
'$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL();
422 # Replace this after transforming the message, T37019
423 $postTransformKeys[
'$PAGESUMMARY'] = $this->summary ==
'' ?
' - ' : $this->summary;
430 $this->subject =
wfMessage(
'enotif_subject_' . $this->pageStatus )->inContentLanguage()
431 ->params( $pageTitle,
$keys[
'$PAGEEDITOR'] )->text();
436 $keys[
'$PAGEINTRO'] =
wfMessage(
'enotif_body_intro_' . $this->pageStatus )
437 ->inContentLanguage()
438 ->params( $pageTitle,
$keys[
'$PAGEEDITOR'], $pageTitleUrl )
441 $body =
wfMessage(
'enotif_body' )->inContentLanguage()->plain();
442 $body = strtr( $body,
$keys );
443 $body = $messageCache->
transform( $body,
false,
null, $this->title );
444 $this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 );
446 # Reveal the page editor's address as REPLY-TO address only if
447 # the user has not opted-out and the option is enabled at the
448 # global configuration level.
450 $config->get( MainConfigNames::PasswordSender ),
451 wfMessage(
'emailsender' )->inContentLanguage()->text()
453 if ( $config->get( MainConfigNames::EnotifRevealEditorAddress )
454 && ( $this->editor->getEmail() !=
'' )
455 && $this->editor->getOption(
'enotifrevealaddr' )
458 if ( $config->get( MainConfigNames::EnotifFromEditor ) ) {
459 $this->from = $editorAddress;
461 $this->from = $adminAddress;
462 $this->replyto = $editorAddress;
465 $this->from = $adminAddress;
467 $config->get( MainConfigNames::NoReplyAddress )
482 if ( !$this->composed_common ) {
483 $this->composeCommonMailtext( $messageCache );
486 if ( MediaWikiServices::getInstance()->getMainConfig()
487 ->
get( MainConfigNames::EnotifImpersonal ) ) {
490 $this->sendPersonalised( $user,
$source );
498 if ( MediaWikiServices::getInstance()->getMainConfig()
499 ->
get( MainConfigNames::EnotifImpersonal ) ) {
500 $this->sendImpersonal( $this->mailTargets );
521 # $PAGEEDITDATE is the time and date of the page change
522 # expressed in terms of individual local time of the notification
523 # recipient, i.e. watching user
524 $mwServices = MediaWikiServices::getInstance();
525 $contLang = $mwServices->getContentLanguage();
526 $watchingUserName = (
527 $mwServices->getMainConfig()->get( MainConfigNames::EnotifUseRealName ) &&
538 $contLang->userDate( $this->timestamp, $watchingUser->
getUser() ),
539 $contLang->userTime( $this->timestamp, $watchingUser->
getUser() )
545 if (
$source === self::WATCHLIST ) {
546 $headers[
'List-Help'] =
'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Watchlist';
550 'replyTo' => $this->replyto,
551 'headers' => $headers,
562 if ( empty( $addresses ) ) {
566 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
574 wfMessage(
'enotif_impersonal_salutation' )->inContentLanguage()->text(),
575 $contLang->date( $this->timestamp,
false,
false ),
576 $contLang->time( $this->timestamp,
false,
false )
582 'replyTo' => $this->replyto,
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
This module processes the email notifications when the current page is changed.
sendPersonalised(UserEmailContact $watchingUser, $source)
Does the per-user customizations to a notification e-mail (name, timestamp in proper timezone,...
sendImpersonal( $addresses)
Same as sendPersonalised but does impersonal mail suitable for bulk mailing.
MailAddress null $replyto
const ALL_CHANGES
Notification because user is notified for all changes.
sendMails()
Send any queued mails.
canSendUserTalkEmail(UserIdentity $editor, $title, $minorEdit)
actuallyNotifyOnPageChange(Authority $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus='changed')
Immediate version of notifyOnPageChange().
const WATCHLIST
Notification is due to a watchlisted page being edited.
notifyOnPageChange(Authority $editor, $title, $timestamp, $summary, $minorEdit, $oldid=false, $pageStatus='changed')
Send emails corresponding to the user $editor editing the page $title.
const USER_TALK
Notification is due to user's user talk being edited.
composeCommonMailtext(MessageCache $messageCache)
Generate the generic "this page has been changed" e-mail text.
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...
getPageStatus()
Extensions that have hooks for UpdateUserMailerFormattedPageStatus (to provide additional pageStatus ...
MailAddress[] $mailTargets
Job for email notification mails.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Stores a single person's name and email address.
static newFromUser(UserEmailContact $user)
Create a new MailAddress object for the given user.
A class containing constants representing the names of configuration variables.
Cache of messages that are defined by MediaWiki namespace pages or by hooks.
transform( $message, $interface=false, $language=null, PageReference $page=null)
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage.
getNamespace()
Get the namespace index, i.e.
static send( $to, $from, $subject, $body, $options=[])
This function will perform a direct (authenticated) login to a SMTP Server to use for mail relaying i...
static newFromName( $name, $validate='valid')
isAllowed(string $permission)
Checks whether this authority has the given permission in general.