2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-02-27 12:48:07 +00:00
|
|
|
require_once('UserMailer.php');
|
|
|
|
|
|
2004-04-24 07:02:27 +00:00
|
|
|
function wfSpecialEmailuser( $par ) {
|
2004-11-25 06:20:01 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-11-25 06:20:01 +00:00
|
|
|
if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
|
|
|
|
|
$wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-25 18:38:43 +00:00
|
|
|
if( !$wgUser->canSendEmail() ) {
|
|
|
|
|
wfDebug( "User can't send.\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->errorpage( "mailnologin", "mailnologintext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-04-24 07:02:27 +00:00
|
|
|
|
2004-04-01 12:53:01 +00:00
|
|
|
$action = $wgRequest->getVal( 'action' );
|
2005-05-06 11:20:37 +00:00
|
|
|
$target = isset($par) ? $par : $wgRequest->getVal( 'target' );
|
2003-04-14 23:10:40 +00:00
|
|
|
if ( "" == $target ) {
|
2005-04-25 18:38:43 +00:00
|
|
|
wfDebug( "Target is empty.\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->errorpage( "notargettitle", "notargettext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-04-25 18:38:43 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$nt = Title::newFromURL( $target );
|
2004-10-14 07:29:12 +00:00
|
|
|
if ( is_null( $nt ) ) {
|
2005-04-25 18:38:43 +00:00
|
|
|
wfDebug( "Target is invalid title.\n" );
|
2004-10-14 07:29:12 +00:00
|
|
|
$wgOut->errorpage( "notargettitle", "notargettext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-04-25 18:38:43 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$nu = User::newFromName( $nt->getText() );
|
2005-04-25 18:38:43 +00:00
|
|
|
if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
|
|
|
|
|
wfDebug( "Target is invalid user or can't receive.\n" );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->errorpage( "noemailtitle", "noemailtext" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-29 17:58:28 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$address = $nu->getEmail();
|
2004-03-08 09:09:35 +00:00
|
|
|
$f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2005-02-21 01:56:50 +00:00
|
|
|
if ( "success" == $action ) {
|
|
|
|
|
$f->showSuccess();
|
|
|
|
|
} else if ( "submit" == $action && $wgRequest->wasPosted() &&
|
|
|
|
|
$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
|
|
|
|
|
$f->doSubmit();
|
|
|
|
|
} else {
|
|
|
|
|
$f->showForm();
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
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-09-02 23:28:24 +00:00
|
|
|
function EmailUserForm( $addr, $target ) {
|
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
|
|
|
}
|
|
|
|
|
|
2005-02-11 10:08:41 +00:00
|
|
|
function showForm() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang;
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "emailpage" ) );
|
|
|
|
|
$wgOut->addWikiText( wfMsg( "emailpagetext" ) );
|
|
|
|
|
|
2004-04-01 12:53:01 +00:00
|
|
|
if ( $this->subject === "" ) {
|
|
|
|
|
$this->subject = 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-04-01 12:53:01 +00:00
|
|
|
$encSubject = htmlspecialchars( $this->subject );
|
|
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
|
2005-02-11 10:08:41 +00:00
|
|
|
$action = $titleObj->escapeLocalURL( "target=" .
|
|
|
|
|
urlencode( $this->target ) . "&action=submit" );
|
2005-02-21 01:56:50 +00:00
|
|
|
$token = $wgUser->editToken();
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-10-14 07:29:12 +00:00
|
|
|
$wgOut->addHTML( "
|
2003-04-14 23:10:40 +00:00
|
|
|
<form id=\"emailuser\" method=\"post\" action=\"{$action}\">
|
2004-10-14 07:29:12 +00:00
|
|
|
<table border='0'><tr>
|
|
|
|
|
<td align='right'>{$emf}:</td>
|
2005-02-11 10:08:41 +00:00
|
|
|
<td align='left'><strong>" . htmlspecialchars( $sender ) . "</strong></td>
|
2003-04-14 23:10:40 +00:00
|
|
|
</tr><tr>
|
2004-10-14 07:29:12 +00:00
|
|
|
<td align='right'>{$emt}:</td>
|
2005-02-11 10:08:41 +00:00
|
|
|
<td align='left'><strong>" . htmlspecialchars( $rcpt ) . "</strong></td>
|
2003-04-14 23:10:40 +00:00
|
|
|
</tr><tr>
|
2004-10-14 07:29:12 +00:00
|
|
|
<td align='right'>{$emr}:</td>
|
|
|
|
|
<td align='left'>
|
|
|
|
|
<input type='text' name=\"wpSubject\" value=\"{$encSubject}\" />
|
2003-04-14 23:10:40 +00:00
|
|
|
</td>
|
|
|
|
|
</tr><tr>
|
2004-10-14 07:29:12 +00:00
|
|
|
<td align='right'>{$emm}:</td>
|
|
|
|
|
<td align='left'>
|
|
|
|
|
<textarea name=\"wpText\" rows='10' cols='60' wrap='virtual'>" . htmlspecialchars( $this->text ) .
|
2004-10-13 21:07:08 +00:00
|
|
|
"</textarea>
|
2003-04-14 23:10:40 +00:00
|
|
|
</td></tr><tr>
|
2004-10-14 07:29:12 +00:00
|
|
|
<td> </td><td align='left'>
|
|
|
|
|
<input type='submit' name=\"wpSend\" value=\"{$ems}\" />
|
2003-04-14 23:10:40 +00:00
|
|
|
</td></tr></table>
|
2005-02-21 01:56:50 +00:00
|
|
|
<input type='hidden' name='wpEditToken' value=\"$token\" />
|
2003-04-14 23:10:40 +00:00
|
|
|
</form>\n" );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function doSubmit() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
|
2003-11-12 10:21:28 +00:00
|
|
|
|
|
|
|
|
$from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
|
2004-11-29 04:23:12 +00:00
|
|
|
$subject = wfQuotedPrintable( $this->subject );
|
2004-02-27 12:48:07 +00:00
|
|
|
|
Changed the calling protocol for function wfRunHooks() in Hooks.php.
Previously, this function used variable arguments to allow
different hooks to pass different parameters. However, var args
silently convert reference-calling to value-calling. So a call
that used to work like this:
# old
wfRunHooks('SomeEvent', $param1, &$param2, $param3);
...now works like this:
# new
wfRunHooks('SomeEvent', array($param1, &$param2, $param3));
Hook functions can now change pass-by-reference parameters correctly
(e.g. $param2 in the above example).
All calls to wfRunHooks() were changed and tested, and the change
was documented in docs/hooks.doc. This change was originally checked
in on REL1_4 branch as a bugfix, but per vibber reverted and checked
in to HEAD instead.
2005-03-13 15:29:43 +00:00
|
|
|
if (wfRunHooks('EmailUser', array(&$this->mAddress, &$from, &$subject, &$this->text))) {
|
2004-11-29 04:23:12 +00:00
|
|
|
|
|
|
|
|
$mailResult = userMailer( $this->mAddress, $from, $subject, $this->text );
|
|
|
|
|
|
2005-04-25 18:38:43 +00:00
|
|
|
if( WikiError::isError( $mailResult ) ) {
|
|
|
|
|
$wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
|
|
|
|
|
} else {
|
2004-11-29 04:23:12 +00:00
|
|
|
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
|
|
|
|
|
$encTarget = wfUrlencode( $this->target );
|
|
|
|
|
$wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
|
Changed the calling protocol for function wfRunHooks() in Hooks.php.
Previously, this function used variable arguments to allow
different hooks to pass different parameters. However, var args
silently convert reference-calling to value-calling. So a call
that used to work like this:
# old
wfRunHooks('SomeEvent', $param1, &$param2, $param3);
...now works like this:
# new
wfRunHooks('SomeEvent', array($param1, &$param2, $param3));
Hook functions can now change pass-by-reference parameters correctly
(e.g. $param2 in the above example).
All calls to wfRunHooks() were changed and tested, and the change
was documented in docs/hooks.doc. This change was originally checked
in on REL1_4 branch as a bugfix, but per vibber reverted and checked
in to HEAD instead.
2005-03-13 15:29:43 +00:00
|
|
|
wfRunHooks('EmailUserComplete', array($this->mAddress, $from, $subject, $this->text));
|
2004-11-29 04:23:12 +00:00
|
|
|
}
|
2004-02-27 12:48:07 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function showSuccess() {
|
2003-04-14 23:10:40 +00:00
|
|
|
global $wgOut, $wgUser;
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "emailsent" ) );
|
|
|
|
|
$wgOut->addHTML( wfMsg( "emailsenttext" ) );
|
|
|
|
|
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|