+ protected function userForm( $name ) {
+ global $wgScript;
+ $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) ) .
+ Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
+ Xml::openElement( 'fieldset' ) .
+ Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) .
+ Xml::inputLabel( wfMessage( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' .
+ Xml::submitButton( wfMessage( 'emailusernamesubmit' )->text() ) .
+ Xml::closeElement( 'fieldset' ) .
+ Xml::closeElement( 'form' ) . "\n";
+ return $string;
+ }
+
+ /**
+ * Really send a mail. Permissions should have been checked using
+ * getPermissionsError(). It is probably also a good
+ * idea to check the edit token and ping limiter in advance.
+ *
+ * @return Mixed: Status object, or potentially a String on error
+ * or maybe even true on success if anything uses the EmailUser hook.
+ */
+ public static function submit( $data ) {
+ global $wgUser, $wgUserEmailUseReplyTo;
+
+ $target = self::getTarget( $data['Target'] );
+ if( !$target instanceof User ) {
+ return wfMsgExt( $target . 'text', 'parse' );
+ }
+ $to = new MailAddress( $target );
+ $from = new MailAddress( $wgUser );
+ $subject = $data['Subject'];
+ $text = $data['Text'];
+
+ // Add a standard footer and trim up trailing newlines
+ $text = rtrim( $text ) . "\n\n-- \n";
+ $text .= wfMsgExt(
+ 'emailuserfooter',
+ array( 'content', 'parsemag' ),
+ array( $from->name, $to->name )
+ );
+
+ $error = '';
+ if( !wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$text, &$error ) ) ) {
+ return $error;
+ }
+
+ if( $wgUserEmailUseReplyTo ) {
+ // 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).
+ global $wgPasswordSender, $wgPasswordSenderName;
+ $mailFrom = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
+ $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, $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 = wfMsg(
+ 'emailccsubject',
+ $target->getName(),
+ $subject
+ );
+ wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) );
+ $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text );
+ $status->merge( $ccStatus );
+ }
+
+ wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $text ) );
+ return $status;
+ }