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