Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/262589
Change subject: Fix Special:EmailUser
......................................................................
Fix Special:EmailUser
HTMLForm has a little problem, if the form, which submits the page, isn't
present anymore, but another one (it will check the submitcallback for the
second one). This isn't the intended behaviour here, so this needs a little
hack/workaround (because we can't make sure, that the first one is really
posted) with a new, little, hidden field.
Without this change, Special:EmailUser will send an empty e-mail to the
"target" user when the "sending user" uses the user selection field (when
opening Special:EmailUser directly).
Change-Id: I3e0c02155428ae400bc3a6d3ed2e66e69ee441fa
---
M includes/specials/SpecialEmailuser.php
1 file changed, 92 insertions(+), 79 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/89/262589/1
diff --git a/includes/specials/SpecialEmailuser.php
b/includes/specials/SpecialEmailuser.php
index 3aeadc9..b409baf 100644
--- a/includes/specials/SpecialEmailuser.php
+++ b/includes/specials/SpecialEmailuser.php
@@ -277,11 +277,15 @@
$context->setTitle( $this->getPageTitle() ); // Remove subpage
$form = HTMLForm::factory( 'ooui', $this->getFormFields(),
$context );
// By now we are supposed to be sure that $this->mTarget is a
user name
- $form->addPreText( $this->msg( 'emailpagetext', $this->mTarget
)->parse() );
- $form->setSubmitTextMsg( 'emailsend' );
- $form->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) );
- $form->setWrapperLegendMsg( 'email-legend' );
- $form->loadData();
+ $form->addPreText( $this->msg( 'emailpagetext', $this->mTarget
)->parse() )
+ // a little hack, otherwise HTMLForm will think, that
the user (when submitting the
+ // user selection form) submitted this one and sends an
emoty e-mail. The submit call-
+ // back of this form will check this field, so it must
not be set by the first form!
+ ->addHiddenField( 'fromEmailForm', '1' )
+ ->setSubmitTextMsg( 'emailsend' )
+ ->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) )
+ ->setWrapperLegendMsg( 'email-legend' )
+ ->loadData();
if ( !Hooks::run( 'EmailUserForm', array( &$form ) ) ) {
return false;
@@ -321,85 +325,94 @@
*/
public static function submit( array $data, IContextSource $context ) {
$config = $context->getConfig();
+ $request = $context->getRequest();
- $target = self::getTarget( $data['Target'] );
- if ( !$target instanceof User ) {
- // Messages used here: notargettext, noemailtext,
nowikiemailtext
- return $context->msg( $target . 'text'
)->parseAsBlock();
- }
-
- $to = MailAddress::newFromUser( $target );
- $from = MailAddress::newFromUser( $context->getUser() );
- $subject = $data['Subject'];
- $text = $data['Text'];
-
- // Add a standard footer and trim up trailing newlines
- $text = rtrim( $text ) . "\n\n-- \n";
- $text .= $context->msg( 'emailuserfooter',
- $from->name, $to->name )->inContentLanguage()->text();
-
- $error = '';
- if ( !Hooks::run( 'EmailUser', array( &$to, &$from, &$subject,
&$text, &$error ) ) ) {
- return $error;
- }
-
- if ( $config->get( 'UserEmailUseReplyTo' ) ) {
- /**
- * Put the generic wiki autogenerated address in the
From:
- * header and reserve the user for Reply-To.
- *
- * This is a bit ugly, but will serve to differentiate
- * wiki-borne mails from direct mails and protects
against
- * SPF and bounce problems with some mailers (see
below).
- */
- $mailFrom = new MailAddress( $config->get(
'PasswordSender' ),
- wfMessage( 'emailsender'
)->inContentLanguage()->text() );
- $replyTo = $from;
- } else {
- /**
- * Put the sending user's e-mail address in the From:
header.
- *
- * This is clean-looking and convenient, but has issues.
- * One is that it doesn't as clearly differentiate the
wiki mail
- * from "directly" sent mails.
- *
- * Another is that some mailers (like sSMTP) will use
the From
- * address as the envelope sender as well. For open
sites this
- * can cause mails to be flunked for SPF violations
(since the
- * wiki server isn't an authorized sender for various
users'
- * domains) as well as creating a privacy issue as
bounces
- * containing the recipient's e-mail address may get
sent to
- * the sending user.
- */
- $mailFrom = $from;
- $replyTo = null;
- }
-
- $status = UserMailer::send( $to, $mailFrom, $subject, $text,
array(
- 'replyTo' => $replyTo,
- ) );
-
- if ( !$status->isGood() ) {
- return $status;
- } else {
- // 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 ( $data['CCMe'] && $to != $from ) {
- $cc_subject = $context->msg( 'emailccsubject'
)->rawParams(
- $target->getName(), $subject )->text();
-
- // target and sender are equal, because this is
the CC for the sender
- Hooks::run( 'EmailUserCC', array( &$from,
&$from, &$cc_subject, &$text ) );
-
- $ccStatus = UserMailer::send( $from, $from,
$cc_subject, $text );
- $status->merge( $ccStatus );
+ // This is a hidden field, set to 1, which is sent by the
UserEmailForm only, not
+ // by the UserSelectionForm. This is used to make sure, that we
send an e-mail only,
+ // if the user submits the second (UserEmailForm) form.
+ if ( $request->getBool( 'fromEmailForm' ) ) {
+ $target = self::getTarget( $data['Target'] );
+ if ( !$target instanceof User ) {
+ // Messages used here: notargettext,
noemailtext, nowikiemailtext
+ return $context->msg( $target . 'text'
)->parseAsBlock();
}
- Hooks::run( 'EmailUserComplete', array( $to, $from,
$subject, $text ) );
+ $to = MailAddress::newFromUser( $target );
+ $from = MailAddress::newFromUser( $context->getUser() );
+ $subject = $data['Subject'];
+ $text = $data['Text'];
- return $status;
+ // Add a standard footer and trim up trailing newlines
+ $text = rtrim( $text ) . "\n\n-- \n";
+ $text .= $context->msg( 'emailuserfooter',
+ $from->name, $to->name
)->inContentLanguage()->text();
+
+ $error = '';
+ if ( !Hooks::run( 'EmailUser', array( &$to, &$from,
&$subject, &$text, &$error ) ) ) {
+ return $error;
+ }
+
+ if ( $config->get( 'UserEmailUseReplyTo' ) ) {
+ /**
+ * Put the generic wiki autogenerated address
in the From:
+ * header and reserve the user for Reply-To.
+ *
+ * This is a bit ugly, but will serve to
differentiate
+ * wiki-borne mails from direct mails and
protects against
+ * SPF and bounce problems with some mailers
(see below).
+ */
+ $mailFrom = new MailAddress( $config->get(
'PasswordSender' ),
+ wfMessage( 'emailsender'
)->inContentLanguage()->text() );
+ $replyTo = $from;
+ } else {
+ /**
+ * Put the sending user's e-mail address in the
From: header.
+ *
+ * This is clean-looking and convenient, but
has issues.
+ * One is that it doesn't as clearly
differentiate the wiki mail
+ * from "directly" sent mails.
+ *
+ * Another is that some mailers (like sSMTP)
will use the From
+ * address as the envelope sender as well. For
open sites this
+ * can cause mails to be flunked for SPF
violations (since the
+ * wiki server isn't an authorized sender for
various users'
+ * domains) as well as creating a privacy issue
as bounces
+ * containing the recipient's e-mail address
may get sent to
+ * the sending user.
+ */
+ $mailFrom = $from;
+ $replyTo = null;
+ }
+
+ $status = UserMailer::send( $to, $mailFrom, $subject,
$text, array(
+ 'replyTo' => $replyTo,
+ ) );
+
+ if ( !$status->isGood() ) {
+ return $status;
+ } else {
+ // 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 ( $data['CCMe'] && $to != $from ) {
+ $cc_subject = $context->msg(
'emailccsubject' )->rawParams(
+ $target->getName(), $subject
)->text();
+
+ // target and sender are equal, because
this is the CC for the sender
+ Hooks::run( 'EmailUserCC', array(
&$from, &$from, &$cc_subject, &$text ) );
+
+ $ccStatus = UserMailer::send( $from,
$from, $cc_subject, $text );
+ $status->merge( $ccStatus );
+ }
+
+ Hooks::run( 'EmailUserComplete', array( $to,
$from, $subject, $text ) );
+
+ return $status;
+ }
}
+
+ // show the form again, without any error message
+ return false;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/262589
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e0c02155428ae400bc3a6d3ed2e66e69ee441fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits