2004-02-28 07:08:13 +00:00
|
|
|
<?php
|
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
|
2024-02-09 01:02:16 +00:00
|
|
|
* @author Brooke Vibber
|
2005-01-27 18:19:16 +00:00
|
|
|
* @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
|
|
|
|
2023-05-06 20:01:10 +00:00
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2021-03-26 01:50:30 +00:00
|
|
|
use MediaWiki\Mail\UserEmailContact;
|
2022-04-13 15:28:26 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2016-04-15 16:29:05 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-03-26 01:50:30 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2023-09-19 16:42:44 +00:00
|
|
|
use MediaWiki\User\UserArray;
|
2021-03-26 01:50:30 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2016-04-15 16:29:05 +00:00
|
|
|
|
2008-12-23 18:08:43 +00:00
|
|
|
/**
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
* Find watchers and create email notifications after a page is changed.
|
2008-12-23 18:08:43 +00:00
|
|
|
*
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
* After an edit is published to RCFeed, RecentChange::save calls EmailNotification.
|
|
|
|
|
* Here we query the `watchlist` table (via WatchedItemStore) to find who is watching
|
|
|
|
|
* a given page, format the emails in question, and dispatch emails to each of them
|
|
|
|
|
* via the JobQueue.
|
2008-12-23 18:08:43 +00:00
|
|
|
*
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
* The current implementation sends independent emails to each watching user for
|
|
|
|
|
* the following reason: Each email mentions the page edit time expressed in
|
|
|
|
|
* the person's local time (UTC is shown additionally). To achieve this, we need to
|
2021-08-23 08:56:24 +00:00
|
|
|
* find the individual timeoffset of each watching user from the preferences.
|
2008-12-23 18:08:43 +00:00
|
|
|
*
|
2017-05-31 02:16:22 +00:00
|
|
|
* Visit the documentation pages under
|
|
|
|
|
* https://www.mediawiki.org/wiki/Help:Watching_pages
|
2021-03-30 19:39:34 +00:00
|
|
|
*
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
* @todo If the volume becomes too great, we could send out bulk mails (bcc:user1,user2...)
|
|
|
|
|
* grouped by users having the same timeoffset in their preferences. This would however
|
|
|
|
|
* need to carefully consider impact of failure rate, re-try behaviour, and idempotence.
|
|
|
|
|
*
|
|
|
|
|
* @todo Use UserOptionsLookup and other services, consider converting this to a service
|
|
|
|
|
*
|
|
|
|
|
* @since 1.11.0
|
|
|
|
|
* @ingroup Mail
|
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
|
|
|
|
|
*/
|
2020-05-11 00:36:36 +00:00
|
|
|
private const USER_TALK = 'user_talk';
|
2015-07-07 18:44:25 +00:00
|
|
|
/**
|
|
|
|
|
* Notification is due to a watchlisted page being edited
|
|
|
|
|
*/
|
2020-05-11 00:36:36 +00:00
|
|
|
private const WATCHLIST = 'watchlist';
|
2015-07-07 18:44:25 +00:00
|
|
|
/**
|
|
|
|
|
* Notification because user is notified for all changes
|
|
|
|
|
*/
|
2020-05-11 00:36:36 +00:00
|
|
|
private const ALL_CHANGES = 'all_changes';
|
2015-07-07 18:44:25 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected string $subject = '';
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected string $body = '';
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected ?MailAddress $replyto;
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected ?MailAddress $from;
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected ?string $timestamp;
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected string $summary = '';
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected ?bool $minorEdit;
|
2021-03-30 19:39:34 +00:00
|
|
|
|
|
|
|
|
/** @var int|null|bool */
|
|
|
|
|
protected $oldid;
|
|
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected bool $composed_common = false;
|
2021-03-30 19:39:34 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected string $pageStatus = '';
|
2021-03-30 19:39:34 +00:00
|
|
|
|
|
|
|
|
/** @var MailAddress[] */
|
2023-10-30 22:55:57 +00:00
|
|
|
protected array $mailTargets = [];
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected Title $title;
|
2011-10-26 03:44:47 +00:00
|
|
|
|
2023-10-30 22:55:57 +00:00
|
|
|
protected User $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.
|
|
|
|
|
*
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
* @since 1.11.0
|
|
|
|
|
* @since 1.35 returns a boolean indicating whether an email job was created.
|
2021-03-26 01:50:30 +00:00
|
|
|
* @param Authority $editor
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param string $timestamp
|
|
|
|
|
* @param string $summary
|
|
|
|
|
* @param bool $minorEdit
|
|
|
|
|
* @param bool $oldid (default: false)
|
|
|
|
|
* @param string $pageStatus (default: 'changed')
|
2020-06-17 19:08:11 +00:00
|
|
|
* @return bool Whether an email job was created or not.
|
2007-10-03 08:46:17 +00:00
|
|
|
*/
|
2021-03-30 19:39:34 +00:00
|
|
|
public function notifyOnPageChange(
|
2021-03-26 01:50:30 +00:00
|
|
|
Authority $editor,
|
2021-03-30 19:39:34 +00:00
|
|
|
$title,
|
|
|
|
|
$timestamp,
|
|
|
|
|
$summary,
|
|
|
|
|
$minorEdit,
|
|
|
|
|
$oldid = false,
|
|
|
|
|
$pageStatus = 'changed'
|
2020-06-17 19:08:11 +00:00
|
|
|
): bool {
|
2011-05-21 19:36:03 +00:00
|
|
|
if ( $title->getNamespace() < 0 ) {
|
2020-06-17 19:08:11 +00:00
|
|
|
return false;
|
2011-05-21 19:36:03 +00:00
|
|
|
}
|
2007-07-09 14:21:49 +00:00
|
|
|
|
2021-03-30 19:39:34 +00:00
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
|
|
|
|
$config = $mwServices->getMainConfig();
|
|
|
|
|
|
2014-09-09 21:10:01 +00:00
|
|
|
// update wl_notificationtimestamp for watchers
|
2016-02-05 12:14:13 +00:00
|
|
|
$watchers = [];
|
2024-02-12 09:48:21 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifWatchlist ) || $config->get( MainConfigNames::ShowUpdatedMarker ) ) {
|
2021-03-30 19:39:34 +00:00
|
|
|
$watchers = $mwServices->getWatchedItemStore()->updateNotificationTimestamp(
|
2021-03-26 01:50:30 +00:00
|
|
|
$editor->getUser(),
|
2016-02-05 12:14:13 +00:00
|
|
|
$title,
|
|
|
|
|
$timestamp
|
|
|
|
|
);
|
|
|
|
|
}
|
2009-03-02 12:15:28 +00:00
|
|
|
|
2024-02-12 09:48:21 +00:00
|
|
|
// Don't send email for bots
|
|
|
|
|
if ( $mwServices->getUserFactory()->newFromAuthority( $editor )->isBot() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $watchers === [] &&
|
2022-11-19 22:46:28 +00:00
|
|
|
!count( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) )
|
|
|
|
|
) {
|
2011-09-22 12:14:21 +00:00
|
|
|
$sendEmail = false;
|
|
|
|
|
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
|
2021-03-30 19:39:34 +00:00
|
|
|
if ( !$minorEdit ||
|
2022-04-13 15:28:26 +00:00
|
|
|
( $config->get( MainConfigNames::EnotifMinorEdits ) &&
|
|
|
|
|
!$editor->isAllowed( 'nominornewtalk' ) )
|
2019-08-21 02:01:06 +00:00
|
|
|
) {
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifUserTalk )
|
2022-11-19 22:46:28 +00:00
|
|
|
&& $title->getNamespace() === NS_USER_TALK
|
2021-03-26 01:50:30 +00:00
|
|
|
&& $this->canSendUserTalkEmail( $editor->getUser(), $title, $minorEdit )
|
2014-05-11 15:34:14 +00:00
|
|
|
) {
|
2011-09-22 12:14:21 +00:00
|
|
|
$sendEmail = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 00:03:29 +00:00
|
|
|
if ( $sendEmail ) {
|
2022-01-27 20:19:18 +00:00
|
|
|
$mwServices->getJobQueueGroup()->lazyPush( new EnotifNotifyJob(
|
2016-01-30 00:03:29 +00:00
|
|
|
$title,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2021-03-26 01:50:30 +00:00
|
|
|
'editor' => $editor->getUser()->getName(),
|
|
|
|
|
'editorID' => $editor->getUser()->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
|
|
|
}
|
2020-06-17 19:08:11 +00:00
|
|
|
|
|
|
|
|
return $sendEmail;
|
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.
|
mail: Improve docs, fix file headers, widen `@covers`
* Add missing `ingroup` to class blocks (and remove from any file blocks)
as otherwise the file is indexed twice (e.g. in Doxygen) which makes
navigation on doc.wikimedia.org rather messy.
Remove duplicate descriptions from file blocks in favour of class
doc blocks. This reduces needless duplication and was often
incorrect or outdated, and helps make file headers more consistently
(visually) ignorable.
Ref https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged
* Widen `@covers` tags in phpunit tests
Given all called methods are de-facto and liberally claimed, and
that we keep the coverage limited to the subject class, it maintains
the spirit and intent by listing the class explicitly instead.
PHPUnit offers a more precise tool when you need it (i.e. when testing
legacy monster/god classes), but for well-written code, the
class-wide tag is exactly what you want.
We lose useful coverage and waste valuable time on keeping tags
accurate through refactors (or worse, forget to do so).
Tracking tiny per-method details wastes time in realizing (and
fixing) when people inevitably don't keep them in sync, and time
lost in finding uncovered code to write tests to realize it was
already covered but "not yet claimed".
Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen
While at it, improve purposes and explainations of several mail-related
classes, and set `@since`:
- EmailNotification introduced in r22110 (1.11.0), git a6f6e04841,
later moved to a separate file in bf8810d6bc (Ic435bbdbb6).
- MailAddress introduced in r12082 (1.6.0, 1.5.7), git 5cfddf9a82.
- UserMailer converted to class with ::send in r26357 (1.12.0),
git 353f203ce2.
Change-Id: I1216781240bcfabdebf109cef8f995355db0f659
2024-05-10 17:46:24 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.11.0
|
2021-03-26 01:50:30 +00:00
|
|
|
* @param Authority $editor
|
2014-04-22 11:07:02 +00:00
|
|
|
* @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
|
2005-01-27 18:19:16 +00:00
|
|
|
*/
|
2019-08-26 13:03:35 +00:00
|
|
|
public function actuallyNotifyOnPageChange(
|
2021-03-26 01:50:30 +00:00
|
|
|
Authority $editor,
|
2019-08-26 13:03:35 +00:00
|
|
|
$title,
|
|
|
|
|
$timestamp,
|
|
|
|
|
$summary,
|
|
|
|
|
$minorEdit,
|
|
|
|
|
$oldid,
|
|
|
|
|
$watchers,
|
|
|
|
|
$pageStatus = 'changed'
|
|
|
|
|
) {
|
2008-12-23 18:08:43 +00:00
|
|
|
# we use $wgPasswordSender as sender's address
|
|
|
|
|
|
2021-03-30 19:39:34 +00:00
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
|
|
|
|
$messageCache = $mwServices->getMessageCache();
|
|
|
|
|
$config = $mwServices->getMainConfig();
|
2019-08-26 13:03:35 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->timestamp = $timestamp;
|
|
|
|
|
$this->summary = $summary;
|
|
|
|
|
$this->minorEdit = $minorEdit;
|
|
|
|
|
$this->oldid = $oldid;
|
2021-03-26 01:50:30 +00:00
|
|
|
$this->editor = MediaWikiServices::getInstance()->getUserFactory()->newFromAuthority( $editor );
|
2008-12-23 18:08:43 +00:00
|
|
|
$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
|
|
|
|
2023-05-06 20:01:10 +00:00
|
|
|
$hookRunner = new HookRunner( $mwServices->getHookContainer() );
|
|
|
|
|
$hookRunner->onUpdateUserMailerFormattedPageStatus( $formattedPageStatus );
|
2012-05-18 21:01:12 +00:00
|
|
|
if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
|
2023-06-09 15:01:45 +00:00
|
|
|
throw new UnexpectedValueException( 'Not a valid page status!' );
|
2012-05-18 21:01:12 +00:00
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
$userTalkId = false;
|
|
|
|
|
|
2021-03-30 19:39:34 +00:00
|
|
|
if ( !$minorEdit ||
|
2022-04-13 15:28:26 +00:00
|
|
|
( $config->get( MainConfigNames::EnotifMinorEdits ) &&
|
|
|
|
|
!$editor->isAllowed( 'nominornewtalk' ) )
|
2019-08-21 02:01:06 +00:00
|
|
|
) {
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifUserTalk )
|
2022-11-19 22:46:28 +00:00
|
|
|
&& $title->getNamespace() === NS_USER_TALK
|
2021-03-26 01:50:30 +00:00
|
|
|
&& $this->canSendUserTalkEmail( $editor->getUser(), $title, $minorEdit )
|
2014-05-11 15:34:14 +00:00
|
|
|
) {
|
2008-12-23 18:08:43 +00:00
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
2019-08-26 13:03:35 +00:00
|
|
|
$this->compose( $targetUser, self::USER_TALK, $messageCache );
|
2011-09-22 12:14:21 +00:00
|
|
|
$userTalkId = $targetUser->getId();
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifWatchlist ) ) {
|
2022-04-29 18:56:13 +00:00
|
|
|
$userOptionsLookup = $mwServices->getUserOptionsLookup();
|
2008-12-23 18:08:43 +00:00
|
|
|
// 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 ) {
|
2022-04-29 18:56:13 +00:00
|
|
|
if ( $userOptionsLookup->getOption( $watchingUser, 'enotifwatchlistpages' )
|
|
|
|
|
&& ( !$minorEdit || $userOptionsLookup->getOption( $watchingUser, 'enotifminoredits' ) )
|
2013-12-01 20:39:00 +00:00
|
|
|
&& $watchingUser->isEmailConfirmed()
|
2016-03-19 00:08:06 +00:00
|
|
|
&& $watchingUser->getId() != $userTalkId
|
2022-04-13 15:28:26 +00:00
|
|
|
&& !in_array( $watchingUser->getName(),
|
|
|
|
|
$config->get( MainConfigNames::UsersNotifiedOnAllChanges ) )
|
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
|
2022-04-13 15:28:26 +00:00
|
|
|
&& !( $config->get( MainConfigNames::BlockDisablesLogin ) &&
|
|
|
|
|
$watchingUser->getBlock() )
|
2023-05-06 20:01:10 +00:00
|
|
|
&& $hookRunner->onSendWatchlistEmailNotification( $watchingUser, $title, $this )
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
2019-08-26 13:03:35 +00:00
|
|
|
$this->compose( $watchingUser, self::WATCHLIST, $messageCache );
|
2008-12-23 18:08:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 15:28:26 +00:00
|
|
|
foreach ( $config->get( MainConfigNames::UsersNotifiedOnAllChanges ) as $name ) {
|
2021-03-26 01:50:30 +00:00
|
|
|
if ( $editor->getUser()->getName() == $name ) {
|
2012-01-23 15:04:22 +00:00
|
|
|
// No point notifying the user that actually made the change!
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
$user = User::newFromName( $name );
|
2022-05-22 10:49:47 +00:00
|
|
|
if ( $user instanceof User ) {
|
|
|
|
|
$this->compose( $user, self::ALL_CHANGES, $messageCache );
|
|
|
|
|
}
|
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
|
|
|
/**
|
2021-03-26 01:50:30 +00:00
|
|
|
* @param UserIdentity $editor
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param bool $minorEdit
|
2011-09-22 12:14:21 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-03-26 01:50:30 +00:00
|
|
|
private function canSendUserTalkEmail( UserIdentity $editor, $title, $minorEdit ) {
|
2022-04-29 18:56:13 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$config = $services->getMainConfig();
|
2011-09-22 12:14:21 +00:00
|
|
|
|
2022-11-19 22:46:28 +00:00
|
|
|
if ( !$config->get( MainConfigNames::EnotifUserTalk ) || $title->getNamespace() !== NS_USER_TALK ) {
|
2021-03-30 19:39:34 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 18:56:13 +00:00
|
|
|
$userOptionsLookup = $services->getUserOptionsLookup();
|
2021-03-30 19:39:34 +00:00
|
|
|
$targetUser = User::newFromName( $title->getText() );
|
|
|
|
|
|
|
|
|
|
if ( !$targetUser || $targetUser->isAnon() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": user talk page edited, but user does not exist" );
|
|
|
|
|
} elseif ( $targetUser->getId() == $editor->getId() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent" );
|
2023-05-24 13:43:51 +00:00
|
|
|
} elseif ( $targetUser->isTemp() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner is a temporary user so doesn't have email" );
|
2022-04-13 15:28:26 +00:00
|
|
|
} elseif ( $config->get( MainConfigNames::BlockDisablesLogin ) &&
|
2022-11-19 22:46:28 +00:00
|
|
|
$targetUser->getBlock()
|
|
|
|
|
) {
|
2021-03-30 19:39:34 +00:00
|
|
|
// @TODO Partial blocks should not prevent the user from logging in.
|
|
|
|
|
// see: https://phabricator.wikimedia.org/T208895
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner is blocked and cannot login, no notification sent" );
|
2022-04-29 18:56:13 +00:00
|
|
|
} elseif ( $userOptionsLookup->getOption( $targetUser, 'enotifusertalkpages' )
|
|
|
|
|
&& ( !$minorEdit || $userOptionsLookup->getOption( $targetUser, 'enotifminoredits' ) )
|
2021-03-30 19:39:34 +00:00
|
|
|
) {
|
|
|
|
|
if ( !$targetUser->isEmailConfirmed() ) {
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner doesn't have validated email" );
|
2023-05-06 20:01:10 +00:00
|
|
|
} elseif ( !( new HookRunner( $services->getHookContainer() ) )
|
|
|
|
|
->onAbortTalkPageEmailNotification( $targetUser, $title )
|
|
|
|
|
) {
|
2021-03-30 19:39:34 +00:00
|
|
|
wfDebug( __METHOD__ . ": talk page update notification is aborted for this user" );
|
2011-09-22 12:14:21 +00:00
|
|
|
} else {
|
2021-03-30 19:39:34 +00:00
|
|
|
wfDebug( __METHOD__ . ": sending talk page update notification" );
|
|
|
|
|
return true;
|
2011-09-22 12:14:21 +00:00
|
|
|
}
|
2021-03-30 19:39:34 +00:00
|
|
|
} else {
|
|
|
|
|
wfDebug( __METHOD__ . ": talk page owner doesn't want notifications" );
|
2011-09-22 12:14:21 +00:00
|
|
|
}
|
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.
|
2019-08-26 13:03:35 +00:00
|
|
|
* @param MessageCache $messageCache
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2019-08-26 13:03:35 +00:00
|
|
|
private function composeCommonMailtext( MessageCache $messageCache ) {
|
2022-04-29 18:56:13 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$config = $services->getMainConfig();
|
|
|
|
|
$userOptionsLookup = $services->getUserOptionsLookup();
|
2024-09-07 17:50:18 +00:00
|
|
|
$urlUtils = $services->getUrlUtils();
|
2008-12-23 18:08:43 +00:00
|
|
|
|
|
|
|
|
$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.
|
2021-03-30 19:39:34 +00:00
|
|
|
$keys['$NEWPAGE'] = "\n\n" . wfMessage(
|
|
|
|
|
'enotif_lastdiff',
|
|
|
|
|
$this->title->getCanonicalURL( [ 'diff' => 'next', 'oldid' => $this->oldid ] )
|
|
|
|
|
)->inContentLanguage()->text();
|
2012-05-18 21:01:12 +00:00
|
|
|
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( !$config->get( MainConfigNames::EnotifImpersonal ) ) {
|
2012-02-10 21:47:37 +00:00
|
|
|
// For personal mail, also show a link to the diff of all changes
|
|
|
|
|
// since last visited.
|
2021-03-30 19:39:34 +00:00
|
|
|
$keys['$NEWPAGE'] .= "\n\n" . wfMessage(
|
|
|
|
|
'enotif_lastvisited',
|
|
|
|
|
$this->title->getCanonicalURL( [ 'diff' => '0', 'oldid' => $this->oldid ] )
|
|
|
|
|
)->inContentLanguage()->text();
|
2011-10-15 19:06:31 +00:00
|
|
|
}
|
2013-02-03 20:05:24 +00:00
|
|
|
$keys['$OLDID'] = $this->oldid;
|
2023-10-26 14:10:15 +00:00
|
|
|
$keys['$PAGELOG'] = '';
|
2004-12-18 03:47:11 +00:00
|
|
|
} else {
|
2023-10-26 14:10:15 +00:00
|
|
|
// If there is no revision to link to, link to the page log, which should have details. See T115183.
|
2013-02-03 20:05:24 +00:00
|
|
|
$keys['$OLDID'] = '';
|
2012-05-18 21:01:12 +00:00
|
|
|
$keys['$NEWPAGE'] = '';
|
2023-10-26 14:10:15 +00:00
|
|
|
$keys['$PAGELOG'] = "\n\n" . wfMessage(
|
|
|
|
|
'enotif_pagelog',
|
|
|
|
|
SpecialPage::getTitleFor( 'Log' )->getCanonicalURL( [ 'page' => $this->title->getPrefixedDBkey() ] )
|
|
|
|
|
)->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
|
|
|
|
2023-05-24 13:43:51 +00:00
|
|
|
if ( $this->editor->isAnon() ) {
|
2011-10-16 09:53:41 +00:00
|
|
|
# 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();
|
2023-05-24 13:43:51 +00:00
|
|
|
} elseif ( $this->editor->isTemp() ) {
|
|
|
|
|
$keys['$PAGEEDITOR'] = wfMessage( 'enotif_temp_editor', $this->editor->getName() )
|
|
|
|
|
->inContentLanguage()->text();
|
|
|
|
|
$keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
|
2011-10-16 09:53:41 +00:00
|
|
|
} else {
|
2022-04-13 15:28:26 +00:00
|
|
|
$keys['$PAGEEDITOR'] = $config->get( MainConfigNames::EnotifUseRealName ) &&
|
|
|
|
|
$this->editor->getRealName() !== ''
|
2014-04-27 09:17:35 +00:00
|
|
|
? $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
|
|
|
|
2019-12-23 21:49:48 +00:00
|
|
|
$keys['$PAGEEDITOR_WIKI'] = $this->editor->getTalkPage()->getCanonicalURL();
|
2024-09-07 17:50:18 +00:00
|
|
|
$keys['$HELPPAGE'] = $urlUtils->expand(
|
|
|
|
|
Skin::makeInternalOrExternalUrl( wfMessage( 'helppage' )->inContentLanguage()->text() ),
|
|
|
|
|
PROTO_CURRENT
|
|
|
|
|
) ?? false;
|
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 )
|
2021-03-30 19:39:34 +00:00
|
|
|
->inContentLanguage()
|
2023-11-04 12:50:15 +00:00
|
|
|
->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 );
|
2019-08-26 13:03:35 +00:00
|
|
|
$body = $messageCache->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.
|
2021-03-30 19:39:34 +00:00
|
|
|
$adminAddress = new MailAddress(
|
2022-04-13 15:28:26 +00:00
|
|
|
$config->get( MainConfigNames::PasswordSender ),
|
2021-03-30 19:39:34 +00:00
|
|
|
wfMessage( 'emailsender' )->inContentLanguage()->text()
|
|
|
|
|
);
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifRevealEditorAddress )
|
2011-10-16 09:53:41 +00:00
|
|
|
&& ( $this->editor->getEmail() != '' )
|
2022-04-29 18:56:13 +00:00
|
|
|
&& $userOptionsLookup->getOption( $this->editor, 'enotifrevealaddr' )
|
2013-12-01 20:39:00 +00:00
|
|
|
) {
|
2014-09-13 03:25:19 +00:00
|
|
|
$editorAddress = MailAddress::newFromUser( $this->editor );
|
2022-04-13 15:28:26 +00:00
|
|
|
if ( $config->get( MainConfigNames::EnotifFromEditor ) ) {
|
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;
|
2021-03-30 19:39:34 +00:00
|
|
|
$this->replyto = new MailAddress(
|
2022-04-13 15:28:26 +00:00
|
|
|
$config->get( MainConfigNames::NoReplyAddress )
|
2021-03-30 19:39:34 +00:00
|
|
|
);
|
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.
|
2021-03-26 01:50:30 +00:00
|
|
|
* @param UserEmailContact $user
|
2015-07-07 18:44:25 +00:00
|
|
|
* @param string $source
|
2019-08-26 13:03:35 +00:00
|
|
|
* @param MessageCache $messageCache
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2021-03-26 01:50:30 +00:00
|
|
|
private function compose( UserEmailContact $user, $source, MessageCache $messageCache ) {
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->composed_common ) {
|
2019-08-26 13:03:35 +00:00
|
|
|
$this->composeCommonMailtext( $messageCache );
|
2013-04-20 22:49:30 +00:00
|
|
|
}
|
2008-12-17 07:08:16 +00:00
|
|
|
|
2022-11-19 22:46:28 +00:00
|
|
|
if ( MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::EnotifImpersonal ) ) {
|
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() {
|
2022-11-19 22:46:28 +00:00
|
|
|
if ( MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::EnotifImpersonal ) ) {
|
2008-12-23 18:08:43 +00:00
|
|
|
$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
|
|
|
*
|
2021-03-26 01:50:30 +00:00
|
|
|
* @param UserEmailContact $watchingUser
|
2015-07-07 18:44:25 +00:00
|
|
|
* @param string $source
|
2020-05-13 03:54:09 +00:00
|
|
|
* @return StatusValue
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2020-05-13 03:54:09 +00:00
|
|
|
private function sendPersonalised( UserEmailContact $watchingUser, $source ): StatusValue {
|
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
|
2021-03-30 19:39:34 +00:00
|
|
|
$mwServices = MediaWikiServices::getInstance();
|
|
|
|
|
$contLang = $mwServices->getContentLanguage();
|
|
|
|
|
$watchingUserName = (
|
2022-04-13 15:28:26 +00:00
|
|
|
$mwServices->getMainConfig()->get( MainConfigNames::EnotifUseRealName ) &&
|
2021-03-30 19:39:34 +00:00
|
|
|
$watchingUser->getRealName() !== ''
|
2021-03-26 01:50:30 +00:00
|
|
|
) ? $watchingUser->getRealName() : $watchingUser->getUser()->getName();
|
2009-08-23 17:48:25 +00:00
|
|
|
$body = str_replace(
|
2021-03-30 19:39:34 +00:00
|
|
|
[
|
|
|
|
|
'$WATCHINGUSERNAME',
|
2009-08-23 17:48:25 +00:00
|
|
|
'$PAGEEDITDATE',
|
2021-03-30 19:39:34 +00:00
|
|
|
'$PAGEEDITTIME'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$watchingUserName,
|
2021-03-26 01:50:30 +00:00
|
|
|
$contLang->userDate( $this->timestamp, $watchingUser->getUser() ),
|
|
|
|
|
$contLang->userTime( $this->timestamp, $watchingUser->getUser() )
|
2021-03-30 19:39:34 +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';
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 03:54:09 +00:00
|
|
|
return $mwServices
|
|
|
|
|
->getEmailer()
|
|
|
|
|
->send(
|
|
|
|
|
[ $to ],
|
|
|
|
|
$this->from,
|
|
|
|
|
$this->subject,
|
|
|
|
|
$body,
|
|
|
|
|
null,
|
|
|
|
|
[
|
|
|
|
|
'replyTo' => $this->replyto,
|
|
|
|
|
'headers' => $headers,
|
|
|
|
|
]
|
|
|
|
|
);
|
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
|
2020-05-13 03:54:09 +00:00
|
|
|
* @return ?StatusValue
|
2008-12-23 18:08:43 +00:00
|
|
|
*/
|
2020-05-13 03:54:09 +00:00
|
|
|
private function sendImpersonal( array $addresses ): ?StatusValue {
|
|
|
|
|
if ( count( $addresses ) === 0 ) {
|
2012-12-09 02:59:04 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2020-05-13 03:54:09 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$contLang = $services->getContentLanguage();
|
2008-12-23 18:08:43 +00:00
|
|
|
$body = str_replace(
|
2021-03-30 19:39:34 +00:00
|
|
|
[
|
|
|
|
|
'$WATCHINGUSERNAME',
|
2014-09-13 02:01:22 +00:00
|
|
|
'$PAGEEDITDATE',
|
2021-03-30 19:39:34 +00:00
|
|
|
'$PAGEEDITTIME'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang->date( $this->timestamp, false, false ),
|
2021-03-30 19:39:34 +00:00
|
|
|
$contLang->time( $this->timestamp, false, false )
|
|
|
|
|
],
|
|
|
|
|
$this->body
|
|
|
|
|
);
|
2008-12-10 06:40:05 +00:00
|
|
|
|
2020-05-13 03:54:09 +00:00
|
|
|
return $services
|
|
|
|
|
->getEmailer()
|
|
|
|
|
->send(
|
|
|
|
|
$addresses,
|
|
|
|
|
$this->from,
|
|
|
|
|
$this->subject,
|
|
|
|
|
$body,
|
|
|
|
|
null,
|
|
|
|
|
[
|
|
|
|
|
'replyTo' => $this->replyto,
|
|
|
|
|
]
|
|
|
|
|
);
|
2008-12-17 07:08:16 +00:00
|
|
|
}
|
2008-12-23 18:08:43 +00:00
|
|
|
|
2014-09-13 02:01:22 +00:00
|
|
|
}
|