2007-02-12 14:50:29 -07:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Speclial:Contact, a contact form for visitors.
|
|
|
|
* Based on SpecialEmailUser.php
|
2008-02-03 07:37:27 -07:00
|
|
|
*
|
2009-01-11 05:16:13 -07:00
|
|
|
* @file
|
|
|
|
* @ingroup SpecialPage
|
2007-02-12 14:50:29 -07:00
|
|
|
* @author Daniel Kinzler, brightbyte.de
|
|
|
|
* @copyright © 2007 Daniel Kinzler
|
2008-11-04 01:19:56 -07:00
|
|
|
* @license GNU General Public Licence 2.0 or later
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-01-11 05:16:13 -07:00
|
|
|
* Provides the contact form
|
|
|
|
* @ingroup SpecialPage
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
|
|
|
class SpecialContact extends SpecialPage {
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2009-01-11 05:16:13 -07:00
|
|
|
public function __construct() {
|
|
|
|
parent::__construct( 'Contact' );
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2011-12-02 07:29:26 -07:00
|
|
|
/**
|
|
|
|
* @see SpecialPage::getDescription
|
|
|
|
*/
|
|
|
|
function getDescription() {
|
2012-08-30 03:18:41 -06:00
|
|
|
return $this->msg( 'contactpage' )->text();
|
2011-12-02 07:29:26 -07:00
|
|
|
}
|
|
|
|
|
2007-02-12 14:50:29 -07:00
|
|
|
/**
|
|
|
|
* Main execution function
|
2009-01-11 05:16:13 -07:00
|
|
|
*
|
|
|
|
* @param $par Mixed: Parameters passed to the page
|
2012-08-30 03:18:41 -06:00
|
|
|
* @throws UserBlockedError
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
2009-01-11 05:16:13 -07:00
|
|
|
public function execute( $par ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
global $wgEnableEmail, $wgContactUser;
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2008-07-05 15:06:49 -06:00
|
|
|
if( !$wgEnableEmail || !$wgContactUser ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
|
2007-02-12 14:50:29 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
|
|
$action = $request->getVal( 'action' );
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2007-02-12 14:50:29 -07:00
|
|
|
$nu = User::newFromName( $wgContactUser );
|
2010-11-14 13:12:49 -07:00
|
|
|
if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
|
2007-02-12 14:50:29 -07:00
|
|
|
wfDebug( "Target is invalid user or can't receive.\n" );
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->getOutput()->showErrorPage( 'noemailtitle', 'noemailtext' );
|
2007-02-12 14:50:29 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2011-01-24 01:00:45 -07:00
|
|
|
// Blocked users cannot use the contact form if they're disabled from sending email.
|
2012-08-30 03:18:41 -06:00
|
|
|
if ( $user->isBlockedFromEmailuser() ) {
|
|
|
|
throw new UserBlockedError( $this->getUser()->mBlock );
|
2010-08-29 06:31:42 -06:00
|
|
|
}
|
|
|
|
|
2010-11-14 13:12:49 -07:00
|
|
|
$f = new EmailContactForm( $nu, $par );
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
if ( 'success' == $action ) {
|
|
|
|
wfDebug( __METHOD__ . ": success.\n" );
|
|
|
|
$f->showSuccess();
|
2012-08-30 03:18:41 -06:00
|
|
|
} elseif ( 'submit' == $action && $request->wasPosted() && $f->hasAllInfo() ) {
|
|
|
|
$token = $request->getVal( 'wpEditToken' );
|
2007-04-18 06:41:35 -06:00
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
if( $user->isAnon() ) {
|
2007-04-18 06:41:35 -06:00
|
|
|
# Anonymous users may not have a session
|
|
|
|
# open. Check for suffix anyway.
|
|
|
|
$tokenOk = ( EDIT_TOKEN_SUFFIX == $token );
|
|
|
|
} else {
|
2012-08-30 03:18:41 -06:00
|
|
|
$tokenOk = $user->matchEditToken( $token );
|
2007-04-18 06:41:35 -06:00
|
|
|
}
|
|
|
|
|
2007-10-13 05:41:44 -06:00
|
|
|
if ( !$tokenOk ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
wfDebug( __METHOD__ . ": bad token (" . ( $user->isAnon() ? 'anon' : 'user' ) . "): $token\n" );
|
|
|
|
$this->getOutput()->addWikiMsg( 'sessionfailure' );
|
2007-04-18 06:41:35 -06:00
|
|
|
$f->showForm();
|
2010-01-04 17:43:27 -07:00
|
|
|
} elseif ( !$f->passCaptcha() ) {
|
2009-01-11 05:16:13 -07:00
|
|
|
wfDebug( __METHOD__ . ": captcha failed" );
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->getOutput()->addWikiMsg( 'contactpage-captcha-failed' );
|
2007-10-13 05:41:44 -06:00
|
|
|
$f->showForm();
|
|
|
|
} else {
|
2009-01-11 05:16:13 -07:00
|
|
|
wfDebug( __METHOD__ . ": submit\n" );
|
2007-10-13 05:41:44 -06:00
|
|
|
$f->doSubmit();
|
2007-04-18 06:41:35 -06:00
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
} else {
|
2009-01-11 05:16:13 -07:00
|
|
|
wfDebug( __METHOD__ . ": form\n" );
|
2007-02-12 14:50:29 -07:00
|
|
|
$f->showForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo document
|
2009-01-11 05:16:13 -07:00
|
|
|
* @ingroup SpecialPage
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
|
|
|
class EmailContactForm {
|
|
|
|
var $target;
|
|
|
|
var $text, $subject;
|
2009-01-11 05:16:13 -07:00
|
|
|
var $cc_me; // Whether user requested to be sent a separate copy of their email.
|
2007-02-12 14:50:29 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $target
|
2012-08-30 03:18:41 -06:00
|
|
|
* @param $par
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
2010-11-14 10:08:48 -07:00
|
|
|
function __construct( $target, $par ) {
|
2007-02-12 14:50:29 -07:00
|
|
|
global $wgRequest, $wgUser;
|
2007-10-13 05:41:44 -06:00
|
|
|
|
2010-12-07 08:57:48 -07:00
|
|
|
$this->wasPosted = $wgRequest->wasPosted();
|
2010-11-15 11:48:54 -07:00
|
|
|
$this->formType = $wgRequest->getText( 'formtype', $par );
|
2011-06-17 10:25:46 -06:00
|
|
|
|
2010-11-14 10:08:48 -07:00
|
|
|
# Check for type in [[Special:Contact/type]]: change pagetext and prefill form fields
|
2010-11-15 11:48:54 -07:00
|
|
|
if ( $this->formType != '' ) {
|
|
|
|
$message = 'contactpage-pagetext-' . $this->formType;
|
2012-08-30 03:18:41 -06:00
|
|
|
$text = wfMessage( $message )->parseAsBlock();
|
|
|
|
if ( !wfMessage( $message, $text )->isDisabled() ) {
|
2010-11-14 10:08:48 -07:00
|
|
|
$this->formularText = $text;
|
|
|
|
} else {
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->formularText = wfMessage( 'contactpage-pagetext' )->parseAsBlock();
|
2010-11-14 10:08:48 -07:00
|
|
|
}
|
|
|
|
|
2010-11-15 11:48:54 -07:00
|
|
|
$message = 'contactpage-subject-' . $this->formType;
|
2012-08-30 03:18:41 -06:00
|
|
|
$text = wfMessage( $message )->inContentLanguage()->plain();
|
|
|
|
if ( !wfMessage( $message, $text )->isDisabled() ) {
|
2010-11-14 10:08:48 -07:00
|
|
|
$this->subject = $wgRequest->getText( 'wpSubject', $text );
|
|
|
|
} else {
|
|
|
|
$this->subject = $wgRequest->getText( 'wpSubject' );
|
|
|
|
}
|
|
|
|
|
2010-11-15 11:48:54 -07:00
|
|
|
$message = 'contactpage-text-' . $this->formType;
|
2012-08-30 03:18:41 -06:00
|
|
|
$text = wfMessage( $message )->inContentLanguage()->plain();
|
|
|
|
if ( !wfMessage( $message, $text )->isDisabled() ) {
|
2010-11-14 10:08:48 -07:00
|
|
|
$this->text = $wgRequest->getText( 'wpText', $text );
|
|
|
|
} else {
|
|
|
|
$this->text = $wgRequest->getText( 'wpText' );
|
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
} else {
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->formularText = wfMessage( 'contactpage-pagetext' )->parseAsBlock();
|
2010-11-14 10:08:48 -07:00
|
|
|
$this->text = $wgRequest->getText( 'wpText' );
|
|
|
|
$this->subject = $wgRequest->getText( 'wpSubject' );
|
|
|
|
}
|
|
|
|
|
2007-02-12 14:50:29 -07:00
|
|
|
$this->target = $target;
|
|
|
|
$this->cc_me = $wgRequest->getBool( 'wpCCMe' );
|
2010-03-28 07:23:42 -06:00
|
|
|
$this->includeIP = $wgRequest->getBool( 'wpIncludeIP' );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
|
|
|
$this->fromname = $wgRequest->getText( 'wpFromName' );
|
|
|
|
$this->fromaddress = $wgRequest->getText( 'wpFromAddress' );
|
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
if( $wgUser->isLoggedIn() ) {
|
2010-01-04 17:43:27 -07:00
|
|
|
if( !$this->fromname ) {
|
|
|
|
$this->fromname = $wgUser->getName();
|
|
|
|
}
|
|
|
|
if( !$this->fromaddress ) {
|
|
|
|
$this->fromaddress = $wgUser->getEmail();
|
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
// prepare captcha if applicable
|
2008-07-06 08:23:16 -06:00
|
|
|
if ( $this->useCaptcha() ) {
|
2008-06-26 07:06:55 -06:00
|
|
|
$captcha = ConfirmEditHooks::getInstance();
|
|
|
|
$captcha->trigger = 'contactpage';
|
|
|
|
$captcha->action = 'contact';
|
2007-10-13 05:41:44 -06:00
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
|
2008-07-05 15:20:32 -06:00
|
|
|
function hasAllInfo() {
|
|
|
|
global $wgContactRequireAll;
|
|
|
|
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( $this->text === null ) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$this->text = trim( $this->text );
|
|
|
|
}
|
|
|
|
if ( $this->text === '' ) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-05 15:20:32 -06:00
|
|
|
|
|
|
|
if ( $wgContactRequireAll ) {
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( $this->fromname === null ) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$this->fromname = trim( $this->fromname );
|
|
|
|
}
|
|
|
|
if ( $this->fromname === '' ) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-05 15:20:32 -06:00
|
|
|
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( $this->fromaddress === null ) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$this->fromaddress = trim( $this->fromaddress );
|
|
|
|
}
|
|
|
|
if ( $this->fromaddress === '' ) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-05 15:20:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-02-12 14:50:29 -07:00
|
|
|
function showForm() {
|
2012-08-30 03:18:41 -06:00
|
|
|
global $wgOut, $wgUser, $wgContactRequireAll, $wgContactIncludeIP;
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
# @todo Show captcha
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
$wgOut->setPageTitle( wfMessage( 'contactpage-title' ) );
|
2010-11-14 10:08:48 -07:00
|
|
|
$wgOut->addHTML( $this->formularText );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
if ( $this->subject === '' ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$this->subject = wfMessage( 'contactpage-defsubject' )->inContentLanguage()->text();
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
|
2008-07-05 15:20:32 -06:00
|
|
|
$msgSuffix = $wgContactRequireAll ? '-required' : '';
|
|
|
|
|
2008-11-04 01:19:56 -07:00
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Contact' );
|
|
|
|
$action = $titleObj->getLocalURL( 'action=submit' );
|
2012-08-30 03:18:41 -06:00
|
|
|
$token = $wgUser->isAnon() ? EDIT_TOKEN_SUFFIX : $wgUser->getEditToken(); //this kind of sucks, really...
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2010-01-04 17:43:27 -07:00
|
|
|
$form =
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'emailuser' ) ) .
|
|
|
|
Xml::openElement( 'fieldset' ) .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::element( 'legend', null, wfMessage( 'contactpage-legend' )->text() ) .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::openElement( 'table', array( 'id' => 'mailheader' ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'<tr>
|
|
|
|
<td class="mw-label">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::label( wfMessage( 'emailsubject' )->text(), 'wpSubject' ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
<td class="mw-input" id="mw-contactpage-subject">' .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::input( 'wpSubject', 60, $this->subject, array( 'type' => 'text', 'maxlength' => 200 ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
2008-11-04 01:19:56 -07:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-label">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::label( wfMessage( "contactpage-fromname$msgSuffix" )->text(), 'wpFromName' ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
<td class="mw-input" id="mw-contactpage-from">' .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::input( 'wpFromName', 60, $this->fromname, array( 'type' => 'text', 'maxlength' => 200 ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
2008-11-04 01:19:56 -07:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-label">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::label( wfMessage( "contactpage-fromaddress$msgSuffix" )->text(), 'wpFromAddress' ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
<td class="mw-input" id="mw-contactpage-address">' .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::input( 'wpFromAddress', 60, $this->fromaddress, array( 'type' => 'text', 'maxlength' => 200 ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
// Allow other extensions to add more fields into Special:Contact
|
|
|
|
wfRunHooks( 'ContactFormBeforeMessage', array( $this, &$form ) );
|
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
// @todo FIXME: Unescaped text is inserted into HTML here.
|
2010-01-04 17:43:27 -07:00
|
|
|
$form .= '<tr>
|
2008-11-04 01:19:56 -07:00
|
|
|
<td></td>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-input" id="mw-contactpage-formfootnote">
|
2012-08-30 03:18:41 -06:00
|
|
|
<small>' . wfMessage( "contactpage-formfootnotes$msgSuffix" )->text() . '</small>
|
2008-11-04 01:19:56 -07:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-label">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::label( wfMessage( 'emailmessage' )->text(), 'wpText' ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
<td class="mw-input">' .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::textarea( 'wpText', $this->text, 80, 20, array( 'id' => 'wpText' ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
2010-03-28 07:23:42 -06:00
|
|
|
</tr>';
|
2010-06-04 03:52:05 -06:00
|
|
|
if ( $wgContactIncludeIP && $wgUser->isLoggedIn() ) {
|
2010-03-28 07:23:42 -06:00
|
|
|
$form .= '<tr>
|
|
|
|
<td></td>
|
|
|
|
<td class="mw-input">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::checkLabel( wfMessage( 'contactpage-includeip' )->text(), 'wpIncludeIP', 'wpIncludeIP', false ) .
|
2010-03-28 07:23:42 -06:00
|
|
|
'</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
|
2010-12-07 08:57:48 -07:00
|
|
|
$ccme = $this->wasPosted ? $this->cc_me : $wgUser->getBoolOption( 'ccmeonemails' );
|
2010-03-28 07:23:42 -06:00
|
|
|
$form .= '<tr>
|
2008-11-04 01:19:56 -07:00
|
|
|
<td></td>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-input">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::checkLabel( wfMessage( 'emailccme' )->text(), 'wpCCMe', 'wpCCMe', $ccme ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'<br />' . $this->getCaptcha() .
|
|
|
|
'</td>
|
2008-11-04 01:19:56 -07:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td></td>
|
2010-01-04 17:43:27 -07:00
|
|
|
<td class="mw-submit">' .
|
2012-08-30 03:18:41 -06:00
|
|
|
Xml::submitButton( wfMessage( 'emailsend' )->text(), array( 'name' => 'wpSend', 'accesskey' => 's' ) ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
'</td>
|
|
|
|
</tr>' .
|
2010-10-29 09:32:44 -06:00
|
|
|
Html::hidden( 'wpEditToken', $token ) .
|
2010-11-15 11:48:54 -07:00
|
|
|
Html::hidden( 'formtype', $this->formType ) .
|
2008-11-04 01:19:56 -07:00
|
|
|
Xml::closeElement( 'table' ) .
|
|
|
|
Xml::closeElement( 'fieldset' ) .
|
2010-01-04 17:43:27 -07:00
|
|
|
Xml::closeElement( 'form' );
|
|
|
|
$wgOut->addHTML( $form );
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
|
2008-07-06 08:23:16 -06:00
|
|
|
function useCaptcha() {
|
|
|
|
global $wgCaptchaClass, $wgCaptchaTriggers, $wgUser;
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( !$wgCaptchaClass ) {
|
|
|
|
return false; // no captcha installed
|
|
|
|
}
|
|
|
|
if ( !@$wgCaptchaTriggers['contactpage'] ) {
|
|
|
|
return false; // don't trigger on contact form
|
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
|
2008-07-05 15:40:25 -06:00
|
|
|
if( $wgUser->isAllowed( 'skipcaptcha' ) ) {
|
2008-07-06 08:23:16 -06:00
|
|
|
wfDebug( "EmailContactForm::useCaptcha: user group allows skipping captcha\n" );
|
|
|
|
return false;
|
2008-07-05 15:40:25 -06:00
|
|
|
}
|
|
|
|
|
2008-07-06 08:23:16 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCaptcha() {
|
|
|
|
global $wgCaptcha;
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( !$this->useCaptcha() ) {
|
|
|
|
return '';
|
|
|
|
}
|
2008-07-06 08:23:16 -06:00
|
|
|
|
2008-06-29 16:46:04 -06:00
|
|
|
wfSetupSession(); #NOTE: make sure we have a session. May be required for captchas to work.
|
|
|
|
|
2010-01-04 17:43:27 -07:00
|
|
|
return '<div class="captcha">' .
|
|
|
|
$wgCaptcha->getForm() .
|
2012-08-30 03:18:41 -06:00
|
|
|
wfMessage( 'contactpage-captcha' )->parse() .
|
2007-10-13 05:41:44 -06:00
|
|
|
"</div>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function passCaptcha() {
|
2008-07-06 08:23:16 -06:00
|
|
|
global $wgCaptcha;
|
2010-01-04 17:43:27 -07:00
|
|
|
if ( !$this->useCaptcha() ) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
|
|
|
|
return $wgCaptcha->passCaptcha();
|
|
|
|
}
|
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
function doSubmit() {
|
2012-08-30 03:18:41 -06:00
|
|
|
global $wgOut, $wgUser, $wgRequest;
|
2010-10-29 15:55:29 -06:00
|
|
|
global $wgUserEmailUseReplyTo, $wgPasswordSender;
|
|
|
|
global $wgContactSender, $wgContactSenderName, $wgContactIncludeIP;
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2010-09-29 11:05:29 -06:00
|
|
|
$csender = $wgContactSender ? $wgContactSender : $wgPasswordSender;
|
2008-07-05 15:06:49 -06:00
|
|
|
$cname = $wgContactSenderName;
|
2012-08-30 03:18:41 -06:00
|
|
|
$senderIP = $wgRequest->getIP();
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
wfDebug( __METHOD__ . ": start\n" );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2009-02-19 20:47:30 -07:00
|
|
|
$targetAddress = new MailAddress( $this->target );
|
|
|
|
$replyto = null;
|
|
|
|
$contactSender = new MailAddress( $csender, $cname );
|
2008-07-05 15:06:49 -06:00
|
|
|
|
|
|
|
if ( !$this->fromaddress ) {
|
2009-02-19 20:47:30 -07:00
|
|
|
$submitterAddress = $contactSender;
|
2009-01-11 05:16:13 -07:00
|
|
|
} else {
|
2009-02-19 20:47:30 -07:00
|
|
|
$submitterAddress = new MailAddress( $this->fromaddress, $this->fromname );
|
|
|
|
if ( $wgUserEmailUseReplyTo ) {
|
|
|
|
$replyto = $submitterAddress;
|
|
|
|
}
|
2008-07-05 15:06:49 -06:00
|
|
|
}
|
|
|
|
|
2007-02-16 15:20:14 -07:00
|
|
|
$subject = trim( $this->subject );
|
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
if ( $subject === '' ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage( 'contactpage-defsubject' )->inContentLanguage()->text();
|
2007-02-16 15:20:14 -07:00
|
|
|
}
|
|
|
|
|
2010-06-04 03:52:05 -06:00
|
|
|
$includeIP = $wgContactIncludeIP && ( $this->includeIP || $wgUser->isAnon() );
|
2009-01-11 05:16:13 -07:00
|
|
|
if ( $this->fromname !== '' ) {
|
2010-03-28 07:23:42 -06:00
|
|
|
if ( $includeIP ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage(
|
|
|
|
'contactpage-subject-and-sender-withip',
|
|
|
|
$subject,
|
|
|
|
$this->fromname,
|
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
} else {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage(
|
|
|
|
'contactpage-subject-and-sender',
|
|
|
|
$subject,
|
|
|
|
$this->fromname
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
}
|
2010-01-04 17:43:27 -07:00
|
|
|
} elseif ( $this->fromaddress !== '' ) {
|
2010-03-28 07:23:42 -06:00
|
|
|
if ( $includeIP ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage(
|
|
|
|
'contactpage-subject-and-sender-withip',
|
|
|
|
$subject,
|
|
|
|
$this->fromaddress,
|
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
} else {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage(
|
|
|
|
'contactpage-subject-and-sender',
|
|
|
|
$subject,
|
|
|
|
$this->fromaddress
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
} elseif ( $includeIP ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$subject = wfMessage(
|
|
|
|
'contactpage-subject-and-sender',
|
|
|
|
$subject,
|
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2008-07-05 15:06:49 -06:00
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2010-11-15 11:48:54 -07:00
|
|
|
if( !wfRunHooks( 'ContactForm', array( &$targetAddress, &$replyto, &$subject, &$this->text, $this->formType ) ) ) {
|
2009-02-19 20:47:30 -07:00
|
|
|
wfDebug( __METHOD__ . ": aborted by hook\n" );
|
|
|
|
return;
|
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2010-01-04 17:43:27 -07:00
|
|
|
wfDebug( __METHOD__ . ": sending mail from " . $submitterAddress->toString() .
|
|
|
|
" to " . $targetAddress->toString().
|
|
|
|
" replyto " . ( $replyto == null ? '-/-' : $replyto->toString() ) . "\n" );
|
2007-02-14 16:45:20 -07:00
|
|
|
|
2009-02-19 20:47:30 -07:00
|
|
|
$mailResult = UserMailer::send( $targetAddress, $submitterAddress, $subject, $this->text, $replyto );
|
2007-02-14 16:45:20 -07:00
|
|
|
|
2009-02-19 20:47:30 -07:00
|
|
|
if( WikiError::isError( $mailResult ) ) {
|
|
|
|
$wgOut->addWikiMsg( 'usermailererror' ) . $mailResult->getMessage();
|
|
|
|
wfDebug( __METHOD__ . ": got error from UserMailer: " . $mailResult->getMessage() . "\n" );
|
|
|
|
return;
|
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2009-02-19 20:47:30 -07:00
|
|
|
// if the user requested a copy of this mail, do this now,
|
|
|
|
// unless they are emailing themselves, in which case one copy of the message is sufficient.
|
|
|
|
if( $this->cc_me && $this->fromaddress ) {
|
2012-08-30 03:18:41 -06:00
|
|
|
$cc_subject = wfMessage( 'emailccsubject', $this->target->getName(), $subject )->text();
|
2010-11-15 11:48:54 -07:00
|
|
|
if( wfRunHooks( 'ContactForm', array( &$submitterAddress, &$contactSender, &$cc_subject, &$this->text, $this->formType ) ) ) {
|
2010-01-04 17:43:27 -07:00
|
|
|
wfDebug( __METHOD__ . ": sending cc mail from " . $contactSender->toString() .
|
|
|
|
" to " . $submitterAddress->toString() . "\n" );
|
2009-02-19 20:47:30 -07:00
|
|
|
$ccResult = UserMailer::send( $submitterAddress, $contactSender, $cc_subject, $this->text );
|
|
|
|
if( WikiError::isError( $ccResult ) ) {
|
|
|
|
// At this stage, the user's CC mail has failed, but their
|
|
|
|
// original mail has succeeded. It's unlikely, but still, what to do?
|
|
|
|
// We can either show them an error, or we can say everything was fine,
|
|
|
|
// or we can say we sort of failed AND sort of succeeded. Of these options,
|
|
|
|
// simply saying there was an error is probably best.
|
2012-08-30 03:18:41 -06:00
|
|
|
$wgOut->addWikiText( wfMessage( 'usermailererror' )->text() . $ccResult );
|
2009-02-19 20:47:30 -07:00
|
|
|
return;
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 20:47:30 -07:00
|
|
|
wfDebug( __METHOD__ . ": success\n" );
|
|
|
|
|
|
|
|
$titleObj = SpecialPage::getTitleFor( 'Contact' );
|
2010-01-04 17:43:27 -07:00
|
|
|
$wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
|
2009-02-19 20:47:30 -07:00
|
|
|
wfRunHooks( 'ContactFromComplete', array( $targetAddress, $replyto, $subject, $this->text ) );
|
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
wfDebug( __METHOD__ . ": end\n" );
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
|
2009-01-11 05:16:13 -07:00
|
|
|
function showSuccess() {
|
2007-02-12 14:50:29 -07:00
|
|
|
global $wgOut;
|
|
|
|
|
2012-08-30 03:18:41 -06:00
|
|
|
$wgOut->setPageTitle( wfMessage( 'emailsent' ) );
|
2009-01-11 05:16:13 -07:00
|
|
|
$wgOut->addWikiMsg( 'emailsenttext' );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
}
|
2009-02-19 20:47:30 -07:00
|
|
|
}
|