configuration of the live site
[lhc/web/wiklou.git] / includes / SpecialEmailuser.php
1 <?php
2
3 require_once('UserMailer.php');
4
5 function wfSpecialEmailuser( $par ) {
6 global $wgUser, $wgOut, $wgRequest;
7
8 if ( 0 == $wgUser->getID() ||
9 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
10 $wgOut->errorpage( "mailnologin", "mailnologintext" );
11 return;
12 }
13
14 $action = $wgRequest->getVal( 'action' );
15 if( empty( $par ) ) {
16 $target = $wgRequest->getVal( 'target' );
17 } else {
18 $target = $par;
19 }
20 if ( "" == $target ) {
21 $wgOut->errorpage( "notargettitle", "notargettext" );
22 return;
23 }
24 $nt = Title::newFromURL( $target );
25 $nu = User::newFromName( $nt->getText() );
26 $id = $nu->idForName();
27
28 if ( 0 == $id ) {
29 $wgOut->errorpage( "noemailtitle", "noemailtext" );
30 return;
31 }
32 $nu->setID( $id );
33 $address = $nu->getEmail();
34
35 if ( ( false === strpos( $address, "@" ) ) ||
36 ( 1 == $nu->getOption( "disablemail" ) ) ) {
37 $wgOut->errorpage( "noemailtitle", "noemailtext" );
38 return;
39 }
40
41 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
42
43 if ( "success" == $action ) { $f->showSuccess(); }
44 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
45 else { $f->showForm( "" ); }
46 }
47
48 class EmailUserForm {
49
50 var $mAddress;
51 var $target;
52 var $text, $subject;
53
54 function EmailUserForm( $addr, $target )
55 {
56 global $wgRequest;
57 $this->mAddress = $addr;
58 $this->target = $target;
59 $this->text = $wgRequest->getText( 'wpText' );
60 $this->subject = $wgRequest->getText( 'wpSubject' );
61 }
62
63 function showForm( $err )
64 {
65 global $wgOut, $wgUser, $wgLang;
66
67 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
68 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
69
70 if ( $this->subject === "" ) {
71 $this->subject = wfMsg( "defemailsubject" );
72 }
73
74 $emf = wfMsg( "emailfrom" );
75 $sender = $wgUser->getName();
76 $emt = wfMsg( "emailto" );
77 $rcpt = str_replace( "_", " ", $this->target );
78 $emr = wfMsg( "emailsubject" );
79 $emm = wfMsg( "emailmessage" );
80 $ems = wfMsg( "emailsend" );
81 $encSubject = htmlspecialchars( $this->subject );
82
83 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
84 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
85
86 if ( "" != $err ) {
87 $wgOut->setSubtitle( wfMsg( "formerror" ) );
88 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
89 }
90 $wgOut->addHTML( "<p>
91 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
92 <table border=0><tr>
93 <td align=right>{$emf}:</td>
94 <td align=left><strong>{$sender}</strong></td>
95 </tr><tr>
96 <td align=right>{$emt}:</td>
97 <td align=left><strong>{$rcpt}</strong></td>
98 </tr><tr>
99 <td align=right>{$emr}:</td>
100 <td align=left>
101 <input type=text name=\"wpSubject\" value=\"{$encSubject}\">
102 </td>
103 </tr><tr>
104 <td align=right>{$emm}:</td>
105 <td align=left>
106 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
107 {$this->text}
108 </textarea>
109 </td></tr><tr>
110 <td>&nbsp;</td><td align=left>
111 <input type=submit name=\"wpSend\" value=\"{$ems}\">
112 </td></tr></table>
113 </form>\n" );
114
115 }
116
117 function doSubmit()
118 {
119 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
120
121 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
122
123 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text );
124
125 if (! $mailResult)
126 {
127 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
128 $encTarget = wfUrlencode( $this->target );
129 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
130 }
131 else
132 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
133 }
134
135 function showSuccess()
136 {
137 global $wgOut, $wgUser;
138
139 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
140 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
141
142 $wgOut->returnToMain( false );
143 }
144 }
145 ?>