* (bug 1368) Fix SQL error on stopword/short word search w/ MySQL 3.x
[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, $wgEnableEmail, $wgEnableUserEmail;
15
16 if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
17 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
18 return;
19 }
20
21 if ( 0 == $wgUser->getID() ||
22 ( !$wgUser->isValidEmailAddr( $wgUser->getEmail() ) ) ) {
23 $wgOut->errorpage( "mailnologin", "mailnologintext" );
24 return;
25 }
26
27 $action = $wgRequest->getVal( 'action' );
28 if( empty( $par ) ) {
29 $target = $wgRequest->getVal( 'target' );
30 } else {
31 $target = $par;
32 }
33 if ( "" == $target ) {
34 $wgOut->errorpage( "notargettitle", "notargettext" );
35 return;
36 }
37 $nt = Title::newFromURL( $target );
38 if ( is_null( $nt ) ) {
39 $wgOut->errorpage( "notargettitle", "notargettext" );
40 return;
41 }
42 $nu = User::newFromName( $nt->getText() );
43
44 if ( 0 == $nu->getID() ) {
45 $wgOut->errorpage( "noemailtitle", "noemailtext" );
46 return;
47 }
48
49 $address = $nu->getEmail();
50
51 if ( ( !$nu->isValidEmailAddr( $address ) ) ||
52 ( 1 == $nu->getOption( "disablemail" ) ) ||
53 ( 0 == $nu->getEmailauthenticationtimestamp() ) ) {
54 $wgOut->errorpage( "noemailtitle", "noemailtext" );
55 return;
56 }
57
58 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
59
60 if ( "success" == $action ) { $f->showSuccess(); }
61 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
62 else { $f->showForm( "" ); }
63 }
64
65 /**
66 * @todo document
67 * @package MediaWiki
68 * @subpackage SpecialPage
69 */
70 class EmailUserForm {
71
72 var $mAddress;
73 var $target;
74 var $text, $subject;
75
76 function EmailUserForm( $addr, $target ) {
77 global $wgRequest;
78 $this->mAddress = $addr;
79 $this->target = $target;
80 $this->text = $wgRequest->getText( 'wpText' );
81 $this->subject = $wgRequest->getText( 'wpSubject' );
82 }
83
84 function showForm( $err ) {
85 global $wgOut, $wgUser, $wgLang;
86
87 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
88 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
89
90 if ( $this->subject === "" ) {
91 $this->subject = wfMsg( "defemailsubject" );
92 }
93
94 $emf = wfMsg( "emailfrom" );
95 $sender = $wgUser->getName();
96 $emt = wfMsg( "emailto" );
97 $rcpt = str_replace( "_", " ", $this->target );
98 $emr = wfMsg( "emailsubject" );
99 $emm = wfMsg( "emailmessage" );
100 $ems = wfMsg( "emailsend" );
101 $encSubject = htmlspecialchars( $this->subject );
102
103 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
104 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
105
106 if ( "" != $err ) {
107 $wgOut->setSubtitle( wfMsg( "formerror" ) );
108 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font></p>\n" );
109 }
110 $wgOut->addHTML( "
111 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
112 <table border='0'><tr>
113 <td align='right'>{$emf}:</td>
114 <td align='left'><strong>{$sender}</strong></td>
115 </tr><tr>
116 <td align='right'>{$emt}:</td>
117 <td align='left'><strong>{$rcpt}</strong></td>
118 </tr><tr>
119 <td align='right'>{$emr}:</td>
120 <td align='left'>
121 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
122 </td>
123 </tr><tr>
124 <td align='right'>{$emm}:</td>
125 <td align='left'>
126 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text ) .
127 "</textarea>
128 </td></tr><tr>
129 <td>&nbsp;</td><td align='left'>
130 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
131 </td></tr></table>
132 </form>\n" );
133
134 }
135
136 function doSubmit() {
137 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
138
139 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
140 $subject = wfQuotedPrintable( $this->subject );
141
142 if (wfRunHooks('EmailUser', $this->mAddress, $from, $subject, $this->text)) {
143
144 $mailResult = userMailer( $this->mAddress, $from, $subject, $this->text );
145
146 if (!$mailResult) {
147 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
148 $encTarget = wfUrlencode( $this->target );
149 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
150 wfRunHooks('EmailUserComplete', $this->mAddress, $from, $subject, $this->text);
151 } else {
152 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
153 }
154 }
155 }
156
157 function showSuccess() {
158 global $wgOut, $wgUser;
159
160 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
161 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
162
163 $wgOut->returnToMain( false );
164 }
165 }
166 ?>