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 $nu = User
::newFromName( $nt->getText() );
34 $id = $nu->idForName();
37 $wgOut->errorpage( "noemailtitle", "noemailtext" );
41 $address = $nu->getEmail();
43 if ( ( false === strpos( $address, "@" ) ) ||
44 ( 1 == $nu->getOption( "disablemail" ) ) ) {
45 $wgOut->errorpage( "noemailtitle", "noemailtext" );
49 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
51 if ( "success" == $action ) { $f->showSuccess(); }
52 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
53 else { $f->showForm( "" ); }
59 * @subpackage SpecialPage
67 function EmailUserForm( $addr, $target ) {
69 $this->mAddress
= $addr;
70 $this->target
= $target;
71 $this->text
= $wgRequest->getText( 'wpText' );
72 $this->subject
= $wgRequest->getText( 'wpSubject' );
75 function showForm( $err ) {
76 global $wgOut, $wgUser, $wgLang;
78 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
79 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
81 if ( $this->subject
=== "" ) {
82 $this->subject
= wfMsg( "defemailsubject" );
85 $emf = wfMsg( "emailfrom" );
86 $sender = $wgUser->getName();
87 $emt = wfMsg( "emailto" );
88 $rcpt = str_replace( "_", " ", $this->target
);
89 $emr = wfMsg( "emailsubject" );
90 $emm = wfMsg( "emailmessage" );
91 $ems = wfMsg( "emailsend" );
92 $encSubject = htmlspecialchars( $this->subject
);
94 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
95 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
98 $wgOut->setSubtitle( wfMsg( "formerror" ) );
99 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
101 $wgOut->addHTML( "<p>
102 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
104 <td align=right>{$emf}:</td>
105 <td align=left><strong>{$sender}</strong></td>
107 <td align=right>{$emt}:</td>
108 <td align=left><strong>{$rcpt}</strong></td>
110 <td align=right>{$emr}:</td>
112 <input type=text name=\"wpSubject\" value=\"{$encSubject}\">
115 <td align=right>{$emm}:</td>
117 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
121 <td> </td><td align=left>
122 <input type=submit name=\"wpSend\" value=\"{$ems}\">
128 function doSubmit() {
129 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
131 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
133 $mailResult = userMailer( $this->mAddress
, $from, wfQuotedPrintable( $this->subject
), $this->text
);
137 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
138 $encTarget = wfUrlencode( $this->target
);
139 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
142 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
145 function showSuccess() {
146 global $wgOut, $wgUser;
148 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
149 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
151 $wgOut->returnToMain( false );