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
|
2014-02-17 16:16:48 -07:00
|
|
|
* @copyright © 2007-2014 Daniel Kinzler, Sam Reed
|
2018-04-13 17:50:35 -06:00
|
|
|
* @license GPL-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
|
|
|
*/
|
2014-02-17 16:16:48 -07:00
|
|
|
class SpecialContact extends UnlistedSpecialPage {
|
2015-03-02 19:51:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default value after registration
|
|
|
|
*/
|
|
|
|
public static function onRegistration() {
|
|
|
|
global $wgContactConfig, $wgSitename;
|
|
|
|
if ( $wgContactConfig['default']['SenderName'] === null ) {
|
|
|
|
$wgContactConfig['default']['SenderName'] = "Contact Form on $wgSitename";
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 13:11:39 -06:00
|
|
|
|
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
|
|
|
/**
|
2017-10-11 13:11:39 -06:00
|
|
|
* @inheritDoc
|
2011-12-02 07:29:26 -07:00
|
|
|
*/
|
2018-11-01 13:13:52 -06:00
|
|
|
public function getDescription() {
|
2012-08-30 03:18:41 -06:00
|
|
|
return $this->msg( 'contactpage' )->text();
|
2011-12-02 07:29:26 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $formType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getTypeConfig() {
|
|
|
|
global $wgContactConfig;
|
|
|
|
if ( isset( $wgContactConfig[$this->formType] ) ) {
|
2019-04-21 04:01:41 -06:00
|
|
|
/** @phan-suppress-next-line PhanTypeMismatchReturn */
|
2014-02-17 16:16:48 -07:00
|
|
|
return $wgContactConfig[$this->formType] + $wgContactConfig['default'];
|
|
|
|
}
|
|
|
|
return $wgContactConfig['default'];
|
|
|
|
}
|
|
|
|
|
2007-02-12 14:50:29 -07:00
|
|
|
/**
|
|
|
|
* Main execution function
|
2009-01-11 05:16:13 -07:00
|
|
|
*
|
2017-10-11 13:11:39 -06:00
|
|
|
* @param string|null $par Parameters passed to the page
|
2012-08-30 03:18:41 -06:00
|
|
|
* @throws UserBlockedError
|
2014-01-28 20:31:19 -07:00
|
|
|
* @throws ErrorPageError
|
2007-02-12 14:50:29 -07:00
|
|
|
*/
|
2009-01-11 05:16:13 -07:00
|
|
|
public function execute( $par ) {
|
2014-02-17 16:16:48 -07:00
|
|
|
global $wgEnableEmail;
|
2008-02-03 07:37:27 -07:00
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !$wgEnableEmail ) {
|
2014-01-28 20:31:19 -07:00
|
|
|
// From Special:EmailUser
|
2014-01-28 23:46:08 -07:00
|
|
|
throw new ErrorPageError( 'usermaildisabled', 'usermaildisabledtext' );
|
2014-01-28 20:31:19 -07:00
|
|
|
}
|
2014-02-17 16:16:48 -07:00
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$this->formType = strtolower( $request->getText( 'formtype', $par ) );
|
|
|
|
|
|
|
|
$config = $this->getTypeConfig();
|
2018-07-10 11:08:33 -06:00
|
|
|
|
|
|
|
if ( $config['MustBeLoggedIn'] ) {
|
|
|
|
$this->requireLogin( 'contactpage-mustbeloggedin' );
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !$config['RecipientUser'] ) {
|
|
|
|
$this->getOutput()->showErrorPage( 'contactpage-config-error-title',
|
|
|
|
'contactpage-config-error' );
|
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
|
|
|
$user = $this->getUser();
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$nu = User::newFromName( $config['RecipientUser'] );
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( is_null( $nu ) || !$nu->canReceiveEmail() ) {
|
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
|
|
|
}
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$pageTitle = '';
|
|
|
|
if ( $this->formType != '' ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$message = $this->msg( 'contactpage-title-' . $this->formType );
|
2014-02-17 16:16:48 -07:00
|
|
|
if ( !$message->isDisabled() ) {
|
|
|
|
$pageTitle = $message;
|
2007-04-18 06:41:35 -06:00
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2014-01-29 13:07:28 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
if ( $pageTitle === '' ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$pageTitle = $this->msg( 'contactpage-title' );
|
2014-02-17 16:16:48 -07:00
|
|
|
}
|
|
|
|
$this->getOutput()->setPageTitle( $pageTitle );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject = '';
|
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 != '' ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$message = $this->msg( 'contactpage-pagetext-' . $this->formType );
|
2014-01-28 22:56:14 -07:00
|
|
|
if ( !$message->isDisabled() ) {
|
2014-02-17 16:16:48 -07:00
|
|
|
$formText = $message->parseAsBlock();
|
2010-11-14 10:08:48 -07:00
|
|
|
} else {
|
2016-08-09 20:29:34 -06:00
|
|
|
$formText = $this->msg( 'contactpage-pagetext' )->parseAsBlock();
|
2010-11-14 10:08:48 -07:00
|
|
|
}
|
|
|
|
|
2016-08-09 20:29:34 -06:00
|
|
|
$message = $this->msg( 'contactpage-subject-' . $this->formType );
|
2014-01-28 22:56:14 -07:00
|
|
|
if ( !$message->isDisabled() ) {
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject = $message->inContentLanguage()->plain();
|
2010-11-14 10:08:48 -07:00
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
} else {
|
2016-08-09 20:29:34 -06:00
|
|
|
$formText = $this->msg( 'contactpage-pagetext' )->parseAsBlock();
|
2014-01-28 22:56:14 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject = trim( $subject );
|
2014-01-28 22:56:14 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
if ( $subject === '' ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg( 'contactpage-defsubject' )->inContentLanguage()->text();
|
2010-11-14 10:08:48 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$fromAddress = '';
|
|
|
|
$fromName = '';
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( $user->isLoggedIn() ) {
|
2014-02-17 16:16:48 -07:00
|
|
|
// Use real name if set
|
|
|
|
$realName = $user->getRealName();
|
|
|
|
if ( $realName ) {
|
|
|
|
$fromName = $realName;
|
|
|
|
} else {
|
|
|
|
$fromName = $user->getName();
|
2010-01-04 17:43:27 -07:00
|
|
|
}
|
2014-02-17 16:16:48 -07:00
|
|
|
$fromAddress = $user->getEmail();
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
|
2014-02-19 15:14:19 -07:00
|
|
|
$additional = $config['AdditionalFields'];
|
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
$formItems = [
|
|
|
|
'FromName' => [
|
2014-02-27 14:34:43 -07:00
|
|
|
'label-message' => 'contactpage-fromname',
|
2014-02-17 16:16:48 -07:00
|
|
|
'type' => 'text',
|
|
|
|
'required' => $config['RequireDetails'],
|
|
|
|
'default' => $fromName,
|
2017-05-17 12:43:37 -06:00
|
|
|
],
|
|
|
|
'FromAddress' => [
|
2014-02-27 14:34:43 -07:00
|
|
|
'label-message' => 'contactpage-fromaddress',
|
2014-02-17 16:16:48 -07:00
|
|
|
'type' => 'email',
|
|
|
|
'required' => $config['RequireDetails'],
|
|
|
|
'default' => $fromAddress,
|
2017-05-17 12:43:37 -06:00
|
|
|
],
|
|
|
|
'FromInfo' => [
|
2014-02-17 16:16:48 -07:00
|
|
|
'label' => '',
|
|
|
|
'type' => 'info',
|
2017-05-17 12:43:37 -06:00
|
|
|
'default' => Html::rawElement( 'small', [],
|
2018-08-08 09:25:02 -06:00
|
|
|
$this->msg( 'contactpage-formfootnotes' )->escaped()
|
2014-02-17 16:16:48 -07:00
|
|
|
),
|
|
|
|
'raw' => true,
|
2017-05-17 12:43:37 -06:00
|
|
|
],
|
|
|
|
'Subject' => [
|
2014-02-18 16:22:55 -07:00
|
|
|
'label-message' => 'emailsubject',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => $subject,
|
2017-05-17 12:43:37 -06:00
|
|
|
],
|
|
|
|
] + $additional + [
|
|
|
|
'CCme' => [
|
2014-02-17 16:16:48 -07:00
|
|
|
'label-message' => 'emailccme',
|
|
|
|
'type' => 'check',
|
|
|
|
'default' => $this->getUser()->getBoolOption( 'ccmeonemails' ),
|
2017-05-17 12:43:37 -06:00
|
|
|
],
|
|
|
|
'FormType' => [
|
2014-02-17 16:16:48 -07:00
|
|
|
'class' => 'HTMLHiddenField',
|
|
|
|
'label' => 'Type',
|
|
|
|
'default' => $this->formType,
|
2017-05-17 12:43:37 -06:00
|
|
|
]
|
|
|
|
];
|
2014-02-17 16:16:48 -07:00
|
|
|
|
|
|
|
if ( $config['IncludeIP'] && $user->isLoggedIn() ) {
|
2017-05-17 12:43:37 -06:00
|
|
|
$formItems['IncludeIP'] = [
|
2014-02-17 16:16:48 -07:00
|
|
|
'label-message' => 'contactpage-includeip',
|
|
|
|
'type' => 'check',
|
2017-05-17 12:43:37 -06:00
|
|
|
];
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
|
2014-08-24 14:57:00 -06:00
|
|
|
if ( $this->useCaptcha() ) {
|
2017-05-17 12:43:37 -06:00
|
|
|
$formItems['Captcha'] = [
|
2014-08-24 14:57:00 -06:00
|
|
|
'label-message' => 'captcha-label',
|
|
|
|
'type' => 'info',
|
|
|
|
'default' => $this->getCaptcha(),
|
|
|
|
'raw' => true,
|
2017-05-17 12:43:37 -06:00
|
|
|
];
|
2014-08-24 14:57:00 -06:00
|
|
|
}
|
|
|
|
|
2017-04-17 10:49:16 -06:00
|
|
|
$form = HTMLForm::factory( 'ooui',
|
2015-04-30 08:42:16 -06:00
|
|
|
$formItems, $this->getContext(), "contactpage-{$this->formType}"
|
|
|
|
);
|
2014-02-17 16:16:48 -07:00
|
|
|
$form->setWrapperLegendMsg( 'contactpage-legend' );
|
|
|
|
$form->setSubmitTextMsg( 'emailsend' );
|
2015-04-29 14:01:22 -06:00
|
|
|
if ( $this->formType != '' ) {
|
|
|
|
$form->setId( Sanitizer::escapeId( "contactpage-{$this->formType}" ) );
|
|
|
|
|
|
|
|
$msg = $this->msg( "contactpage-legend-{$this->formType}" );
|
|
|
|
if ( !$msg->isDisabled() ) {
|
|
|
|
$form->setWrapperLegendMsg( $msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
$msg = $this->msg( "contactpage-emailsend-{$this->formType}" );
|
|
|
|
if ( !$msg->isDisabled() ) {
|
|
|
|
$form->setSubmitTextMsg( $msg );
|
|
|
|
}
|
|
|
|
}
|
2017-05-17 12:43:37 -06:00
|
|
|
$form->setSubmitCallback( [ $this, 'processInput' ] );
|
2014-02-17 16:16:48 -07:00
|
|
|
$form->loadData();
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
// Stolen from Special:EmailUser
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !Hooks::run( 'EmailUserForm', [ &$form ] ) ) {
|
2014-02-17 16:16:48 -07:00
|
|
|
return;
|
2010-01-04 17:43:27 -07:00
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$result = $form->show();
|
2008-07-05 15:40:25 -06:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
|
|
|
|
$out = $this->getOutput();
|
2015-04-29 14:01:22 -06:00
|
|
|
$pageTitle = $this->msg( 'emailsent' );
|
|
|
|
$pageText = 'emailsenttext';
|
|
|
|
if ( $this->formType !== '' ) {
|
|
|
|
$msg = $this->msg( "contactpage-emailsent-{$this->formType}" );
|
|
|
|
if ( !$msg->isDisabled() ) {
|
|
|
|
$pageTitle = $msg;
|
|
|
|
}
|
|
|
|
if ( !$this->msg( "contactpage-emailsenttext-{$this->formType}" )->isDisabled() ) {
|
|
|
|
$pageText = "contactpage-emailsenttext-{$this->formType}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out->setPageTitle( $pageTitle );
|
|
|
|
$out->addWikiMsg( $pageText );
|
2008-07-06 08:23:16 -06:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$out->returnToMain( false );
|
|
|
|
} else {
|
2015-04-30 13:56:41 -06:00
|
|
|
if ( $config['RLStyleModules'] ) {
|
|
|
|
$this->getOutput()->addModuleStyles( $config['RLStyleModules'] );
|
|
|
|
}
|
|
|
|
if ( $config['RLModules'] ) {
|
|
|
|
$this->getOutput()->addModules( $config['RLModules'] );
|
|
|
|
}
|
2014-02-17 16:16:48 -07:00
|
|
|
$this->getOutput()->prependHTML( trim( $formText ) );
|
2010-01-04 17:43:27 -07:00
|
|
|
}
|
2007-10-13 05:41:44 -06:00
|
|
|
}
|
|
|
|
|
2014-01-28 19:47:23 -07:00
|
|
|
/**
|
2014-02-17 16:16:48 -07:00
|
|
|
* @param array $formData
|
|
|
|
* @return bool|string
|
|
|
|
* true: Form won't be displayed
|
|
|
|
* false: Form will be redisplayed
|
|
|
|
* string: Error message to display
|
2014-01-28 19:47:23 -07:00
|
|
|
*/
|
2014-02-17 16:16:48 -07:00
|
|
|
public function processInput( $formData ) {
|
2014-08-24 14:57:00 -06:00
|
|
|
global $wgUserEmailUseReplyTo, $wgPasswordSender, $wgCaptcha;
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$config = $this->getTypeConfig();
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $this->getUser();
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2019-07-06 16:43:48 -06:00
|
|
|
/* @var SimpleCaptcha $wgCaptcha */
|
|
|
|
if ( $this->useCaptcha() &&
|
|
|
|
!$wgCaptcha->passCaptchaFromRequest( $request, $user )
|
|
|
|
) {
|
|
|
|
return $this->msg( 'contactpage-captcha-error' )->plain();
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$senderIP = $request->getIP();
|
|
|
|
|
2014-11-19 15:08:51 -07:00
|
|
|
// Setup user that is going to recieve the contact page response
|
|
|
|
$contactRecipientUser = User::newFromName( $config['RecipientUser'] );
|
|
|
|
$contactRecipientAddress = MailAddress::newFromUser( $contactRecipientUser );
|
|
|
|
|
|
|
|
// Used when user hasn't set an email, or when sending CC email to user
|
|
|
|
$contactSender = new MailAddress(
|
|
|
|
$config['SenderEmail'] ?: $wgPasswordSender,
|
|
|
|
$config['SenderName']
|
|
|
|
);
|
|
|
|
|
|
|
|
$replyTo = null;
|
2008-07-05 15:06:49 -06:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
$fromAddress = $formData['FromAddress'];
|
|
|
|
$fromName = $formData['FromName'];
|
|
|
|
if ( !$fromAddress ) {
|
2014-11-19 15:08:51 -07:00
|
|
|
// No email address entered, so use $contactSender instead
|
|
|
|
$senderAddress = $contactSender;
|
2009-01-11 05:16:13 -07:00
|
|
|
} else {
|
2014-11-19 15:08:51 -07:00
|
|
|
// Use user submitted details
|
|
|
|
$senderAddress = new MailAddress( $fromAddress, $fromName );
|
2009-02-19 20:47:30 -07:00
|
|
|
if ( $wgUserEmailUseReplyTo ) {
|
2014-11-19 15:08:51 -07:00
|
|
|
// Define reply-to address
|
|
|
|
$replyTo = $senderAddress;
|
2009-02-19 20:47:30 -07:00
|
|
|
}
|
2008-07-05 15:06:49 -06:00
|
|
|
}
|
|
|
|
|
2014-11-15 05:56:07 -07:00
|
|
|
$includeIP = isset( $config['IncludeIP'] ) && $config['IncludeIP']
|
2015-03-31 05:06:52 -06:00
|
|
|
&& ( $user->isAnon() || $formData['IncludeIP'] );
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject = $formData['Subject'];
|
|
|
|
|
|
|
|
if ( $fromName !== '' ) {
|
2010-03-28 07:23:42 -06:00
|
|
|
if ( $includeIP ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg(
|
2012-08-30 03:18:41 -06:00
|
|
|
'contactpage-subject-and-sender-withip',
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject,
|
|
|
|
$fromName,
|
2012-08-30 03:18:41 -06:00
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
} else {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg(
|
2012-08-30 03:18:41 -06:00
|
|
|
'contactpage-subject-and-sender',
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject,
|
|
|
|
$fromName
|
2012-08-30 03:18:41 -06:00
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
}
|
2014-02-17 16:16:48 -07:00
|
|
|
} elseif ( $fromAddress !== '' ) {
|
2010-03-28 07:23:42 -06:00
|
|
|
if ( $includeIP ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg(
|
2012-08-30 03:18:41 -06:00
|
|
|
'contactpage-subject-and-sender-withip',
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject,
|
|
|
|
$fromAddress,
|
2012-08-30 03:18:41 -06:00
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
} else {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg(
|
2012-08-30 03:18:41 -06:00
|
|
|
'contactpage-subject-and-sender',
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject,
|
|
|
|
$fromAddress
|
2012-08-30 03:18:41 -06:00
|
|
|
)->inContentLanguage()->text();
|
2010-03-10 10:01:38 -07:00
|
|
|
}
|
2011-06-17 10:25:46 -06:00
|
|
|
} elseif ( $includeIP ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$subject = $this->msg(
|
2012-08-30 03:18:41 -06:00
|
|
|
'contactpage-subject-and-sender',
|
2014-02-17 16:16:48 -07:00
|
|
|
$subject,
|
2012-08-30 03:18:41 -06:00
|
|
|
$senderIP
|
|
|
|
)->inContentLanguage()->text();
|
2008-07-05 15:06:49 -06:00
|
|
|
}
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2014-02-19 15:14:19 -07:00
|
|
|
$text = '';
|
2017-05-17 12:43:37 -06:00
|
|
|
foreach ( $config['AdditionalFields'] as $name => $field ) {
|
2014-02-19 15:14:19 -07:00
|
|
|
$class = HTMLForm::getClassFromDescriptor( $name, $field );
|
|
|
|
|
|
|
|
$value = '';
|
|
|
|
// TODO: Support selectandother/HTMLSelectAndOtherField
|
|
|
|
// options, options-messages and options-message
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( isset( $field['options-messages'] ) ) { // Multiple values!
|
2014-02-19 15:14:19 -07:00
|
|
|
if ( is_string( $formData[$name] ) ) {
|
|
|
|
$optionValues = array_flip( $field['options-messages'] );
|
|
|
|
if ( isset( $optionValues[$formData[$name]] ) ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$value = $this->msg( $optionValues[$formData[$name]] )->inContentLanguage()->text();
|
2014-02-19 15:14:19 -07:00
|
|
|
} else {
|
|
|
|
$value = $formData[$name];
|
|
|
|
}
|
|
|
|
} elseif ( count( $formData[$name] ) ) {
|
|
|
|
$formValues = array_flip( $formData[$name] );
|
|
|
|
$value .= "\n";
|
2017-05-17 12:43:37 -06:00
|
|
|
foreach ( $field['options-messages'] as $msg => $optionValue ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$msg = $this->msg( $msg )->inContentLanguage()->text();
|
|
|
|
$optionValue = $this->getYesOrNoMsg( isset( $formValues[$optionValue] ) );
|
2014-02-19 15:14:19 -07:00
|
|
|
$value .= "\t$msg: $optionValue\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ( isset( $field['options'] ) ) {
|
|
|
|
if ( is_string( $formData[$name] ) ) {
|
|
|
|
$value = $formData[$name];
|
|
|
|
} elseif ( count( $formData[$name] ) ) {
|
|
|
|
$formValues = array_flip( $formData[$name] );
|
|
|
|
$value .= "\n";
|
2017-05-17 12:43:37 -06:00
|
|
|
foreach ( $field['options'] as $msg => $optionValue ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$optionValue = $this->getYesOrNoMsg( isset( $formValues[$optionValue] ) );
|
2014-02-19 15:14:19 -07:00
|
|
|
$value .= "\t$msg: $optionValue\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ( $class === 'HTMLCheckField' ) {
|
2017-05-17 12:43:37 -06:00
|
|
|
$value = $this->getYesOrNoMsg( $formData[$name] xor
|
|
|
|
( isset( $field['invert'] ) && $field['invert'] ) );
|
2014-02-19 15:14:19 -07:00
|
|
|
} elseif ( isset( $formData[$name] ) ) {
|
|
|
|
// HTMLTextField, HTMLTextAreaField
|
|
|
|
// HTMLFloatField, HTMLIntField
|
|
|
|
|
|
|
|
// Just dump the value if its wordy
|
|
|
|
$value = $formData[$name];
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:10:37 -06:00
|
|
|
if ( isset( $field['contactpage-email-label'] ) ) {
|
|
|
|
$name = $field['contactpage-email-label'];
|
|
|
|
} elseif ( isset( $field['label-message'] ) ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$name = $this->msg( $field['label-message'] )->inContentLanguage()->text();
|
2014-02-19 15:14:19 -07:00
|
|
|
} else {
|
|
|
|
$name = $field['label'];
|
|
|
|
}
|
2007-02-14 16:45:20 -07:00
|
|
|
|
2014-02-19 15:14:19 -07:00
|
|
|
$text .= "{$name}: $value\n";
|
|
|
|
}
|
2014-02-17 16:16:48 -07:00
|
|
|
|
|
|
|
// Stolen from Special:EmailUser
|
|
|
|
$error = '';
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !Hooks::run( 'EmailUser', [ &$contactRecipientAddress, &$senderAddress, &$subject,
|
|
|
|
&$text, &$error ] )
|
|
|
|
) {
|
2014-02-17 16:16:48 -07:00
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !Hooks::run( 'ContactForm', [ &$contactRecipientAddress, &$replyTo, &$subject,
|
|
|
|
&$text, $this->formType, $formData ] )
|
|
|
|
) {
|
2014-02-17 16:16:48 -07:00
|
|
|
return false; // TODO: Need to do some proper error handling here
|
|
|
|
}
|
|
|
|
|
2014-11-19 15:08:51 -07:00
|
|
|
wfDebug( __METHOD__ . ': sending mail from ' . $senderAddress->toString() .
|
2018-09-02 18:12:52 -06:00
|
|
|
' to ' . $contactRecipientAddress->toString() .
|
2014-11-19 15:08:51 -07:00
|
|
|
' replyto ' . ( $replyTo == null ? '-/-' : $replyTo->toString() ) . "\n"
|
2014-02-19 15:14:19 -07:00
|
|
|
);
|
2016-01-18 14:45:12 -07:00
|
|
|
$mailResult = UserMailer::send(
|
|
|
|
$contactRecipientAddress,
|
|
|
|
$senderAddress,
|
|
|
|
$subject,
|
|
|
|
$text,
|
2017-05-17 12:43:37 -06:00
|
|
|
[ 'replyTo' => $replyTo ]
|
2016-01-18 14:45:12 -07:00
|
|
|
);
|
2007-02-14 16:45:20 -07:00
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !$mailResult->isOK() ) {
|
2014-01-28 23:46:08 -07:00
|
|
|
wfDebug( __METHOD__ . ': got error from UserMailer: ' . $mailResult->getMessage() . "\n" );
|
2016-08-09 20:29:34 -06:00
|
|
|
return $this->msg( 'contactpage-usermailererror' )->text() . $mailResult->getMessage();
|
2009-02-19 20:47:30 -07:00
|
|
|
}
|
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.
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( $formData['CCme'] && $fromAddress ) {
|
2016-08-09 20:29:34 -06:00
|
|
|
$cc_subject = $this->msg( 'emailccsubject', $contactRecipientUser->getName(), $subject )->text();
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( Hooks::run( 'ContactForm',
|
|
|
|
[ &$senderAddress, &$contactSender, &$cc_subject, &$text, $this->formType, $formData ] )
|
2014-11-19 15:08:51 -07:00
|
|
|
) {
|
2014-01-28 23:46:08 -07:00
|
|
|
wfDebug( __METHOD__ . ': sending cc mail from ' . $contactSender->toString() .
|
2014-11-19 15:08:51 -07:00
|
|
|
' to ' . $senderAddress->toString() . "\n"
|
2014-02-19 15:14:19 -07:00
|
|
|
);
|
2014-11-19 15:08:51 -07:00
|
|
|
$ccResult = UserMailer::send( $senderAddress, $contactSender, $cc_subject, $text );
|
2017-05-17 12:43:37 -06:00
|
|
|
if ( !$ccResult->isOK() ) {
|
2009-02-19 20:47:30 -07:00
|
|
|
// 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.
|
2016-08-09 20:29:34 -06:00
|
|
|
return $this->msg( 'contactpage-usermailererror' )->text() . $ccResult->getMessage();
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 12:43:37 -06:00
|
|
|
Hooks::run( 'ContactFromComplete', [ $contactRecipientAddress, $replyTo, $subject, $text ] );
|
2007-02-12 14:50:29 -07:00
|
|
|
|
2014-02-17 16:16:48 -07:00
|
|
|
return true;
|
2007-02-12 14:50:29 -07:00
|
|
|
}
|
2014-02-19 15:14:19 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $value
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-08-09 20:29:34 -06:00
|
|
|
private function getYesOrNoMsg( $value ) {
|
|
|
|
return $this->msg( $value ? 'htmlform-yes' : 'htmlform-no' )->inContentLanguage()->text();
|
2014-02-19 15:14:19 -07:00
|
|
|
}
|
2014-08-24 14:57:00 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return boolean True if CAPTCHA should be used, false otherwise
|
|
|
|
*/
|
|
|
|
private function useCaptcha() {
|
|
|
|
global $wgCaptchaClass, $wgCaptchaTriggers;
|
|
|
|
|
|
|
|
return $wgCaptchaClass &&
|
|
|
|
isset( $wgCaptchaTriggers['contactpage'] ) &&
|
|
|
|
$wgCaptchaTriggers['contactpage'] &&
|
|
|
|
!$this->getUser()->isAllowed( 'skipcaptcha' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string CAPTCHA form HTML
|
|
|
|
*/
|
|
|
|
private function getCaptcha() {
|
|
|
|
// NOTE: make sure we have a session. May be required for CAPTCHAs to work.
|
2016-05-17 11:57:38 -06:00
|
|
|
\MediaWiki\Session\SessionManager::getGlobalSession()->persist();
|
2014-08-24 14:57:00 -06:00
|
|
|
|
|
|
|
$captcha = ConfirmEditHooks::getInstance();
|
2016-05-17 11:57:38 -06:00
|
|
|
$captcha->setTrigger( 'contactpage' );
|
|
|
|
$captcha->setAction( 'contact' );
|
2014-08-24 14:57:00 -06:00
|
|
|
|
2016-08-03 10:43:50 -06:00
|
|
|
$formInformation = $captcha->getFormInformation();
|
|
|
|
$formMetainfo = $formInformation;
|
|
|
|
unset( $formMetainfo['html'] );
|
|
|
|
$captcha->addFormInformationToOutput( $this->getOutput(), $formMetainfo );
|
|
|
|
|
2014-08-24 14:57:00 -06:00
|
|
|
return '<div class="captcha">' .
|
2016-08-03 10:43:50 -06:00
|
|
|
$formInformation['html'] .
|
2014-08-24 14:57:00 -06:00
|
|
|
"</div>\n";
|
|
|
|
}
|
2009-02-19 20:47:30 -07:00
|
|
|
}
|