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