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