Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / mail / EmailNotification.php
index 6c9972c..01b6afa 100644 (file)
  * 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,
                ) );
        }