Reedy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/174578

Change subject: Minor refactoring/cleanup and some documentation
......................................................................

Minor refactoring/cleanup and some documentation

Change-Id: Icd0a3a4f3142bcaaeefd64d8c1f5e45c84a182ed
---
M ContactPage_body.php
1 file changed, 31 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContactPage 
refs/changes/78/174578/1

diff --git a/ContactPage_body.php b/ContactPage_body.php
index 54bbbe5..ac04e7d 100644
--- a/ContactPage_body.php
+++ b/ContactPage_body.php
@@ -230,28 +230,35 @@
                $request = $this->getRequest();
                $user = $this->getUser();
 
-               $csender = $config['SenderEmail'] ?: $wgPasswordSender;
-               $cname = $config['SenderName'];
                $senderIP = $request->getIP();
 
-               $contactUser = User::newFromName( $config['RecipientUser'] );
-               $targetAddress = MailAddress::newFromUser( $contactUser );
-               $replyto = null;
-               $contactSender = new MailAddress( $csender, $cname );
+               // Setup user that is going to recieve the contact page response
+               $contactRecipientUser = User::newFromName( 
$config['RecipientUser'] );
+               $contactRecipientAddress = MailAddress::newFromUser( 
$contactRecipientUser );
+
+               // Used when user hasn't set an email, or when sending CC email 
to user
+               $contactSender = new MailAddress(
+                       $config['SenderEmail'] ?: $wgPasswordSender,
+                       $config['SenderName']
+               );
+
+               $replyTo = null;
 
                $fromAddress = $formData['FromAddress'];
                $fromName = $formData['FromName'];
                if ( !$fromAddress ) {
-                       $submitterAddress = $contactSender;
+                       // No email address entered, so use $contactSender 
instead
+                       $senderAddress = $contactSender;
                } else {
-                       $submitterAddress = new MailAddress( $fromAddress, 
$fromName );
+                       // Use user submitted details
+                       $senderAddress = new MailAddress( $fromAddress, 
$fromName );
                        if ( $wgUserEmailUseReplyTo ) {
-                               $replyto = $submitterAddress;
+                               // Define reply-to address
+                               $replyTo = $senderAddress;
                        }
                }
 
                $includeIP = $config['IncludeIP'] && ( $formData['IncludeIP'] 
|| $user->isAnon() );
-               $fromName = $formData['FromName'];
                $subject = $formData['Subject'];
 
                if ( $fromName !== '' ) {
@@ -348,25 +355,26 @@
                        $text .= "{$name}: $value\n";
                }
 
+               /* @var SimpleCaptcha $wgCaptcha */
                if ( $this->useCaptcha() && !$wgCaptcha->passCaptcha() ) {
                        return wfMessage( 'contactpage-captcha-error' 
)->plain();
                }
 
                // Stolen from Special:EmailUser
                $error = '';
-               if ( !wfRunHooks( 'EmailUser', array( &$targetAddress, 
&$submitterAddress, &$subject, &$text, &$error ) ) ) {
+               if ( !wfRunHooks( 'EmailUser', array( 
&$contactRecipientAddress, &$senderAddress, &$subject, &$text, &$error ) ) ) {
                        return $error;
                }
 
-               if( !wfRunHooks( 'ContactForm', array( &$targetAddress, 
&$replyto, &$subject, &$text, $this->formType ) ) ) {
+               if( !wfRunHooks( 'ContactForm', array( 
&$contactRecipientAddress, &$replyTo, &$subject, &$text, $this->formType ) ) ) {
                        return false; // TODO: Need to do some proper error 
handling here
                }
 
-               wfDebug( __METHOD__ . ': sending mail from ' . 
$submitterAddress->toString() .
-                       ' to ' . $targetAddress->toString().
-                       ' replyto ' . ( $replyto == null ? '-/-' : 
$replyto->toString() ) . "\n"
+               wfDebug( __METHOD__ . ': sending mail from ' . 
$senderAddress->toString() .
+                       ' to ' . $contactRecipientAddress->toString().
+                       ' replyto ' . ( $replyTo == null ? '-/-' : 
$replyTo->toString() ) . "\n"
                );
-               $mailResult = UserMailer::send( $targetAddress, 
$submitterAddress, $subject, $text, $replyto );
+               $mailResult = UserMailer::send( $contactRecipientAddress, 
$senderAddress, $subject, $text, $replyTo );
 
                if( !$mailResult->isOK() ) {
                        wfDebug( __METHOD__ . ': got error from UserMailer: ' . 
$mailResult->getMessage() . "\n" );
@@ -376,12 +384,14 @@
                // if the user requested a copy of this mail, do this now,
                // unless they are emailing themselves, in which case one copy 
of the message is sufficient.
                if( $formData['CCme'] && $fromAddress ) {
-                       $cc_subject = wfMessage( 'emailccsubject', 
$contactUser->getName(), $subject )->text();
-                       if( wfRunHooks( 'ContactForm', array( 
&$submitterAddress, &$contactSender, &$cc_subject, &$text, $this->formType ) ) 
) {
+                       $cc_subject = wfMessage( 'emailccsubject', 
$contactRecipientUser->getName(), $subject )->text();
+                       if( wfRunHooks( 'ContactForm',
+                               array( &$senderAddress, &$contactSender, 
&$cc_subject, &$text, $this->formType ) )
+                       ) {
                                wfDebug( __METHOD__ . ': sending cc mail from ' 
. $contactSender->toString() .
-                                       ' to ' . $submitterAddress->toString() 
. "\n"
+                                       ' to ' . $senderAddress->toString() . 
"\n"
                                );
-                               $ccResult = UserMailer::send( 
$submitterAddress, $contactSender, $cc_subject, $text );
+                               $ccResult = UserMailer::send( $senderAddress, 
$contactSender, $cc_subject, $text );
                                if( !$ccResult->isOK() ) {
                                        // At this stage, the user's CC mail 
has failed, but their
                                        // original mail has succeeded. It's 
unlikely, but still, what to do?
@@ -393,7 +403,7 @@
                        }
                }
 
-               wfRunHooks( 'ContactFromComplete', array( $targetAddress, 
$replyto, $subject, $text ) );
+               wfRunHooks( 'ContactFromComplete', array( 
$contactRecipientAddress, $replyTo, $subject, $text ) );
 
                return true;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/174578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd0a3a4f3142bcaaeefd64d8c1f5e45c84a182ed
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContactPage
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to