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