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 ( false === strpos( $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 ( ( false === strpos( $address, "@" ) ) ||
52 ( 1 == $nu->getOption( "disablemail" ) ) ) {
53 $wgOut->errorpage( "noemailtitle", "noemailtext" );
57 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
59 if ( "success" == $action ) { $f->showSuccess(); }
60 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
61 else { $f->showForm( "" ); }
67 * @subpackage SpecialPage
75 function EmailUserForm( $addr, $target ) {
77 $this->mAddress
= $addr;
78 $this->target
= $target;
79 $this->text
= $wgRequest->getText( 'wpText' );
80 $this->subject
= $wgRequest->getText( 'wpSubject' );
83 function showForm( $err ) {
84 global $wgOut, $wgUser, $wgLang;
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 = str_replace( "_", " ", $this->target
);
97 $emr = wfMsg( "emailsubject" );
98 $emm = wfMsg( "emailmessage" );
99 $ems = wfMsg( "emailsend" );
100 $encSubject = htmlspecialchars( $this->subject
);
102 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
103 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
106 $wgOut->setSubtitle( wfMsg( "formerror" ) );
107 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font></p>\n" );
110 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
111 <table border='0'><tr>
112 <td align='right'>{$emf}:</td>
113 <td align='left'><strong>{$sender}</strong></td>
115 <td align='right'>{$emt}:</td>
116 <td align='left'><strong>{$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}\" />
135 function doSubmit() {
136 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
138 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
139 $subject = wfQuotedPrintable( $this->subject
);
141 if (wfRunHooks('EmailUser', $this->mAddress
, $from, $subject, $this->text
)) {
143 $mailResult = userMailer( $this->mAddress
, $from, $subject, $this->text
);
146 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
147 $encTarget = wfUrlencode( $this->target
);
148 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
149 wfRunHooks('EmailUserComplete', $this->mAddress
, $from, $subject, $this->text
);
151 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
156 function showSuccess() {
157 global $wgOut, $wgUser;
159 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
160 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
162 $wgOut->returnToMain( false );