5 * @subpackage SpecialPage
11 require_once('UserMailer.php');
13 function wfSpecialEmailuser( $par ) {
14 global $wgUser, $wgOut, $wgRequest;
16 if ( 0 == $wgUser->getID() ||
17 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
18 $wgOut->errorpage( "mailnologin", "mailnologintext" );
22 $action = $wgRequest->getVal( 'action' );
24 $target = $wgRequest->getVal( 'target' );
28 if ( "" == $target ) {
29 $wgOut->errorpage( "notargettitle", "notargettext" );
32 $nt = Title
::newFromURL( $target );
33 if ( is_null( $nt ) ) {
34 $wgOut->errorpage( "notargettitle", "notargettext" );
37 $nu = User
::newFromName( $nt->getText() );
38 $id = $nu->idForName();
41 $wgOut->errorpage( "noemailtitle", "noemailtext" );
45 $address = $nu->getEmail();
47 if ( ( false === strpos( $address, "@" ) ) ||
48 ( 1 == $nu->getOption( "disablemail" ) ) ) {
49 $wgOut->errorpage( "noemailtitle", "noemailtext" );
53 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
55 if ( "success" == $action ) { $f->showSuccess(); }
56 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
57 else { $f->showForm( "" ); }
63 * @subpackage SpecialPage
71 function EmailUserForm( $addr, $target ) {
73 $this->mAddress
= $addr;
74 $this->target
= $target;
75 $this->text
= $wgRequest->getText( 'wpText' );
76 $this->subject
= $wgRequest->getText( 'wpSubject' );
79 function showForm( $err ) {
80 global $wgOut, $wgUser, $wgLang;
82 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
83 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
85 if ( $this->subject
=== "" ) {
86 $this->subject
= wfMsg( "defemailsubject" );
89 $emf = wfMsg( "emailfrom" );
90 $sender = $wgUser->getName();
91 $emt = wfMsg( "emailto" );
92 $rcpt = str_replace( "_", " ", $this->target
);
93 $emr = wfMsg( "emailsubject" );
94 $emm = wfMsg( "emailmessage" );
95 $ems = wfMsg( "emailsend" );
96 $encSubject = htmlspecialchars( $this->subject
);
98 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
99 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
102 $wgOut->setSubtitle( wfMsg( "formerror" ) );
103 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font></p>\n" );
106 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
107 <table border='0'><tr>
108 <td align='right'>{$emf}:</td>
109 <td align='left'><strong>{$sender}</strong></td>
111 <td align='right'>{$emt}:</td>
112 <td align='left'><strong>{$rcpt}</strong></td>
114 <td align='right'>{$emr}:</td>
116 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
119 <td align='right'>{$emm}:</td>
121 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text
) .
124 <td> </td><td align='left'>
125 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
131 function doSubmit() {
132 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
134 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
136 $mailResult = userMailer( $this->mAddress
, $from, wfQuotedPrintable( $this->subject
), $this->text
);
140 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
141 $encTarget = wfUrlencode( $this->target
);
142 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
145 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
148 function showSuccess() {
149 global $wgOut, $wgUser;
151 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
152 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
154 $wgOut->returnToMain( false );