3f55d0ebf2bdad42f8170485b19f695265e2ce93
10 function wfSpecialEmailuser( $par ) {
11 global $wgRequest, $wgUser, $wgOut;
13 $action = $wgRequest->getVal( 'action' );
14 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
15 $targetUser = EmailUserForm
::validateEmailTarget( $target );
17 if ( !( $targetUser instanceof User
) ) {
18 $wgOut->showErrorPage( $targetUser[0], $targetUser[1] );
22 $form = new EmailUserForm( $targetUser,
23 $wgRequest->getText( 'wpText' ),
24 $wgRequest->getText( 'wpSubject' ),
25 $wgRequest->getBool( 'wpCCMe' ) );
26 if ( $action == 'success' ) {
31 $error = EmailUserForm
::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) );
33 switch ( $error[0] ) {
34 case 'blockedemailuser':
35 $wgOut->blockedPage();
37 case 'actionthrottledtext':
38 $wgOut->rateLimited();
40 case 'sessionfailure':
44 $wgOut->showErrorPage( $error[0], $error[1] );
50 if ( "submit" == $action && $wgRequest->wasPosted() ) {
51 $result = $form->doSubmit();
53 if ( !is_null( $result ) ) {
54 $wgOut->addHTML( wfMsg( "usermailererror" ) .
55 ' ' . htmlspecialchars( $result->getMessage() ) );
57 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
58 $encTarget = wfUrlencode( $form->getTarget()->getName() );
59 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
67 * Implements the Special:Emailuser web interface, and invokes userMailer for sending the email message.
68 * @ingroup SpecialPage
74 var $cc_me; // Whether user requested to be sent a separate copy of their email.
79 function EmailUserForm( $target, $text, $subject, $cc_me ) {
80 $this->target
= $target;
82 $this->subject
= $subject;
83 $this->cc_me
= $cc_me;
87 global $wgOut, $wgUser;
88 $skin = $wgUser->getSkin();
90 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
91 $wgOut->addWikiMsg( "emailpagetext" );
93 if ( $this->subject
=== "" ) {
94 $this->subject
= wfMsgForContent( "defemailsubject" );
97 $emf = wfMsg( "emailfrom" );
98 $senderLink = $skin->makeLinkObj(
99 $wgUser->getUserPage(), htmlspecialchars( $wgUser->getName() ) );
100 $emt = wfMsg( "emailto" );
101 $recipientLink = $skin->makeLinkObj(
102 $this->target
->getUserPage(), htmlspecialchars( $this->target
->getName() ) );
103 $emr = wfMsg( "emailsubject" );
104 $emm = wfMsg( "emailmessage" );
105 $ems = wfMsg( "emailsend" );
106 $emc = wfMsg( "emailccme" );
107 $encSubject = htmlspecialchars( $this->subject
);
109 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
110 $action = $titleObj->escapeLocalURL( "target=" .
111 urlencode( $this->target
->getName() ) . "&action=submit" );
112 $token = htmlspecialchars( $wgUser->editToken() );
115 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
116 <table border='0' id='mailheader'><tr>
117 <td align='right'>{$emf}:</td>
118 <td align='left'><strong>{$senderLink}</strong></td>
120 <td align='right'>{$emt}:</td>
121 <td align='left'><strong>{$recipientLink}</strong></td>
123 <td align='right'>{$emr}:</td>
125 <input type='text' size='60' maxlength='200' name=\"wpSubject\" value=\"{$encSubject}\" />
129 <span id='wpTextLabel'><label for=\"wpText\">{$emm}:</label><br /></span>
130 <textarea id=\"wpText\" name=\"wpText\" rows='20' cols='80' style=\"width: 100%;\">" . htmlspecialchars( $this->text
) .
132 " . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "<br />
133 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
134 <input type='hidden' name='wpEditToken' value=\"$token\" />
140 * Really send a mail. Permissions should have been checked using
141 * EmailUserForm::getPermissionsError. It is probably also a good idea to
142 * check the edit token and ping limiter in advance.
144 function doSubmit() {
145 global $wgUser, $wgUserEmailUseReplyTo, $wgSiteName;
147 $to = new MailAddress( $this->target
);
148 $from = new MailAddress( $wgUser );
149 $subject = $this->subject
;
151 $prefsTitle = Title
::newFromText( 'Preferences', NS_SPECIAL
);
152 $emailTitle = Title
::newFromText( 'Emailuser', NS_SPECIAL
);
154 // Add a standard footer
155 $footerArgs[0] = $wgSitename;
156 $footerArgs[1] = $from->name
;
157 $footerArgs[2] = $to->name
;
158 $footerArgs[3] = $prefsTitle->getFullURL();
159 $footerArgs[4] = $emailTitle->getFullURL() . '/' . urlencode( $from->name
); // Url to Special:Emailuser/Username
160 $this->text
= $this->text
. "\n" . wfMsg( 'emailuserfooter', $footerArgs );
162 if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text
) ) ) {
164 if( $wgUserEmailUseReplyTo ) {
165 // Put the generic wiki autogenerated address in the From:
166 // header and reserve the user for Reply-To.
168 // This is a bit ugly, but will serve to differentiate
169 // wiki-borne mails from direct mails and protects against
170 // SPF and bounce problems with some mailers (see below).
171 global $wgPasswordSender;
172 $mailFrom = new MailAddress( $wgPasswordSender );
175 // Put the sending user's e-mail address in the From: header.
177 // This is clean-looking and convenient, but has issues.
178 // One is that it doesn't as clearly differentiate the wiki mail
179 // from "directly" sent mails.
181 // Another is that some mailers (like sSMTP) will use the From
182 // address as the envelope sender as well. For open sites this
183 // can cause mails to be flunked for SPF violations (since the
184 // wiki server isn't an authorized sender for various users'
185 // domains) as well as creating a privacy issue as bounces
186 // containing the recipient's e-mail address may get sent to
192 $mailResult = UserMailer
::send( $to, $mailFrom, $subject, $this->text
, $replyTo );
194 if( WikiError
::isError( $mailResult ) ) {
199 // if the user requested a copy of this mail, do this now,
200 // unless they are emailing themselves, in which case one copy of the message is sufficient.
201 if ($this->cc_me
&& $to != $from) {
202 $cc_subject = wfMsg('emailccsubject', $this->target
->getName(), $subject);
203 if( wfRunHooks( 'EmailUser', array( &$from, &$from, &$cc_subject, &$this->text
) ) ) {
204 $ccResult = UserMailer
::send( $from, $from, $cc_subject, $this->text
);
205 if( WikiError
::isError( $ccResult ) ) {
206 // At this stage, the user's CC mail has failed, but their
207 // original mail has succeeded. It's unlikely, but still, what to do?
208 // We can either show them an error, or we can say everything was fine,
209 // or we can say we sort of failed AND sort of succeeded. Of these options,
210 // simply saying there was an error is probably best.
216 wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $this->text
) );
222 function showSuccess( &$user = null ) {
225 if ( is_null($user) )
226 $user = $this->target
;
228 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
229 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
231 $wgOut->returnToMain( false, $user->getUserPage() );
234 function getTarget() {
235 return $this->target
;
238 static function validateEmailTarget ( $target ) {
239 global $wgEnableEmail, $wgEnableUserEmail;
241 if( !( $wgEnableEmail && $wgEnableUserEmail ) )
242 return array( "nosuchspecialpage", "nospecialpagetext" );
244 if ( "" == $target ) {
245 wfDebug( "Target is empty.\n" );
246 return array( "notargettitle", "notargettext" );
249 $nt = Title
::newFromURL( $target );
250 if ( is_null( $nt ) ) {
251 wfDebug( "Target is invalid title.\n" );
252 return array( "notargettitle", "notargettext" );
255 $nu = User
::newFromName( $nt->getText() );
256 if( is_null( $nu ) ||
!$nu->canReceiveEmail() ) {
257 wfDebug( "Target is invalid user or can't receive.\n" );
258 return array( "noemailtitle", "noemailtext" );
263 static function getPermissionsError ( $user, $editToken ) {
264 if( !$user->canSendEmail() ) {
265 wfDebug( "User can't send.\n" );
266 return array( "mailnologin", "mailnologintext" );
269 if( $user->isBlockedFromEmailuser() ) {
270 wfDebug( "User is blocked from sending e-mail.\n" );
271 return array( "blockedemailuser", "" );
274 if( $user->pingLimiter( 'emailuser' ) ) {
275 wfDebug( "Ping limiter triggered.\n" );
276 return array( 'actionthrottledtext', '' );
279 if( !$user->matchEditToken( $editToken ) ) {
280 wfDebug( "Matching edit token failed.\n" );
281 return array( 'sessionfailure', '' );
287 static function newFromURL( $target, $text, $subject, $cc_me )
289 $nt = Title
::newFromURL( $target );
290 $nu = User
::newFromName( $nt->getText() );
291 return new EmailUserForm( $nu, $text, $subject, $cc_me );