4 * @addtogroup SpecialPage
10 require_once('UserMailer.php');
12 function wfSpecialEmailuser( $par ) {
13 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail;
15 if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
16 $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
20 if( !$wgUser->canSendEmail() ) {
21 wfDebug( "User can't send.\n" );
22 $wgOut->showErrorPage( "mailnologin", "mailnologintext" );
26 $action = $wgRequest->getVal( 'action' );
27 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
28 if ( "" == $target ) {
29 wfDebug( "Target is empty.\n" );
30 $wgOut->showErrorPage( "notargettitle", "notargettext" );
34 $nt = Title
::newFromURL( $target );
35 if ( is_null( $nt ) ) {
36 wfDebug( "Target is invalid title.\n" );
37 $wgOut->showErrorPage( "notargettitle", "notargettext" );
41 $nu = User
::newFromName( $nt->getText() );
42 if( is_null( $nu ) ||
!$nu->canReceiveEmail() ) {
43 wfDebug( "Target is invalid user or can't receive.\n" );
44 $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
48 $f = new EmailUserForm( $nu );
50 if ( "success" == $action ) {
51 $f->showSuccess( $nu );
52 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
53 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
62 * @addtogroup SpecialPage
68 var $cc_me; // Whether user requested to be sent a separate copy of their email.
73 function EmailUserForm( $target ) {
75 $this->target
= $target;
76 $this->text
= $wgRequest->getText( 'wpText' );
77 $this->subject
= $wgRequest->getText( 'wpSubject' );
78 $this->cc_me
= $wgRequest->getBool( 'wpCCMe' );
82 global $wgOut, $wgUser;
84 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
85 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
87 if ( $this->subject
=== "" ) {
88 $this->subject
= wfMsg( "defemailsubject" );
91 $emf = wfMsg( "emailfrom" );
92 $sender = $wgUser->getName();
93 $emt = wfMsg( "emailto" );
94 $rcpt = $this->target
->getName();
95 $emr = wfMsg( "emailsubject" );
96 $emm = wfMsg( "emailmessage" );
97 $ems = wfMsg( "emailsend" );
98 $emc = wfMsg( "emailccme" );
99 $encSubject = htmlspecialchars( $this->subject
);
101 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
102 $action = $titleObj->escapeLocalURL( "target=" .
103 urlencode( $this->target
->getName() ) . "&action=submit" );
104 $token = $wgUser->editToken();
107 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
108 <table border='0' id='mailheader'><tr>
109 <td align='right'>{$emf}:</td>
110 <td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
112 <td align='right'>{$emt}:</td>
113 <td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
115 <td align='right'>{$emr}:</td>
117 <input type='text' size='60' maxlength='200' name=\"wpSubject\" value=\"{$encSubject}\" />
121 <span id='wpTextLabel'><label for=\"wpText\">{$emm}:</label><br /></span>
122 <textarea name=\"wpText\" rows='20' cols='80' wrap='virtual' style=\"width: 100%;\">" . htmlspecialchars( $this->text
) .
124 " . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "<br />
125 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
126 <input type='hidden' name='wpEditToken' value=\"$token\" />
131 function doSubmit() {
132 global $wgOut, $wgUser;
134 $to = new MailAddress( $this->target
);
135 $from = new MailAddress( $wgUser );
136 $subject = $this->subject
;
138 if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text
) ) ) {
140 $mailResult = userMailer( $to, $from, $subject, $this->text
);
142 if( WikiError
::isError( $mailResult ) ) {
143 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
146 // if the user requested a copy of this mail, do this now,
147 // unless they are emailing themselves, in which case one copy of the message is sufficient.
148 if ($this->cc_me
&& $to != $from) {
149 $cc_subject = wfMsg('emailccsubject', $this->target
->getName(), $subject);
150 if( wfRunHooks( 'EmailUser', array( &$from, &$from, &$cc_subject, &$this->text
) ) ) {
151 $ccResult = userMailer( $from, $from, $cc_subject, $this->text
);
152 if( WikiError
::isError( $ccResult ) ) {
153 // At this stage, the user's CC mail has failed, but their
154 // original mail has succeeded. It's unlikely, but still, what to do?
155 // We can either show them an error, or we can say everything was fine,
156 // or we can say we sort of failed AND sort of succeeded. Of these options,
157 // simply saying there was an error is probably best.
158 $wgOut->addHTML( wfMsg( "usermailererror" ) . $ccResult);
164 $titleObj = SpecialPage
::getTitleFor( "Emailuser" );
165 $encTarget = wfUrlencode( $this->target
->getName() );
166 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
167 wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $this->text
) );
172 function showSuccess( &$user ) {
175 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
176 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
178 $wgOut->returnToMain( false, $user->getUserPage() );