2004-02-28 07:08:13 +00:00
|
|
|
<?php
|
2005-01-27 18:19:16 +00:00
|
|
|
/**
|
2010-08-14 17:42:40 +00:00
|
|
|
* Classes used to send e-mails
|
|
|
|
|
*
|
2005-01-27 18:19:16 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-01-27 18:19:16 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2005-08-02 13:35:19 +00:00
|
|
|
*
|
2010-08-14 17:42:40 +00:00
|
|
|
* @file
|
2005-01-27 18:19:16 +00:00
|
|
|
* @author <brion@pobox.com>
|
|
|
|
|
* @author <mail@tgries.de>
|
2007-10-03 08:46:17 +00:00
|
|
|
* @author Tim Starling
|
2012-12-07 21:41:44 +00:00
|
|
|
* @author Luke Welling lwelling@wikimedia.org
|
2005-01-27 18:19:16 +00:00
|
|
|
*/
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2016-04-15 16:29:05 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2017-05-31 02:16:22 +00:00
|
|
|
* Visit the documentation pages under
|
|
|
|
|
* https://www.mediawiki.org/wiki/Help:Watching_pages
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2004-12-18 10:23:54 +00:00
|
|
|
class EmailNotification {
|
2015-07-07 18:44:25 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Notification is due to user's user talk being edited
|
|
|
|
|
*/
|
|
|
|
|
const USER_TALK = 'user_talk';
|
|
|
|
|
/**
|
|
|
|
|
* Notification is due to a watchlisted page being edited
|
|
|
|
|
*/
|
|
|
|
|
const WATCHLIST = 'watchlist';
|
|
|
|
|
/**
|
|
|
|
|
* Notification because user is notified for all changes
|
|
|
|
|
*/
|
|
|
|
|
const ALL_CHANGES = 'all_changes';
|
|
|
|
|
|
2012-01-06 20:54:24 +00:00
|
|
|
protected $subject, $body, $replyto, $from;
|
2012-05-18 21:01:12 +00:00
|
|
|
protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus;
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mailTargets = [];
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2011-10-26 03:44:47 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
2012-01-06 20:54:24 +00:00
|
|
|
protected $editor;
|
2011-10-26 03:44:47 +00:00
|
|
|
|
2017-09-06 00:42:21 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getPageStatus() {
|
|
|
|
|
return $this->pageStatus;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-03 08:46:17 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Send emails corresponding to the user $editor editing the page $title.
|
2007-10-03 08:46:17 +00:00
|
|
|
*
|
|
|
|
|
* May be deferred via the job queue.
|
|
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $editor
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param string $timestamp
|
|
|
|
|
* @param string $summary
|
|
|
|
|
* @param bool $minorEdit
|
|
|
|
|
* @param bool $oldid (default: false)
|
|
|
|
|
* @param string $pageStatus (default: 'changed')
|
2007-10-03 08:46:17 +00:00
|
|
|
*/
|
2014-05-11 15:34:14 +00:00
|
|
|
public function notifyOnPageChange( $editor, $title, $timestamp, $summary,
|
|
|
|
|
$minorEdit, $oldid = false, $pageStatus = 'changed'
|
|
|
|
|
) {
|
2016-01-22 04:14:44 +00:00
|
|
|
global $wgEnotifMinorEdits, $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-05-21 19:36:03 +00:00
|
|
|
if ( $title->getNamespace() < 0 ) {
|
2007-07-09 14:21:49 +00:00
|
|
|
return;
|
2011-05-21 19:36:03 +00:00
|
|
|
}
|
2007-07-09 14:21:49 +00:00
|
|
|
|
2014-09-09 21:10:01 +00:00
|
|
|
// update wl_notificationtimestamp for watchers
|
2016-02-05 12:14:13 +00:00
|
|
|
$config = RequestContext::getMain()->getConfig();
|
|
|
|
|
$watchers = [];
|
|
|
|
|
if ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) {
|
2016-04-15 16:29:05 +00:00
|
|
|
$watchers = MediaWikiServices::getInstance()->getWatchedItemStore()->updateNotificationTimestamp(
|
2016-02-05 12:14:13 +00:00
|
|
|
$editor,
|
|
|
|
|
$title,
|
|
|
|
|
$timestamp
|
|
|
|
|
);
|
|
|
|
|
}
|
2009-03-02 12:15:28 +00:00
|
|
|
|
2011-09-22 12:14:21 +00:00
|
|
|
$sendEmail = true;
|
2015-09-28 11:47:16 +00:00
|
|
|
// $watchers deals with $wgEnotifWatchlist.
|
2011-09-22 12:14:21 +00:00
|
|
|
// If nobody is watching the page, and there are no users notified on all changes
|
2015-07-09 00:29:39 +00:00
|
|
|
// don't bother creating a job/trying to send emails, unless it's a
|
|
|
|
|
// talk page with an applicable notification.
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $watchers === [] && !count( $wgUsersNotifiedOnAllChanges ) ) {
|
2011-09-22 12:14:21 +00:00
|
|
|
$sendEmail = false;
|
|
|
|
|
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
|
|
|
|
|
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
|
|
|
|
|
$isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
|
2014-05-11 15:34:14 +00:00
|
|
|
if ( $wgEnotifUserTalk
|
|
|
|
|
&& $isUserTalkPage
|
|
|
|
|
&& $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
|
|
|
|
|
) {
|
2011-09-22 12:14:21 +00:00
|
|
|
$sendEmail = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 00:03:29 +00:00
|
|
|
if ( $sendEmail ) {
|
|
|
|
|
JobQueueGroup::singleton()->lazyPush( new EnotifNotifyJob(
|
|
|
|
|
$title,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-01-30 00:03:29 +00:00
|
|
|
'editor' => $editor->getName(),
|
2016-03-19 00:08:06 +00:00
|
|
|
'editorID' => $editor->getId(),
|
2016-01-30 00:03:29 +00:00
|
|
|
'timestamp' => $timestamp,
|
|
|
|
|
'summary' => $summary,
|
|
|
|
|
'minorEdit' => $minorEdit,
|
|
|
|
|
'oldid' => $oldid,
|
|
|
|
|
'watchers' => $watchers,
|
|
|
|
|
'pageStatus' => $pageStatus
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2016-01-30 00:03:29 +00:00
|
|
|
) );
|
2011-09-22 12:14:21 +00:00
|
|
|
}
|
2007-05-11 16:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-21 19:36:03 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Immediate version of notifyOnPageChange().
|
2007-10-03 08:46:17 +00:00
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Send emails corresponding to the user $editor editing the page $title.
|
2007-10-03 08:46:17 +00:00
|
|
|
*
|
2015-05-12 19:00:46 +00:00
|
|
|
* @note Do not call directly. Use notifyOnPageChange so that wl_notificationtimestamp is updated.
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $editor
|
|
|
|
|
* @param Title $title
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $timestamp Edit timestamp
|
|
|
|
|
* @param string $summary Edit summary
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param bool $minorEdit
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $oldid Revision ID
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param array $watchers Array of user IDs
|
2012-12-09 03:09:48 +00:00
|
|
|
* @param string $pageStatus
|
|
|
|
|
* @throws MWException
|
2005-01-27 18:19:16 +00:00
|
|
|
*/
|
2012-05-18 21:01:12 +00:00
|
|
|
public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit,
|
|
|
|
|
$oldid, $watchers, $pageStatus = 'changed' ) {
|
2008-12-23 18:08:43 +00:00
|
|
|
# we use $wgPasswordSender as sender's address
|
2015-11-02 13:37:25 +00:00
|
|
|
global $wgUsersNotifiedOnAllChanges;
|
2015-06-16 09:51:16 +00:00
|
|
|
global $wgEnotifWatchlist, $wgBlockDisablesLogin;
|
2009-03-02 12:15:28 +00:00
|
|
|
global $wgEnotifMinorEdits, $wgEnotifUserTalk;
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
2010-12-04 13:39:18 +00:00
|
|
|
$isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->timestamp = $timestamp;
|
|
|
|
|
$this->summary = $summary;
|
|
|
|
|
$this->minorEdit = $minorEdit;
|
|
|
|
|
$this->oldid = $oldid;
|
|
|
|
|
$this->editor = $editor;
|
|
|
|
|
$this->composed_common = false;
|
2012-05-18 21:01:12 +00:00
|
|
|
$this->pageStatus = $pageStatus;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formattedPageStatus = [ 'deleted', 'created', 'moved', 'restored', 'changed' ];
|
2012-05-18 21:01:12 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'UpdateUserMailerFormattedPageStatus', [ &$formattedPageStatus ] );
|
2012-05-18 21:01:12 +00:00
|
|
|
if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
|
|
|
|
|
throw new MWException( 'Not a valid page status!' );
|
|
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
$userTalkId = false;
|
|
|
|
|
|
2010-12-04 13:39:18 +00:00
|
|
|
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
|
2014-05-11 15:34:14 +00:00
|
|
|
if ( $wgEnotifUserTalk
|
|
|
|
|
&& $isUserTalkPage
|
|
|
|
|
&& $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
|
|
|
|
|
) {
|
2008-12-23 18:08:43 +00:00
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
2015-07-07 18:44:25 +00:00
|
|
|
$this->compose( $targetUser, self::USER_TALK );
|
2011-09-22 12:14:21 +00:00
|
|
|
$userTalkId = $targetUser->getId();
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $wgEnotifWatchlist ) {
|
|
|
|
|
// Send updates to watchers other than the current editor
|
2015-06-16 09:51:16 +00:00
|
|
|
// and don't send to watchers who are blocked and cannot login
|
2009-03-02 12:15:28 +00:00
|
|
|
$userArray = UserArray::newFromIDs( $watchers );
|
2008-12-23 18:08:43 +00:00
|
|
|
foreach ( $userArray as $watchingUser ) {
|
2013-12-01 20:39:00 +00:00
|
|
|
if ( $watchingUser->getOption( 'enotifwatchlistpages' )
|
|
|
|
|
&& ( !$minorEdit || $watchingUser->getOption( 'enotifminoredits' ) )
|
|
|
|
|
&& $watchingUser->isEmailConfirmed()
|
2016-03-19 00:08:06 +00:00
|
|
|
&& $watchingUser->getId() != $userTalkId
|
2015-11-02 13:37:25 +00:00
|
|
|
&& !in_array( $watchingUser->getName(), $wgUsersNotifiedOnAllChanges )
|
2019-04-23 17:51:54 +00:00
|
|
|
// @TODO Partial blocks should not prevent the user from logging in.
|
|
|
|
|
// see: https://phabricator.wikimedia.org/T208895
|
|
|
|
|
&& !( $wgBlockDisablesLogin && $watchingUser->getBlock() )
|
2019-03-29 20:12:24 +00:00
|
|
|
&& Hooks::run( 'SendWatchlistEmailNotification', [ $watchingUser, $title, $this ] )
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
2019-03-29 20:12:24 +00:00
|
|
|
$this->compose( $watchingUser, self::WATCHLIST );
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgUsersNotifiedOnAllChanges as $name ) {
|
2012-01-23 15:04:22 +00:00
|
|
|
if ( $editor->getName() == $name ) {
|
|
|
|
|
// No point notifying the user that actually made the change!
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
$user = User::newFromName( $name );
|
2015-07-07 18:44:25 +00:00
|
|
|
$this->compose( $user, self::ALL_CHANGES );
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:35:13 +00:00
|
|
|
$this->sendMails();
|
2009-03-02 12:15:28 +00:00
|
|
|
}
|
2008-12-10 06:40:05 +00:00
|
|
|
|
2011-09-22 12:14:21 +00:00
|
|
|
/**
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $editor
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param bool $minorEdit
|
2011-09-22 12:14:21 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
|
2015-06-16 09:51:16 +00:00
|
|
|
global $wgEnotifUserTalk, $wgBlockDisablesLogin;
|
2011-09-22 12:14:21 +00:00
|
|
|
$isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
|
|
|
|
|
|
|
|
|
|
if ( $wgEnotifUserTalk && $isUserTalkPage ) {
|
|
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
|
|
|
|
|
|
|
|
|
if ( !$targetUser || $targetUser->isAnon() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
|
|
|
|
|
} elseif ( $targetUser->getId() == $editor->getId() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
|
2019-04-23 17:51:54 +00:00
|
|
|
} elseif ( $wgBlockDisablesLogin && $targetUser->getBlock() ) {
|
|
|
|
|
// @TODO Partial blocks should not prevent the user from logging in.
|
|
|
|
|
// see: https://phabricator.wikimedia.org/T208895
|
2015-06-16 09:51:16 +00:00
|
|
|
wfDebug( __METHOD__ . ": talk page owner is blocked and cannot login, no notification sent\n" );
|
2013-12-01 20:39:00 +00:00
|
|
|
} elseif ( $targetUser->getOption( 'enotifusertalkpages' )
|
|
|
|
|
&& ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) )
|
|
|
|
|
) {
|
2013-06-10 22:11:39 +00:00
|
|
|
if ( !$targetUser->isEmailConfirmed() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
|
2016-02-17 09:09:32 +00:00
|
|
|
} elseif ( !Hooks::run( 'AbortTalkPageEmailNotification', [ $targetUser, $title ] ) ) {
|
2013-06-10 22:11:39 +00:00
|
|
|
wfDebug( __METHOD__ . ": talk page update notification is aborted for this user\n" );
|
|
|
|
|
} else {
|
2011-09-22 12:14:21 +00:00
|
|
|
wfDebug( __METHOD__ . ": sending talk page update notification\n" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-06 20:54:24 +00:00
|
|
|
return false;
|
2011-09-22 12:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
2010-12-05 04:14:39 +00:00
|
|
|
* Generate the generic "this page has been changed" e-mail text.
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2010-12-05 04:14:39 +00:00
|
|
|
private function composeCommonMailtext() {
|
2013-12-31 06:12:09 +00:00
|
|
|
global $wgPasswordSender, $wgNoReplyAddress;
|
2008-12-23 18:08:43 +00:00
|
|
|
global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
|
|
|
|
|
global $wgEnotifImpersonal, $wgEnotifUseRealName;
|
|
|
|
|
|
|
|
|
|
$this->composed_common = true;
|
|
|
|
|
|
|
|
|
|
# You as the WikiAdmin and Sysops can make use of plenty of
|
|
|
|
|
# named variables when composing your notification emails while
|
|
|
|
|
# simply editing the Meta pages
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$keys = [];
|
|
|
|
|
$postTransformKeys = [];
|
2013-03-27 13:36:05 +00:00
|
|
|
$pageTitleUrl = $this->title->getCanonicalURL();
|
2012-05-18 21:01:12 +00:00
|
|
|
$pageTitle = $this->title->getPrefixedText();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2010-12-04 13:39:18 +00:00
|
|
|
if ( $this->oldid ) {
|
2017-02-20 22:44:19 +00:00
|
|
|
// Always show a link to the diff which triggered the mail. See T34210.
|
2012-05-18 21:01:12 +00:00
|
|
|
$keys['$NEWPAGE'] = "\n\n" . wfMessage( 'enotif_lastdiff',
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->title->getCanonicalURL( [ 'diff' => 'next', 'oldid' => $this->oldid ] ) )
|
2014-09-13 02:01:22 +00:00
|
|
|
->inContentLanguage()->text();
|
2012-05-18 21:01:12 +00:00
|
|
|
|
2012-02-10 21:47:37 +00:00
|
|
|
if ( !$wgEnotifImpersonal ) {
|
|
|
|
|
// For personal mail, also show a link to the diff of all changes
|
|
|
|
|
// since last visited.
|
2013-02-03 20:05:24 +00:00
|
|
|
$keys['$NEWPAGE'] .= "\n\n" . wfMessage( 'enotif_lastvisited',
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->title->getCanonicalURL( [ 'diff' => '0', 'oldid' => $this->oldid ] ) )
|
2014-09-13 02:01:22 +00:00
|
|
|
->inContentLanguage()->text();
|
2011-10-15 19:06:31 +00:00
|
|
|
}
|
2013-02-03 20:05:24 +00:00
|
|
|
$keys['$OLDID'] = $this->oldid;
|
2014-04-17 19:08:50 +00:00
|
|
|
// Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility.
|
2012-12-18 02:39:30 +00:00
|
|
|
$keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
|
2004-12-18 03:47:11 +00:00
|
|
|
} else {
|
2004-12-18 10:23:54 +00:00
|
|
|
# clear $OLDID placeholder in the message template
|
2013-02-03 20:05:24 +00:00
|
|
|
$keys['$OLDID'] = '';
|
2012-05-18 21:01:12 +00:00
|
|
|
$keys['$NEWPAGE'] = '';
|
2014-04-17 19:08:50 +00:00
|
|
|
// Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility.
|
2012-12-18 02:39:30 +00:00
|
|
|
$keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
|
2004-12-18 03:47:11 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2011-10-16 09:53:41 +00:00
|
|
|
$keys['$PAGETITLE'] = $this->title->getPrefixedText();
|
2013-03-27 13:36:05 +00:00
|
|
|
$keys['$PAGETITLE_URL'] = $this->title->getCanonicalURL();
|
2019-02-13 11:11:46 +00:00
|
|
|
$keys['$PAGEMINOREDIT'] = $this->minorEdit ?
|
|
|
|
|
"\n\n" . wfMessage( 'enotif_minoredit' )->inContentLanguage()->text() :
|
|
|
|
|
'';
|
2013-03-27 13:36:05 +00:00
|
|
|
$keys['$UNWATCHURL'] = $this->title->getCanonicalURL( 'action=unwatch' );
|
2011-10-16 09:53:41 +00:00
|
|
|
|
|
|
|
|
if ( $this->editor->isAnon() ) {
|
|
|
|
|
# real anon (user:xxx.xxx.xxx.xxx)
|
2012-08-27 18:33:45 +00:00
|
|
|
$keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
|
|
|
|
|
->inContentLanguage()->text();
|
|
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
|
2012-05-18 21:01:12 +00:00
|
|
|
|
2011-10-16 09:53:41 +00:00
|
|
|
} else {
|
2014-04-27 09:17:35 +00:00
|
|
|
$keys['$PAGEEDITOR'] = $wgEnotifUseRealName && $this->editor->getRealName() !== ''
|
|
|
|
|
? $this->editor->getRealName() : $this->editor->getName();
|
2011-10-16 09:53:41 +00:00
|
|
|
$emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
|
2013-03-27 13:36:05 +00:00
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL();
|
2011-10-16 09:53:41 +00:00
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
|
2013-03-27 13:36:05 +00:00
|
|
|
$keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL();
|
2014-05-11 15:34:14 +00:00
|
|
|
$keys['$HELPPAGE'] = wfExpandUrl(
|
|
|
|
|
Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() )
|
|
|
|
|
);
|
2008-12-23 18:08:43 +00:00
|
|
|
|
2017-02-20 22:44:19 +00:00
|
|
|
# Replace this after transforming the message, T37019
|
2012-03-08 21:39:13 +00:00
|
|
|
$postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
|
|
|
|
|
|
2013-08-28 00:38:27 +00:00
|
|
|
// Now build message's subject and body
|
|
|
|
|
|
|
|
|
|
// Messages:
|
|
|
|
|
// enotif_subject_deleted, enotif_subject_created, enotif_subject_moved,
|
|
|
|
|
// enotif_subject_restored, enotif_subject_changed
|
2012-05-18 21:01:12 +00:00
|
|
|
$this->subject = wfMessage( 'enotif_subject_' . $this->pageStatus )->inContentLanguage()
|
2012-12-18 02:39:30 +00:00
|
|
|
->params( $pageTitle, $keys['$PAGEEDITOR'] )->text();
|
2011-10-16 09:53:41 +00:00
|
|
|
|
2013-08-28 00:38:27 +00:00
|
|
|
// Messages:
|
|
|
|
|
// enotif_body_intro_deleted, enotif_body_intro_created, enotif_body_intro_moved,
|
|
|
|
|
// enotif_body_intro_restored, enotif_body_intro_changed
|
2012-05-18 21:01:12 +00:00
|
|
|
$keys['$PAGEINTRO'] = wfMessage( 'enotif_body_intro_' . $this->pageStatus )
|
|
|
|
|
->inContentLanguage()->params( $pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl )
|
2012-12-18 02:39:30 +00:00
|
|
|
->text();
|
2011-10-16 09:53:41 +00:00
|
|
|
|
2012-08-27 18:33:45 +00:00
|
|
|
$body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
|
2011-10-16 09:53:41 +00:00
|
|
|
$body = strtr( $body, $keys );
|
|
|
|
|
$body = MessageCache::singleton()->transform( $body, false, null, $this->title );
|
2012-03-08 21:39:13 +00:00
|
|
|
$this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 );
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
# Reveal the page editor's address as REPLY-TO address only if
|
|
|
|
|
# the user has not opted-out and the option is enabled at the
|
|
|
|
|
# global configuration level.
|
2013-12-31 06:12:09 +00:00
|
|
|
$adminAddress = new MailAddress( $wgPasswordSender,
|
|
|
|
|
wfMessage( 'emailsender' )->inContentLanguage()->text() );
|
2010-12-04 13:39:18 +00:00
|
|
|
if ( $wgEnotifRevealEditorAddress
|
2011-10-16 09:53:41 +00:00
|
|
|
&& ( $this->editor->getEmail() != '' )
|
2013-12-01 20:39:00 +00:00
|
|
|
&& $this->editor->getOption( 'enotifrevealaddr' )
|
|
|
|
|
) {
|
2014-09-13 03:25:19 +00:00
|
|
|
$editorAddress = MailAddress::newFromUser( $this->editor );
|
2010-12-04 13:39:18 +00:00
|
|
|
if ( $wgEnotifFromEditor ) {
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->from = $editorAddress;
|
2008-12-23 18:08:43 +00:00
|
|
|
} else {
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->from = $adminAddress;
|
2011-10-16 09:53:41 +00:00
|
|
|
$this->replyto = $editorAddress;
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->from = $adminAddress;
|
2011-10-16 09:53:41 +00:00
|
|
|
$this->replyto = new MailAddress( $wgNoReplyAddress );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
|
|
|
|
* 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.
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $user
|
2015-07-07 18:44:25 +00:00
|
|
|
* @param string $source
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2019-06-26 10:11:33 +00:00
|
|
|
private function compose( $user, $source ) {
|
2008-12-23 18:08:43 +00:00
|
|
|
global $wgEnotifImpersonal;
|
2004-12-18 03:47:11 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->composed_common ) {
|
2008-12-23 18:08:43 +00:00
|
|
|
$this->composeCommonMailtext();
|
2013-04-20 22:49:30 +00:00
|
|
|
}
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
if ( $wgEnotifImpersonal ) {
|
2014-09-13 03:25:19 +00:00
|
|
|
$this->mailTargets[] = MailAddress::newFromUser( $user );
|
2008-12-23 18:08:43 +00:00
|
|
|
} else {
|
2015-07-07 18:44:25 +00:00
|
|
|
$this->sendPersonalised( $user, $source );
|
2008-12-10 06:40:05 +00:00
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
2007-05-05 12:08:24 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
|
|
|
|
* Send any queued mails
|
|
|
|
|
*/
|
2019-06-26 10:11:33 +00:00
|
|
|
private function sendMails() {
|
2008-12-23 18:08:43 +00:00
|
|
|
global $wgEnotifImpersonal;
|
|
|
|
|
if ( $wgEnotifImpersonal ) {
|
|
|
|
|
$this->sendImpersonal( $this->mailTargets );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
|
|
|
|
* Does the per-user customizations to a notification e-mail (name,
|
|
|
|
|
* timestamp in proper timezone, etc) and sends it out.
|
2018-12-03 14:09:14 +00:00
|
|
|
* Returns Status if email was sent successfully or not (Status::newGood()
|
|
|
|
|
* or Status::newFatal() respectively).
|
2008-12-23 18:08:43 +00:00
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param User $watchingUser
|
2015-07-07 18:44:25 +00:00
|
|
|
* @param string $source
|
2018-12-03 14:09:14 +00:00
|
|
|
* @return Status
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2019-06-26 10:11:33 +00:00
|
|
|
private function sendPersonalised( $watchingUser, $source ) {
|
2018-07-29 12:24:54 +00:00
|
|
|
global $wgEnotifUseRealName;
|
2008-12-23 18:08:43 +00:00
|
|
|
// From the PHP manual:
|
2014-05-11 15:34:14 +00:00
|
|
|
// Note: The to parameter cannot be an address in the form of
|
|
|
|
|
// "Something <someone@example.com>". The mail command will not parse
|
|
|
|
|
// this properly while talking with the MTA.
|
2014-09-13 03:25:19 +00:00
|
|
|
$to = MailAddress::newFromUser( $watchingUser );
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
# $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
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
2009-08-23 17:48:25 +00:00
|
|
|
$body = str_replace(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '$WATCHINGUSERNAME',
|
2009-08-23 17:48:25 +00:00
|
|
|
'$PAGEEDITDATE',
|
2016-02-17 09:09:32 +00:00
|
|
|
'$PAGEEDITTIME' ],
|
|
|
|
|
[ $wgEnotifUseRealName && $watchingUser->getRealName() !== ''
|
2014-09-13 02:01:22 +00:00
|
|
|
? $watchingUser->getRealName() : $watchingUser->getName(),
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang->userDate( $this->timestamp, $watchingUser ),
|
|
|
|
|
$contLang->userTime( $this->timestamp, $watchingUser ) ],
|
2011-10-15 19:06:31 +00:00
|
|
|
$this->body );
|
2008-12-23 18:08:43 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$headers = [];
|
2015-07-07 18:44:25 +00:00
|
|
|
if ( $source === self::WATCHLIST ) {
|
|
|
|
|
$headers['List-Help'] = 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Watchlist';
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return UserMailer::send( $to, $this->from, $this->subject, $body, [
|
2015-07-12 05:07:18 +00:00
|
|
|
'replyTo' => $this->replyto,
|
2015-07-07 18:44:25 +00:00
|
|
|
'headers' => $headers,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
2008-12-10 06:02:14 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
|
|
|
|
* Same as sendPersonalised but does impersonal mail suitable for bulk
|
|
|
|
|
* mailing. Takes an array of MailAddress objects.
|
2014-04-23 11:39:49 +00:00
|
|
|
* @param MailAddress[] $addresses
|
2012-12-09 02:59:04 +00:00
|
|
|
* @return Status|null
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2019-06-26 10:11:33 +00:00
|
|
|
private function sendImpersonal( $addresses ) {
|
2012-12-09 02:59:04 +00:00
|
|
|
if ( empty( $addresses ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
2008-12-23 18:08:43 +00:00
|
|
|
$body = str_replace(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '$WATCHINGUSERNAME',
|
2014-09-13 02:01:22 +00:00
|
|
|
'$PAGEEDITDATE',
|
2016-02-17 09:09:32 +00:00
|
|
|
'$PAGEEDITTIME' ],
|
|
|
|
|
[ wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang->date( $this->timestamp, false, false ),
|
|
|
|
|
$contLang->time( $this->timestamp, false, false ) ],
|
2014-09-13 02:01:22 +00:00
|
|
|
$this->body );
|
2008-12-10 06:40:05 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return UserMailer::send( $addresses, $this->from, $this->subject, $body, [
|
2015-07-12 05:07:18 +00:00
|
|
|
'replyTo' => $this->replyto,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
|
2014-09-13 02:01:22 +00:00
|
|
|
}
|