2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-02-27 12:48:07 +00:00
|
|
|
require_once('UserMailer.php');
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
function wfSpecialEmailuser()
|
|
|
|
|
{
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( 0 == $wgUser->getID() ||
|
|
|
|
|
( false === strpos( $wgUser->getEmail(), "@" ) ) ) {
|
|
|
|
|
$wgOut->errorpage( "mailnologin", "mailnologintext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-03-08 09:09:35 +00:00
|
|
|
$action = $wgRequest->getVal( $action );
|
|
|
|
|
$target = $wgRequest->getVal( $target );
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( "" == $target ) {
|
|
|
|
|
$wgOut->errorpage( "notargettitle", "notargettext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$nt = Title::newFromURL( $target );
|
|
|
|
|
$nu = User::newFromName( $nt->getText() );
|
|
|
|
|
$id = $nu->idForName();
|
|
|
|
|
|
|
|
|
|
if ( 0 == $id ) {
|
|
|
|
|
$wgOut->errorpage( "noemailtitle", "noemailtext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$nu->setID( $id );
|
|
|
|
|
$address = $nu->getEmail();
|
|
|
|
|
|
|
|
|
|
if ( ( false === strpos( $address, "@" ) ) ||
|
|
|
|
|
( 1 == $nu->getOption( "disablemail" ) ) ) {
|
|
|
|
|
$wgOut->errorpage( "noemailtitle", "noemailtext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
$f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( "success" == $action ) { $f->showSuccess(); }
|
2004-03-08 09:09:35 +00:00
|
|
|
else if ( "submit" == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
|
2003-04-14 23:10:40 +00:00
|
|
|
else { $f->showForm( "" ); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EmailUserForm {
|
|
|
|
|
|
|
|
|
|
var $mAddress;
|
2004-03-08 09:09:35 +00:00
|
|
|
var $target;
|
|
|
|
|
var $text, $subject;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-08 09:09:35 +00:00
|
|
|
function EmailUserForm( $addr, $target )
|
2003-04-14 23:10:40 +00:00
|
|
|
{
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wgRequest;
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mAddress = $addr;
|
2004-03-08 09:09:35 +00:00
|
|
|
$this->target = $target;
|
|
|
|
|
$this->text = $wgRequest->getText( 'wpText' );
|
|
|
|
|
$this->subject = $wgRequest->getText( 'wpSubject' );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showForm( $err )
|
|
|
|
|
{
|
|
|
|
|
global $wgOut, $wgUser, $wgLang;
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wpSubject, $wpText;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "emailpage" ) );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( "emailpagetext" ) );
|
|
|
|
|
|
2004-02-12 02:33:21 +00:00
|
|
|
if ( ! $wpSubject ) { $wpSubject = wfMsg( "defemailsubject" ); }
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
$emf = wfMsg( "emailfrom" );
|
|
|
|
|
$sender = $wgUser->getName();
|
|
|
|
|
$emt = wfMsg( "emailto" );
|
2004-03-08 09:09:35 +00:00
|
|
|
$rcpt = str_replace( "_", " ", $this->target );
|
2003-04-14 23:10:40 +00:00
|
|
|
$emr = wfMsg( "emailsubject" );
|
|
|
|
|
$emm = wfMsg( "emailmessage" );
|
|
|
|
|
$ems = wfMsg( "emailsend" );
|
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
|
2004-03-08 09:09:35 +00:00
|
|
|
$action = $titleObj->escapeLocalURL( "target={$this->target}&action=submit" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
if ( "" != $err ) {
|
|
|
|
|
$wgOut->setSubtitle( wfMsg( "formerror" ) );
|
|
|
|
|
$wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
|
|
|
|
|
}
|
|
|
|
|
$wgOut->addHTML( "<p>
|
|
|
|
|
<form id=\"emailuser\" method=\"post\" action=\"{$action}\">
|
|
|
|
|
<table border=0><tr>
|
|
|
|
|
<td align=right>{$emf}:</td>
|
|
|
|
|
<td align=left><strong>{$sender}</strong></td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td align=right>{$emt}:</td>
|
|
|
|
|
<td align=left><strong>{$rcpt}</strong></td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td align=right>{$emr}:</td>
|
|
|
|
|
<td align=left>
|
|
|
|
|
<input type=text name=\"wpSubject\" value=\"{$wpSubject}\">
|
|
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
|
|
|
|
<td align=right>{$emm}:</td>
|
|
|
|
|
<td align=left>
|
|
|
|
|
<textarea name=\"wpText\" rows=10 cols=60 wrap=virtual>
|
|
|
|
|
{$wpText}
|
|
|
|
|
</textarea>
|
|
|
|
|
</td></tr><tr>
|
|
|
|
|
<td> </td><td align=left>
|
|
|
|
|
<input type=submit name=\"wpSend\" value=\"{$ems}\">
|
|
|
|
|
</td></tr></table>
|
|
|
|
|
</form>\n" );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doSubmit()
|
|
|
|
|
{
|
|
|
|
|
global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
|
2004-03-08 09:09:35 +00:00
|
|
|
global $wpSubject, $wpText, $this->target;
|
2003-11-12 10:21:28 +00:00
|
|
|
|
|
|
|
|
$from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
|
2004-02-27 12:48:07 +00:00
|
|
|
|
|
|
|
|
$mailResult = userMailer( $this->mAddress, $from, wfQuotedPrintable( $wpSubject ), $wpText );
|
|
|
|
|
|
|
|
|
|
if (! $mailResult)
|
|
|
|
|
{
|
2004-03-06 01:49:16 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
|
2004-03-08 09:09:35 +00:00
|
|
|
$wgOut->redirect( $titleObj->getFullURL( "target={$this->target}&action=success" ) );
|
2004-02-27 12:48:07 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSuccess()
|
|
|
|
|
{
|
|
|
|
|
global $wgOut, $wgUser;
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "emailsent" ) );
|
|
|
|
|
$wgOut->addHTML( wfMsg( "emailsenttext" ) );
|
|
|
|
|
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|