aboutsummaryrefslogtreecommitdiffstats
path: root/includes/mail
diff options
context:
space:
mode:
authorPetr Pchelko <ppchelko@wikimedia.org>2021-03-25 19:50:30 -0600
committerPetr Pchelko <ppchelko@wikimedia.org>2021-04-01 15:46:09 -0600
commitc621548cf81ac23faa15787167927669b4204b9b (patch)
tree1c8a8ef9d63dff4b5eef1b4e4628ab99ba02ecbd /includes/mail
parentc44d44639b14bfb6286b2ed1e4cba8a8477945b4 (diff)
downloadmediawikicore-c621548cf81ac23faa15787167927669b4204b9b.tar.gz
mediawikicore-c621548cf81ac23faa15787167927669b4204b9b.zip
Convert mail namespace to Authority/UserIdentity
Change-Id: I1e1ea72f94735ddaf66eab29aad1296e1abffb9b
Diffstat (limited to 'includes/mail')
-rw-r--r--includes/mail/EmailNotification.php53
-rw-r--r--includes/mail/MailAddress.php10
-rw-r--r--includes/mail/UserEmailContact.php40
3 files changed, 72 insertions, 31 deletions
diff --git a/includes/mail/EmailNotification.php b/includes/mail/EmailNotification.php
index 83c2da9dd7c1..0e532dc3527d 100644
--- a/includes/mail/EmailNotification.php
+++ b/includes/mail/EmailNotification.php
@@ -24,7 +24,10 @@
* @author Luke Welling lwelling@wikimedia.org
*/
+use MediaWiki\Mail\UserEmailContact;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Permissions\Authority;
+use MediaWiki\User\UserIdentity;
/**
* This module processes the email notifications when the current page is
@@ -120,7 +123,7 @@ class EmailNotification {
*
* May be deferred via the job queue.
*
- * @param User $editor
+ * @param Authority $editor
* @param Title $title
* @param string $timestamp
* @param string $summary
@@ -131,7 +134,7 @@ class EmailNotification {
* @since 1.35 returns a boolean indicating whether an email job was created.
*/
public function notifyOnPageChange(
- $editor,
+ Authority $editor,
$title,
$timestamp,
$summary,
@@ -150,7 +153,7 @@ class EmailNotification {
$watchers = [];
if ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) {
$watchers = $mwServices->getWatchedItemStore()->updateNotificationTimestamp(
- $editor,
+ $editor->getUser(),
$title,
$timestamp
);
@@ -165,14 +168,12 @@ class EmailNotification {
$sendEmail = false;
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
if ( !$minorEdit ||
- ( $config->get( 'EnotifMinorEdits' ) && !$mwServices->getPermissionManager()
- ->userHasRight( $editor, 'nominornewtalk' )
- )
+ ( $config->get( 'EnotifMinorEdits' ) && !$editor->isAllowed( 'nominornewtalk' ) )
) {
$isUserTalkPage = ( $title->getNamespace() === NS_USER_TALK );
if ( $config->get( 'EnotifUserTalk' )
&& $isUserTalkPage
- && $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
+ && $this->canSendUserTalkEmail( $editor->getUser(), $title, $minorEdit )
) {
$sendEmail = true;
}
@@ -183,8 +184,8 @@ class EmailNotification {
JobQueueGroup::singleton()->lazyPush( new EnotifNotifyJob(
$title,
[
- 'editor' => $editor->getName(),
- 'editorID' => $editor->getId(),
+ 'editor' => $editor->getUser()->getName(),
+ 'editorID' => $editor->getUser()->getId(),
'timestamp' => $timestamp,
'summary' => $summary,
'minorEdit' => $minorEdit,
@@ -204,7 +205,7 @@ class EmailNotification {
* Send emails corresponding to the user $editor editing the page $title.
*
* @note Do not call directly. Use notifyOnPageChange so that wl_notificationtimestamp is updated.
- * @param User $editor
+ * @param Authority $editor
* @param Title $title
* @param string $timestamp Edit timestamp
* @param string $summary Edit summary
@@ -215,7 +216,7 @@ class EmailNotification {
* @throws MWException
*/
public function actuallyNotifyOnPageChange(
- $editor,
+ Authority $editor,
$title,
$timestamp,
$summary,
@@ -241,7 +242,7 @@ class EmailNotification {
$this->summary = $summary;
$this->minorEdit = $minorEdit;
$this->oldid = $oldid;
- $this->editor = $editor;
+ $this->editor = MediaWikiServices::getInstance()->getUserFactory()->newFromAuthority( $editor );
$this->composed_common = false;
$this->pageStatus = $pageStatus;
@@ -255,13 +256,11 @@ class EmailNotification {
$userTalkId = false;
if ( !$minorEdit ||
- ( $config->get( 'EnotifMinorEdits' ) && !$mwServices->getPermissionManager()
- ->userHasRight( $editor, 'nominornewtalk' )
- )
+ ( $config->get( 'EnotifMinorEdits' ) && !$editor->isAllowed( 'nominornewtalk' ) )
) {
if ( $config->get( 'EnotifUserTalk' )
&& $isUserTalkPage
- && $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
+ && $this->canSendUserTalkEmail( $editor->getUser(), $title, $minorEdit )
) {
$targetUser = User::newFromName( $title->getText() );
$this->compose( $targetUser, self::USER_TALK, $messageCache );
@@ -290,7 +289,7 @@ class EmailNotification {
}
foreach ( $config->get( 'UsersNotifiedOnAllChanges' ) as $name ) {
- if ( $editor->getName() == $name ) {
+ if ( $editor->getUser()->getName() == $name ) {
// No point notifying the user that actually made the change!
continue;
}
@@ -302,12 +301,12 @@ class EmailNotification {
}
/**
- * @param User $editor
+ * @param UserIdentity $editor
* @param Title $title
* @param bool $minorEdit
* @return bool
*/
- private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
+ private function canSendUserTalkEmail( UserIdentity $editor, $title, $minorEdit ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$isUserTalkPage = ( $title->getNamespace() === NS_USER_TALK );
@@ -393,7 +392,7 @@ class EmailNotification {
'';
$keys['$UNWATCHURL'] = $this->title->getCanonicalURL( 'action=unwatch' );
- if ( $this->editor->isAnon() ) {
+ if ( !$this->editor->isRegistered() ) {
# real anon (user:xxx.xxx.xxx.xxx)
$keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
->inContentLanguage()->text();
@@ -466,11 +465,11 @@ class EmailNotification {
* depending on settings.
*
* Call sendMails() to send any mails that were queued.
- * @param User $user
+ * @param UserEmailContact $user
* @param string $source
* @param MessageCache $messageCache
*/
- private function compose( $user, $source, MessageCache $messageCache ) {
+ private function compose( UserEmailContact $user, $source, MessageCache $messageCache ) {
if ( !$this->composed_common ) {
$this->composeCommonMailtext( $messageCache );
}
@@ -497,11 +496,11 @@ class EmailNotification {
* Returns Status if email was sent successfully or not (Status::newGood()
* or Status::newFatal() respectively).
*
- * @param User $watchingUser
+ * @param UserEmailContact $watchingUser
* @param string $source
* @return Status
*/
- private function sendPersonalised( $watchingUser, $source ) {
+ private function sendPersonalised( UserEmailContact $watchingUser, $source ) {
// From the PHP manual:
// Note: The to parameter cannot be an address in the form of
// "Something <someone@example.com>". The mail command will not parse
@@ -516,7 +515,7 @@ class EmailNotification {
$watchingUserName = (
$mwServices->getMainConfig()->get( 'EnotifUseRealName' ) &&
$watchingUser->getRealName() !== ''
- ) ? $watchingUser->getRealName() : $watchingUser->getName();
+ ) ? $watchingUser->getRealName() : $watchingUser->getUser()->getName();
$body = str_replace(
[
'$WATCHINGUSERNAME',
@@ -525,8 +524,8 @@ class EmailNotification {
],
[
$watchingUserName,
- $contLang->userDate( $this->timestamp, $watchingUser ),
- $contLang->userTime( $this->timestamp, $watchingUser )
+ $contLang->userDate( $this->timestamp, $watchingUser->getUser() ),
+ $contLang->userTime( $this->timestamp, $watchingUser->getUser() )
],
$this->body
);
diff --git a/includes/mail/MailAddress.php b/includes/mail/MailAddress.php
index bf64e02506e1..f6a2fca45dbb 100644
--- a/includes/mail/MailAddress.php
+++ b/includes/mail/MailAddress.php
@@ -24,6 +24,8 @@
* @author Luke Welling lwelling@wikimedia.org
*/
+use MediaWiki\Mail\UserEmailContact;
+
/**
* Stores a single person's name and email address.
* These are passed in via the constructor, and will be returned in SMTP
@@ -63,12 +65,12 @@ class MailAddress {
/**
* Create a new MailAddress object for the given user
*
- * @since 1.24
- * @param User $user
+ * @param UserEmailContact $user
* @return MailAddress
+ * @since 1.24
*/
- public static function newFromUser( User $user ) {
- return new MailAddress( $user->getEmail(), $user->getName(), $user->getRealName() );
+ public static function newFromUser( UserEmailContact $user ) {
+ return new MailAddress( $user->getEmail(), $user->getUser()->getName(), $user->getRealName() );
}
/**
diff --git a/includes/mail/UserEmailContact.php b/includes/mail/UserEmailContact.php
new file mode 100644
index 000000000000..32de48f8de1d
--- /dev/null
+++ b/includes/mail/UserEmailContact.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace MediaWiki\Mail;
+
+use MediaWiki\User\UserIdentity;
+
+/**
+ * @since 1.36
+ * @package MediaWiki\Mail
+ */
+interface UserEmailContact {
+
+ /**
+ * Get the identity of the user this contact belongs to.
+ *
+ * @return UserIdentity
+ */
+ public function getUser(): UserIdentity;
+
+ /**
+ * Get user email address an empty string if unknown.
+ *
+ * @return string
+ */
+ public function getEmail(): string;
+
+ /**
+ * Get user real name or an empty string if unknown.
+ *
+ * @return string
+ */
+ public function getRealName(): string;
+
+ /**
+ * Whether user email was confirmed.
+ *
+ * @return bool
+ */
+ public function isEmailConfirmed(): bool;
+}