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->isAnon() ||
22 ( !$wgUser->isValidEmailAddr( $wgUser->getEmail() ) ) ) {
23 $wgOut->errorpage( "mailnologin", "mailnologintext" );
27 $action = $wgRequest->getVal( 'action' );
29 $target = $wgRequest->getVal( 'target' );
33 if ( "" == $target ) {
34 $wgOut->errorpage( "notargettitle", "notargettext" );
37 $nt = Title
::newFromURL( $target );
38 if ( is_null( $nt ) ) {
39 $wgOut->errorpage( "notargettitle", "notargettext" );
42 $nu = User
::newFromName( $nt->getText() );
44 if ( 0 == $nu->getID() ) {
45 $wgOut->errorpage( "noemailtitle", "noemailtext" );
49 $address = $nu->getEmail();
51 if ( ( !$nu->isValidEmailAddr( $address ) ) ||
52 ( 1 == $nu->getOption( "disablemail" ) ) ||
53 ( 0 == $nu->getEmailauthenticationtimestamp() ) ) {
54 $wgOut->errorpage( "noemailtitle", "noemailtext" );
58 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
60 if ( "success" == $action ) {
62 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
63 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
73 * @subpackage SpecialPage
81 function EmailUserForm( $addr, $target ) {
83 $this->mAddress
= $addr;
84 $this->target
= $target;
85 $this->text
= $wgRequest->getText( 'wpText' );
86 $this->subject
= $wgRequest->getText( 'wpSubject' );
90 global $wgOut, $wgUser, $wgLang;
92 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
93 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
95 if ( $this->subject
=== "" ) {
96 $this->subject
= wfMsg( "defemailsubject" );
99 $emf = wfMsg( "emailfrom" );
100 $sender = $wgUser->getName();
101 $emt = wfMsg( "emailto" );
102 $rcpt = str_replace( "_", " ", $this->target
);
103 $emr = wfMsg( "emailsubject" );
104 $emm = wfMsg( "emailmessage" );
105 $ems = wfMsg( "emailsend" );
106 $encSubject = htmlspecialchars( $this->subject
);
108 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
109 $action = $titleObj->escapeLocalURL( "target=" .
110 urlencode( $this->target
) . "&action=submit" );
111 $token = $wgUser->editToken();
114 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
115 <table border='0'><tr>
116 <td align='right'>{$emf}:</td>
117 <td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
119 <td align='right'>{$emt}:</td>
120 <td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
122 <td align='right'>{$emr}:</td>
124 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
127 <td align='right'>{$emm}:</td>
129 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text
) .
132 <td> </td><td align='left'>
133 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
135 <input type='hidden' name='wpEditToken' value=\"$token\" />
140 function doSubmit() {
141 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
143 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
144 $subject = wfQuotedPrintable( $this->subject
);
146 if (wfRunHooks('EmailUser', $this->mAddress
, $from, $subject, $this->text
)) {
148 $mailResult = userMailer( $this->mAddress
, $from, $subject, $this->text
);
151 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
152 $encTarget = wfUrlencode( $this->target
);
153 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
154 wfRunHooks('EmailUserComplete', $this->mAddress
, $from, $subject, $this->text
);
156 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
161 function showSuccess() {
162 global $wgOut, $wgUser;
164 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
165 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
167 $wgOut->returnToMain( false );