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
This commit is contained in:
parent
d1b1b12dac
commit
4e09a3e903
2 changed files with 31 additions and 6 deletions
|
|
@ -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,
|
||||
) );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
|
|
|
|||
Loading…
Reference in a new issue