From: Kunal Mehta Date: Tue, 7 Jul 2015 18:44:25 +0000 (-0700) Subject: Set 'List-Help' header for watchlist emails X-Git-Tag: 1.31.0-rc.0~10348^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=4e09a3e9030c89d0d98f668e62b115abec167a73;p=lhc%2Fweb%2Fwiklou.git Set 'List-Help' header for watchlist emails Added an option to UserMailer::sendMail() to allow adding arbitrary headers to emails. Bug: T58315 Change-Id: I01a60430bf39f6bd104269b7246767f016eb9cd5 --- diff --git a/includes/mail/EmailNotification.php b/includes/mail/EmailNotification.php index 6c9972c8de..01b6afab40 100644 --- a/includes/mail/EmailNotification.php +++ b/includes/mail/EmailNotification.php @@ -43,6 +43,20 @@ * Visit the documentation pages under http://meta.wikipedia.com/Enotif */ class EmailNotification { + + /** + * 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'; + protected $subject, $body, $replyto, $from; protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus; protected $mailTargets = array(); @@ -236,7 +250,7 @@ class EmailNotification { && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) { $targetUser = User::newFromName( $title->getText() ); - $this->compose( $targetUser ); + $this->compose( $targetUser, self::USER_TALK ); $userTalkId = $targetUser->getId(); } @@ -252,7 +266,7 @@ class EmailNotification { && !( $wgBlockDisablesLogin && $watchingUser->isBlocked() ) ) { if ( Hooks::run( 'SendWatchlistEmailNotification', array( $watchingUser, $title, $this ) ) ) { - $this->compose( $watchingUser ); + $this->compose( $watchingUser, self::WATCHLIST ); } } } @@ -266,7 +280,7 @@ class EmailNotification { continue; } $user = User::newFromName( $name ); - $this->compose( $user ); + $this->compose( $user, self::ALL_CHANGES ); } $this->sendMails(); @@ -427,8 +441,9 @@ class EmailNotification { * * Call sendMails() to send any mails that were queued. * @param User $user + * @param string $source */ - function compose( $user ) { + function compose( $user, $source ) { global $wgEnotifImpersonal; if ( !$this->composed_common ) { @@ -438,7 +453,7 @@ class EmailNotification { if ( $wgEnotifImpersonal ) { $this->mailTargets[] = MailAddress::newFromUser( $user ); } else { - $this->sendPersonalised( $user ); + $this->sendPersonalised( $user, $source ); } } @@ -458,10 +473,11 @@ class EmailNotification { * Returns true if the mail was sent successfully. * * @param User $watchingUser + * @param string $source * @return bool * @private */ - function sendPersonalised( $watchingUser ) { + function sendPersonalised( $watchingUser, $source ) { global $wgContLang, $wgEnotifUseRealName; // From the PHP manual: // Note: The to parameter cannot be an address in the form of @@ -482,8 +498,14 @@ class EmailNotification { $wgContLang->userTime( $this->timestamp, $watchingUser ) ), $this->body ); + $headers = array(); + if ( $source === self::WATCHLIST ) { + $headers['List-Help'] = 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Watchlist'; + } + return UserMailer::send( $to, $this->from, $this->subject, $body, array( 'replyTo' => $this->replyto, + 'headers' => $headers, ) ); } diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php index bf4b96b7a6..7c5f18dd5f 100644 --- a/includes/mail/UserMailer.php +++ b/includes/mail/UserMailer.php @@ -105,6 +105,7 @@ class UserMailer { * @param array $options: * 'replyTo' MailAddress * 'contentType' string default 'text/plain; charset=UTF-8' + * 'headers' array Extra headers to set * * Previous versions of this function had $replyto as the 5th argument and $contentType * as the 6th. These are still supported for backwards compatability, but deprecated. @@ -116,9 +117,11 @@ class UserMailer { public static function send( $to, $from, $subject, $body, $options = array() ) { global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail; $contentType = 'text/plain; charset=UTF-8'; + $headers = array(); if ( is_array( $options ) ) { $replyto = isset( $options['replyTo'] ) ? $options['replyTo'] : null; $contentType = isset( $options['contentType'] ) ? $options['contentType'] : $contentType; + $headers = isset( $options['headers'] ) ? $options['headers'] : $headers; } else { // Old calling style wfDeprecated( __METHOD__ . ' with $replyto as 5th parameter', '1.26' );