Clean up UserMailer::send() parameters
authorKunal Mehta <legoktm@gmail.com>
Sun, 12 Jul 2015 05:07:18 +0000 (22:07 -0700)
committerKunal Mehta <legoktm@gmail.com>
Tue, 21 Jul 2015 04:34:44 +0000 (21:34 -0700)
$replyto and $contentType should now be passed as an array of $options.
This will make it easier to add more options in the future without
having a long list of optional parameters.

Change-Id: I2c38bb438bd01e0ed2552024a40311f3e8e2dc08

includes/User.php
includes/jobqueue/jobs/EmaillingJob.php
includes/mail/EmailNotification.php
includes/mail/UserMailer.php
includes/specials/SpecialEmailuser.php

index d627a6d..4c044bd 100644 (file)
@@ -4252,7 +4252,9 @@ class User implements IDBAccessObject {
                }
                $to = MailAddress::newFromUser( $this );
 
-               return UserMailer::send( $to, $sender, $subject, $body, $replyto );
+               return UserMailer::send( $to, $sender, $subject, $body, array(
+                       'replyTo' => $replyto,
+               ) );
        }
 
        /**
index 68e96fc..beeb067 100644 (file)
@@ -38,7 +38,7 @@ class EmaillingJob extends Job {
                        $this->params['from'],
                        $this->params['subj'],
                        $this->params['body'],
-                       $this->params['replyto']
+                       array( 'replyTo' => $this->params['replyto'] )
                );
 
                return $status->isOK();
index 1027732..0eed450 100644 (file)
@@ -478,7 +478,9 @@ class EmailNotification {
                                $wgContLang->userTime( $this->timestamp, $watchingUser ) ),
                        $this->body );
 
-               return UserMailer::send( $to, $this->from, $this->subject, $body, $this->replyto );
+               return UserMailer::send( $to, $this->from, $this->subject, $body, array(
+                       'replyTo' => $this->replyto,
+               ) );
        }
 
        /**
@@ -503,7 +505,9 @@ class EmailNotification {
                                $wgContLang->time( $this->timestamp, false, false ) ),
                        $this->body );
 
-               return UserMailer::send( $addresses, $this->from, $this->subject, $body, $this->replyto );
+               return UserMailer::send( $addresses, $this->from, $this->subject, $body, array(
+                       'replyTo' => $this->replyto,
+               ) );
        }
 
 }
index 546cc8c..d83ae93 100644 (file)
@@ -102,16 +102,32 @@ class UserMailer {
         * @param MailAddress $from Sender's email
         * @param string $subject Email's subject.
         * @param string $body Email's text or Array of two strings to be the text and html bodies
-        * @param MailAddress $replyto Optional reply-to email (default: null).
-        * @param string $contentType Optional custom Content-Type (default: text/plain; charset=UTF-8)
+        * @param array $options:
+        *              'replyTo' MailAddress
+        *              'contentType' string default 'text/plain; charset=UTF-8'
+        *
+        * 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.
+        *
         * @throws MWException
         * @throws Exception
         * @return Status
         */
-       public static function send( $to, $from, $subject, $body, $replyto = null,
-               $contentType = 'text/plain; charset=UTF-8'
-       ) {
+       public static function send( $to, $from, $subject, $body, $options = array() ) {
                global $wgSMTP, $wgEnotifMaxRecips, $wgAdditionalMailParams, $wgAllowHTMLEmail;
+               $contentType = 'text/plain; charset=UTF-8';
+               if ( is_array( $options ) ) {
+                       $replyto = isset( $options['replyTo'] ) ? $options['replyTo'] : null;
+                       $contentType = isset( $options['contentType'] ) ? $options['contentType'] : $contentType;
+               } else {
+                       // Old calling style
+                       wfDeprecated( __METHOD__ . ' with $replyto as 5th parameter', '1.26' );
+                       $replyto = $options;
+                       if ( func_num_args() === 6 ) {
+                               $contentType = func_get_arg( 5 );
+                       }
+               }
+
                $mime = null;
                if ( !is_array( $to ) ) {
                        $to = array( $to );
index c55fa94..1754471 100644 (file)
@@ -356,7 +356,9 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        $replyTo = null;
                }
 
-               $status = UserMailer::send( $to, $mailFrom, $subject, $text, $replyTo );
+               $status = UserMailer::send( $to, $mailFrom, $subject, $text, array(
+                       'replyTo' => $replyTo,
+               ) );
 
                if ( !$status->isGood() ) {
                        return $status;