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