Patch to only load $msgAllMessages instead of replacing the language object.
[mediawiki.git] / includes / SpecialEmailuser.php
blob9661a1c78d0b082911f1f9e504980960212b3bd6
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;
16 if ( 0 == $wgUser->getID() ||
17 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
18 $wgOut->errorpage( "mailnologin", "mailnologintext" );
19 return;
22 $action = $wgRequest->getVal( 'action' );
23 if( empty( $par ) ) {
24 $target = $wgRequest->getVal( 'target' );
25 } else {
26 $target = $par;
28 if ( "" == $target ) {
29 $wgOut->errorpage( "notargettitle", "notargettext" );
30 return;
32 $nt = Title::newFromURL( $target );
33 $nu = User::newFromName( $nt->getText() );
34 $id = $nu->idForName();
36 if ( 0 == $id ) {
37 $wgOut->errorpage( "noemailtitle", "noemailtext" );
38 return;
40 $nu->setID( $id );
41 $address = $nu->getEmail();
43 if ( ( false === strpos( $address, "@" ) ) ||
44 ( 1 == $nu->getOption( "disablemail" ) ) ) {
45 $wgOut->errorpage( "noemailtitle", "noemailtext" );
46 return;
49 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
51 if ( "success" == $action ) { $f->showSuccess(); }
52 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
53 else { $f->showForm( "" ); }
56 /**
57 * @todo document
58 * @package MediaWiki
59 * @subpackage SpecialPage
61 class EmailUserForm {
63 var $mAddress;
64 var $target;
65 var $text, $subject;
67 function EmailUserForm( $addr, $target ) {
68 global $wgRequest;
69 $this->mAddress = $addr;
70 $this->target = $target;
71 $this->text = $wgRequest->getText( 'wpText' );
72 $this->subject = $wgRequest->getText( 'wpSubject' );
75 function showForm( $err ) {
76 global $wgOut, $wgUser, $wgLang;
78 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
79 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
81 if ( $this->subject === "" ) {
82 $this->subject = wfMsg( "defemailsubject" );
85 $emf = wfMsg( "emailfrom" );
86 $sender = $wgUser->getName();
87 $emt = wfMsg( "emailto" );
88 $rcpt = str_replace( "_", " ", $this->target );
89 $emr = wfMsg( "emailsubject" );
90 $emm = wfMsg( "emailmessage" );
91 $ems = wfMsg( "emailsend" );
92 $encSubject = htmlspecialchars( $this->subject );
94 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
95 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
97 if ( "" != $err ) {
98 $wgOut->setSubtitle( wfMsg( "formerror" ) );
99 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
101 $wgOut->addHTML( "<p>
102 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
103 <table border=0><tr>
104 <td align=right>{$emf}:</td>
105 <td align=left><strong>{$sender}</strong></td>
106 </tr><tr>
107 <td align=right>{$emt}:</td>
108 <td align=left><strong>{$rcpt}</strong></td>
109 </tr><tr>
110 <td align=right>{$emr}:</td>
111 <td align=left>
112 <input type=text name=\"wpSubject\" value=\"{$encSubject}\">
113 </td>
114 </tr><tr>
115 <td align=right>{$emm}:</td>
116 <td align=left>
117 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
118 {$this->text}
119 </textarea>
120 </td></tr><tr>
121 <td>&nbsp;</td><td align=left>
122 <input type=submit name=\"wpSend\" value=\"{$ems}\">
123 </td></tr></table>
124 </form>\n" );
128 function doSubmit() {
129 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
131 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
133 $mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $this->subject ), $this->text );
135 if (! $mailResult)
137 $titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
138 $encTarget = wfUrlencode( $this->target );
139 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
141 else
142 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
145 function showSuccess() {
146 global $wgOut, $wgUser;
148 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
149 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
151 $wgOut->returnToMain( false );