Tell regexp parser to use extra analysis on external link regexp;
[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 ( false === strpos( $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 $id = $nu->idForName();
44
45 if ( 0 == $id ) {
46 $wgOut->errorpage( "noemailtitle", "noemailtext" );
47 return;
48 }
49 $nu->setID( $id );
50 $address = $nu->getEmail();
51
52 if ( ( false === strpos( $address, "@" ) ) ||
53 ( 1 == $nu->getOption( "disablemail" ) ) ) {
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
141 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text );
142
143 if (! $mailResult)
144 {
145 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
146 $encTarget = wfUrlencode( $this->target );
147 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
148 }
149 else
150 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
151 }
152
153 function showSuccess() {
154 global $wgOut, $wgUser;
155
156 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
157 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
158
159 $wgOut->returnToMain( false );
160 }
161 }
162 ?>