don't parse blank ISBNs
[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 $nu = User::newFromName( $nt->getText() );
34 $id = $nu->idForName();
35
36 if ( 0 == $id ) {
37 $wgOut->errorpage( "noemailtitle", "noemailtext" );
38 return;
39 }
40 $nu->setID( $id );
41 $address = $nu->getEmail();
42
43 if ( ( false === strpos( $address, "@" ) ) ||
44 ( 1 == $nu->getOption( "disablemail" ) ) ) {
45 $wgOut->errorpage( "noemailtitle", "noemailtext" );
46 return;
47 }
48
49 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
50
51 if ( "success" == $action ) { $f->showSuccess(); }
52 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
53 else { $f->showForm( "" ); }
54 }
55
56 /**
57 * @todo document
58 * @package MediaWiki
59 * @subpackage SpecialPage
60 */
61 class EmailUserForm {
62
63 var $mAddress;
64 var $target;
65 var $text, $subject;
66
67 function EmailUserForm( $addr, $target ) {
68 global $wgRequest;
69 $this->mAddress = $addr;
70 $this->target = $target;
71 $this->text = $wgRequest->getText( 'wpText' );
72 $this->subject = $wgRequest->getText( 'wpSubject' );
73 }
74
75 function showForm( $err ) {
76 global $wgOut, $wgUser, $wgLang;
77
78 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
79 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
80
81 if ( $this->subject === "" ) {
82 $this->subject = wfMsg( "defemailsubject" );
83 }
84
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 );
93
94 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
95 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
96
97 if ( "" != $err ) {
98 $wgOut->setSubtitle( wfMsg( "formerror" ) );
99 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
100 }
101 $wgOut->addHTML( "<p>
102 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
103 <table border=0><tr>
104 <td align=right>{$emf}:</td>
105 <td align=left><strong>{$sender}</strong></td>
106 </tr><tr>
107 <td align=right>{$emt}:</td>
108 <td align=left><strong>{$rcpt}</strong></td>
109 </tr><tr>
110 <td align=right>{$emr}:</td>
111 <td align=left>
112 <input type=text name=\"wpSubject\" value=\"{$encSubject}\">
113 </td>
114 </tr><tr>
115 <td align=right>{$emm}:</td>
116 <td align=left>
117 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
118 {$this->text}
119 </textarea>
120 </td></tr><tr>
121 <td>&nbsp;</td><td align=left>
122 <input type=submit name=\"wpSend\" value=\"{$ems}\">
123 </td></tr></table>
124 </form>\n" );
125
126 }
127
128 function doSubmit() {
129 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
130
131 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
132
133 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text );
134
135 if (! $mailResult)
136 {
137 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
138 $encTarget = wfUrlencode( $this->target );
139 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
140 }
141 else
142 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
143 }
144
145 function showSuccess() {
146 global $wgOut, $wgUser;
147
148 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
149 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
150
151 $wgOut->returnToMain( false );
152 }
153 }
154 ?>