Removed allpagesformtext1 and allpagesformtext2, obsolete
[mediawiki.git] / includes / SpecialEmailuser.php
blob9c53a7148a491625dc0ca1eb48011d74a6edf5e2
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
11 require_once('UserMailer.php');
13 function wfSpecialEmailuser( $par ) {
14 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail;
16 if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
17 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
18 return;
21 if( !$wgUser->canSendEmail() ) {
22 wfDebug( "User can't send.\n" );
23 $wgOut->errorpage( "mailnologin", "mailnologintext" );
24 return;
27 $action = $wgRequest->getVal( 'action' );
28 if( empty( $par ) ) {
29 $target = $wgRequest->getVal( 'target' );
30 } else {
31 $target = $par;
33 if ( "" == $target ) {
34 wfDebug( "Target is empty.\n" );
35 $wgOut->errorpage( "notargettitle", "notargettext" );
36 return;
39 $nt = Title::newFromURL( $target );
40 if ( is_null( $nt ) ) {
41 wfDebug( "Target is invalid title.\n" );
42 $wgOut->errorpage( "notargettitle", "notargettext" );
43 return;
46 $nu = User::newFromName( $nt->getText() );
47 if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
48 wfDebug( "Target is invalid user or can't receive.\n" );
49 $wgOut->errorpage( "noemailtitle", "noemailtext" );
50 return;
53 $address = $nu->getEmail();
54 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
56 if ( "success" == $action ) {
57 $f->showSuccess();
58 } else if ( "submit" == $action && $wgRequest->wasPosted() &&
59 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
60 $f->doSubmit();
61 } else {
62 $f->showForm();
66 /**
67 * @todo document
68 * @package MediaWiki
69 * @subpackage SpecialPage
71 class EmailUserForm {
73 var $mAddress;
74 var $target;
75 var $text, $subject;
77 function EmailUserForm( $addr, $target ) {
78 global $wgRequest;
79 $this->mAddress = $addr;
80 $this->target = $target;
81 $this->text = $wgRequest->getText( 'wpText' );
82 $this->subject = $wgRequest->getText( 'wpSubject' );
85 function showForm() {
86 global $wgOut, $wgUser, $wgLang;
88 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
89 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
91 if ( $this->subject === "" ) {
92 $this->subject = wfMsg( "defemailsubject" );
95 $emf = wfMsg( "emailfrom" );
96 $sender = $wgUser->getName();
97 $emt = wfMsg( "emailto" );
98 $rcpt = str_replace( "_", " ", $this->target );
99 $emr = wfMsg( "emailsubject" );
100 $emm = wfMsg( "emailmessage" );
101 $ems = wfMsg( "emailsend" );
102 $encSubject = htmlspecialchars( $this->subject );
104 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
105 $action = $titleObj->escapeLocalURL( "target=" .
106 urlencode( $this->target ) . "&action=submit" );
107 $token = $wgUser->editToken();
109 $wgOut->addHTML( "
110 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
111 <table border='0'><tr>
112 <td align='right'>{$emf}:</td>
113 <td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
114 </tr><tr>
115 <td align='right'>{$emt}:</td>
116 <td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
117 </tr><tr>
118 <td align='right'>{$emr}:</td>
119 <td align='left'>
120 <input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
121 </td>
122 </tr><tr>
123 <td align='right'>{$emm}:</td>
124 <td align='left'>
125 <textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text ) .
126 "</textarea>
127 </td></tr><tr>
128 <td>&nbsp;</td><td align='left'>
129 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
130 </td></tr></table>
131 <input type='hidden' name='wpEditToken' value=\"$token\" />
132 </form>\n" );
136 function doSubmit() {
137 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
139 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
140 $subject = wfQuotedPrintable( $this->subject );
142 if (wfRunHooks('EmailUser', array(&$this->mAddress, &$from, &$subject, &$this->text))) {
144 $mailResult = userMailer( $this->mAddress, $from, $subject, $this->text );
146 if( WikiError::isError( $mailResult ) ) {
147 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
148 } else {
149 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
150 $encTarget = wfUrlencode( $this->target );
151 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
152 wfRunHooks('EmailUserComplete', array($this->mAddress, $from, $subject, $this->text));
157 function showSuccess() {
158 global $wgOut, $wgUser;
160 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
161 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
163 $wgOut->returnToMain( false );