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->errorpage( "nosuchspecialpage", "nospecialpagetext" );
21 if( !$wgUser->canSendEmail() ) {
22 wfDebug( "User can't send.\n" );
23 $wgOut->errorpage( "mailnologin", "mailnologintext" );
27 $action = $wgRequest->getVal( 'action' );
29 $target = $wgRequest->getVal( 'target' );
33 if ( "" == $target ) {
34 wfDebug( "Target is empty.\n" );
35 $wgOut->errorpage( "notargettitle", "notargettext" );
39 $nt = Title
::newFromURL( $target );
40 if ( is_null( $nt ) ) {
41 wfDebug( "Target is invalid title.\n" );
42 $wgOut->errorpage( "notargettitle", "notargettext" );
46 $nu = User
::newFromName( $nt->getText() );
47 if( is_null( $nu ) ||
!$nu->canReceiveEmail() ) {
48 wfDebug( "Target is invalid user or can't receive.\n" );
49 $wgOut->errorpage( "noemailtitle", "noemailtext" );
53 $address = $nu->getEmail();
54 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
56 if ( "success" == $action ) {
58 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
59 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
69 * @subpackage SpecialPage
77 function EmailUserForm( $addr, $target ) {
79 $this->mAddress
= $addr;
80 $this->target
= $target;
81 $this->text
= $wgRequest->getText( 'wpText' );
82 $this->subject
= $wgRequest->getText( 'wpSubject' );
86 global $wgOut, $wgUser, $wgLang;
88 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
89 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
91 if ( $this->subject
=== "" ) {
92 $this->subject
= wfMsg( "defemailsubject" );
95 $emf = wfMsg( "emailfrom" );
96 $sender = $wgUser->getName();
97 $emt = wfMsg( "emailto" );
98 $rcpt = str_replace( "_", " ", $this->target
);
99 $emr = wfMsg( "emailsubject" );
100 $emm = wfMsg( "emailmessage" );
101 $ems = wfMsg( "emailsend" );
102 $encSubject = htmlspecialchars( $this->subject
);
104 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
105 $action = $titleObj->escapeLocalURL( "target=" .
106 urlencode( $this->target
) . "&action=submit" );
107 $token = $wgUser->editToken();
110 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
111 <table border='0'><tr>
112 <td align='right'>{$emf}:</td>
113 <td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
115 <td align='right'>{$emt}:</td>
116 <td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
118 <td align='right'>{$emr}:</td>
120 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
123 <td align='right'>{$emm}:</td>
125 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text
) .
128 <td> </td><td align='left'>
129 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
131 <input type='hidden' name='wpEditToken' value=\"$token\" />
136 function doSubmit() {
137 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
139 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
140 $subject = wfQuotedPrintable( $this->subject
);
142 if (wfRunHooks('EmailUser', array(&$this->mAddress
, &$from, &$subject, &$this->text
))) {
144 $mailResult = userMailer( $this->mAddress
, $from, $subject, $this->text
);
146 if( WikiError
::isError( $mailResult ) ) {
147 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
149 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
150 $encTarget = wfUrlencode( $this->target
);
151 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
152 wfRunHooks('EmailUserComplete', array($this->mAddress
, $from, $subject, $this->text
));
157 function showSuccess() {
158 global $wgOut, $wgUser;
160 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
161 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
163 $wgOut->returnToMain( false );