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 ( 0 == $wgUser->getID() ||
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 ) { $f->showSuccess(); }
61 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
62 else { $f->showForm( "" ); }
68 * @subpackage SpecialPage
76 function EmailUserForm( $addr, $target ) {
78 $this->mAddress
= $addr;
79 $this->target
= $target;
80 $this->text
= $wgRequest->getText( 'wpText' );
81 $this->subject
= $wgRequest->getText( 'wpSubject' );
84 function showForm( $err ) {
85 global $wgOut, $wgUser, $wgLang;
87 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
88 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
90 if ( $this->subject
=== "" ) {
91 $this->subject
= wfMsg( "defemailsubject" );
94 $emf = wfMsg( "emailfrom" );
95 $sender = $wgUser->getName();
96 $emt = wfMsg( "emailto" );
97 $rcpt = str_replace( "_", " ", $this->target
);
98 $emr = wfMsg( "emailsubject" );
99 $emm = wfMsg( "emailmessage" );
100 $ems = wfMsg( "emailsend" );
101 $encSubject = htmlspecialchars( $this->subject
);
103 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
104 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
107 $wgOut->setSubtitle( wfMsg( "formerror" ) );
108 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font></p>\n" );
111 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
112 <table border='0'><tr>
113 <td align='right'>{$emf}:</td>
114 <td align='left'><strong>{$sender}</strong></td>
116 <td align='right'>{$emt}:</td>
117 <td align='left'><strong>{$rcpt}</strong></td>
119 <td align='right'>{$emr}:</td>
121 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
124 <td align='right'>{$emm}:</td>
126 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text
) .
129 <td> </td><td align='left'>
130 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
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', $this->mAddress
, $from, $subject, $this->text
)) {
144 $mailResult = userMailer( $this->mAddress
, $from, $subject, $this->text
);
147 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
148 $encTarget = wfUrlencode( $this->target
);
149 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
150 wfRunHooks('EmailUserComplete', $this->mAddress
, $from, $subject, $this->text
);
152 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
157 function showSuccess() {
158 global $wgOut, $wgUser;
160 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
161 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
163 $wgOut->returnToMain( false );