renamed replaceInternalLinks to doTokenizedParser
[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 global $wpSubject, $wpText;
63
64 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
65 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
66
67 if ( ! $wpSubject ) { $wpSubject = wfMsg( "defemailsubject" ); }
68
69 $emf = wfMsg( "emailfrom" );
70 $sender = $wgUser->getName();
71 $emt = wfMsg( "emailto" );
72 $rcpt = str_replace( "_", " ", $this->target );
73 $emr = wfMsg( "emailsubject" );
74 $emm = wfMsg( "emailmessage" );
75 $ems = wfMsg( "emailsend" );
76
77 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
78 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
79
80 if ( "" != $err ) {
81 $wgOut->setSubtitle( wfMsg( "formerror" ) );
82 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
83 }
84 $wgOut->addHTML( "<p>
85 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
86 <table border=0><tr>
87 <td align=right>{$emf}:</td>
88 <td align=left><strong>{$sender}</strong></td>
89 </tr><tr>
90 <td align=right>{$emt}:</td>
91 <td align=left><strong>{$rcpt}</strong></td>
92 </tr><tr>
93 <td align=right>{$emr}:</td>
94 <td align=left>
95 <input type=text name=\"wpSubject\" value=\"{$wpSubject}\">
96 </td>
97 </tr><tr>
98 <td align=right>{$emm}:</td>
99 <td align=left>
100 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
101 {$wpText}
102 </textarea>
103 </td></tr><tr>
104 <td>&nbsp;</td><td align=left>
105 <input type=submit name=\"wpSend\" value=\"{$ems}\">
106 </td></tr></table>
107 </form>\n" );
108
109 }
110
111 function doSubmit()
112 {
113 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
114 global $wpSubject, $wpText, $this->target;
115
116 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
117
118 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $wpSubject ), $wpText );
119
120 if (! $mailResult)
121 {
122 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
123 $wgOut->redirect( $titleObj->getFullURL( "target={$this->target}&action=success" ) );
124 }
125 else
126 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
127 }
128
129 function showSuccess()
130 {
131 global $wgOut, $wgUser;
132
133 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
134 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
135
136 $wgOut->returnToMain( false );
137 }
138 }
139 ?>