3 require_once('UserMailer.php');
5 function wfSpecialEmailuser( $par ) {
6 global $wgUser, $wgOut, $wgRequest;
8 if ( 0 == $wgUser->getID() ||
9 ( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
10 $wgOut->errorpage( "mailnologin", "mailnologintext" );
14 $action = $wgRequest->getVal( 'action' );
16 $target = $wgRequest->getVal( 'target' );
20 if ( "" == $target ) {
21 $wgOut->errorpage( "notargettitle", "notargettext" );
24 $nt = Title
::newFromURL( $target );
25 $nu = User
::newFromName( $nt->getText() );
26 $id = $nu->idForName();
29 $wgOut->errorpage( "noemailtitle", "noemailtext" );
33 $address = $nu->getEmail();
35 if ( ( false === strpos( $address, "@" ) ) ||
36 ( 1 == $nu->getOption( "disablemail" ) ) ) {
37 $wgOut->errorpage( "noemailtitle", "noemailtext" );
41 $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
43 if ( "success" == $action ) { $f->showSuccess(); }
44 else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
45 else { $f->showForm( "" ); }
54 function EmailUserForm( $addr, $target )
57 $this->mAddress
= $addr;
58 $this->target
= $target;
59 $this->text
= $wgRequest->getText( 'wpText' );
60 $this->subject
= $wgRequest->getText( 'wpSubject' );
63 function showForm( $err )
65 global $wgOut, $wgUser, $wgLang;
67 $wgOut->setPagetitle( wfMsg( "emailpage" ) );
68 $wgOut->addWikiText( wfMsg( "emailpagetext" ) );
70 if ( $this->subject
=== "" ) {
71 $this->subject
= wfMsg( "defemailsubject" );
74 $emf = wfMsg( "emailfrom" );
75 $sender = $wgUser->getName();
76 $emt = wfMsg( "emailto" );
77 $rcpt = str_replace( "_", " ", $this->target
);
78 $emr = wfMsg( "emailsubject" );
79 $emm = wfMsg( "emailmessage" );
80 $ems = wfMsg( "emailsend" );
81 $encSubject = htmlspecialchars( $this->subject
);
83 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
84 $action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
87 $wgOut->setSubtitle( wfMsg( "formerror" ) );
88 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
91 <form id=\"emailuser\" method=\"post\" action=\"{$action}\">
93 <td align=right>{$emf}:</td>
94 <td align=left><strong>{$sender}</strong></td>
96 <td align=right>{$emt}:</td>
97 <td align=left><strong>{$rcpt}</strong></td>
99 <td align=right>{$emr}:</td>
101 <input type=text name=\"wpSubject\" value=\"{$encSubject}\">
104 <td align=right>{$emm}:</td>
106 <textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
110 <td> </td><td align=left>
111 <input type=submit name=\"wpSend\" value=\"{$ems}\">
119 global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
121 $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
123 $mailResult = userMailer( $this->mAddress
, $from, wfQuotedPrintable( $this->subject
), $this->text
);
127 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Emailuser" );
128 $encTarget = wfUrlencode( $this->target
);
129 $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
132 $wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
135 function showSuccess()
137 global $wgOut, $wgUser;
139 $wgOut->setPagetitle( wfMsg( "emailsent" ) );
140 $wgOut->addHTML( wfMsg( "emailsenttext" ) );
142 $wgOut->returnToMain( false );