fixed section anchors
[mediawiki.git] / includes / SpecialEmailuser.php
blobc1a071f9e4344a88b6b8f935b63559736030dea1
1 <?php
3 require_once('UserMailer.php');
5 function wfSpecialEmailuser()
7 global $wgUser, $wgOut, $wgRequest;
9 if ( 0 == $wgUser->getID() ||
10 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
11 $wgOut->errorpage( "mailnologin", "mailnologintext" );
12 return;
14 $action = $wgRequest->getVal( $action );
15 $target = $wgRequest->getVal( $target );
16 if ( "" == $target ) {
17 $wgOut->errorpage( "notargettitle", "notargettext" );
18 return;
20 $nt = Title::newFromURL( $target );
21 $nu = User::newFromName( $nt->getText() );
22 $id = $nu->idForName();
24 if ( 0 == $id ) {
25 $wgOut->errorpage( "noemailtitle", "noemailtext" );
26 return;
28 $nu->setID( $id );
29 $address = $nu->getEmail();
31 if ( ( false === strpos( $address, "@" ) ) ||
32 ( 1 == $nu->getOption( "disablemail" ) ) ) {
33 $wgOut->errorpage( "noemailtitle", "noemailtext" );
34 return;
37 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
39 if ( "success" == $action ) { $f->showSuccess(); }
40 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
41 else { $f->showForm( "" ); }
44 class EmailUserForm {
46 var $mAddress;
47 var $target;
48 var $text, $subject;
50 function EmailUserForm( $addr, $target )
52 global $wgRequest;
53 $this->mAddress = $addr;
54 $this->target = $target;
55 $this->text = $wgRequest->getText( 'wpText' );
56 $this->subject = $wgRequest->getText( 'wpSubject' );
59 function showForm( $err )
61 global $wgOut, $wgUser, $wgLang;
62 global $wpSubject, $wpText;
64 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
65 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
67 if ( ! $wpSubject ) { $wpSubject = wfMsg( "defemailsubject" ); }
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" );
77 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
78 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
80 if ( "" != $err ) {
81 $wgOut->setSubtitle( wfMsg( "formerror" ) );
82 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
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" );
111 function doSubmit()
113 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
114 global $wpSubject, $wpText, $this->target;
116 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
118 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $wpSubject ), $wpText );
120 if (! $mailResult)
122 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
123 $wgOut->redirect( $titleObj->getFullURL( "target={$this->target}&action=success" ) );
125 else
126 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
129 function showSuccess()
131 global $wgOut, $wgUser;
133 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
134 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
136 $wgOut->returnToMain( false );