Readd CAPTCHA (ConfirmEdit extension) support

Bug: 66811
Change-Id: I46041c24fedc6643fc56f9f53cd59ea5803ebd85
This commit is contained in:
Cook879 2014-08-24 23:57:00 +03:00 committed by Jack Phoenix
parent ec6d99e181
commit daa666dec4
3 changed files with 65 additions and 21 deletions

View File

@ -182,6 +182,15 @@ class SpecialContact extends UnlistedSpecialPage {
);
}
if ( $this->useCaptcha() ) {
$formItems['Captcha'] = array(
'label-message' => 'captcha-label',
'type' => 'info',
'default' => $this->getCaptcha(),
'raw' => true,
);
}
$form = new HTMLForm( $formItems, $this->getContext(), "contactpage-{$this->formType}" );
$form->setWrapperLegendMsg( 'contactpage-legend' );
$form->setSubmitTextMsg( 'emailsend' );
@ -214,7 +223,8 @@ class SpecialContact extends UnlistedSpecialPage {
* string: Error message to display
*/
public function processInput( $formData ) {
global $wgUserEmailUseReplyTo, $wgPasswordSender;
global $wgUserEmailUseReplyTo, $wgPasswordSender, $wgCaptcha;
$config = $this->getTypeConfig();
$request = $this->getRequest();
@ -338,6 +348,10 @@ class SpecialContact extends UnlistedSpecialPage {
$text .= "{$name}: $value\n";
}
if ( $this->useCaptcha() && !$wgCaptcha->passCaptcha() ) {
return wfMessage( 'contactpage-captcha-error' )->plain();
}
// Stolen from Special:EmailUser
$error = '';
if ( !wfRunHooks( 'EmailUser', array( &$targetAddress, &$submitterAddress, &$subject, &$text, &$error ) ) ) {
@ -391,4 +405,32 @@ class SpecialContact extends UnlistedSpecialPage {
private static function getYesOrNoMsg( $value ) {
return wfMessage( $value ? 'htmlform-yes' : 'htmlform-no' )->inContentLanguage()->text();
}
/**
* @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.
wfSetupSession();
$captcha = ConfirmEditHooks::getInstance();
$captcha->trigger = 'contactpage';
$captcha->action = 'contact';
return '<div class="captcha">' .
$captcha->getForm() .
"</div>\n";
}
}

View File

@ -1,21 +1,22 @@
{
"@metadata": {
"authors": [
"Daniel Kinzler",
"Reedy"
]
},
"contactpage": "Contact page",
"contactpage-desc": "[[Special:Contact|Contact form for visitors]]",
"contactpage-title": "Contact",
"contactpage-pagetext": "Please use the form below to contact us.",
"contactpage-legend": "Send email",
"contactpage-defsubject": "Contact message",
"contactpage-subject-and-sender": "$1 (from $2)",
"contactpage-subject-and-sender-withip": "$1 (from $2 at $3)",
"contactpage-fromname": "Your name:",
"contactpage-fromaddress": "Your email address:",
"contactpage-formfootnotes": "(needed if you want an answer)",
"contactpage-includeip": "Include my IP address in this message.",
"contactpage-usermailererror": "Mail object returned error:"
"@metadata": {
"authors": [
"Daniel Kinzler",
"Reedy"
]
},
"contactpage": "Contact page",
"contactpage-desc": "[[Special:Contact|Contact form for visitors]]",
"contactpage-title": "Contact",
"contactpage-pagetext": "Please use the form below to contact us.",
"contactpage-legend": "Send email",
"contactpage-defsubject": "Contact message",
"contactpage-subject-and-sender": "$1 (from $2)",
"contactpage-subject-and-sender-withip": "$1 (from $2 at $3)",
"contactpage-fromname": "Your name:",
"contactpage-fromaddress": "Your email address:",
"contactpage-formfootnotes": "(needed if you want an answer)",
"contactpage-includeip": "Include my IP address in this message.",
"contactpage-usermailererror": "Mail object returned error:",
"contactpage-captcha-error": "CAPTCHA error"
}

View File

@ -22,5 +22,6 @@
"contactpage-fromaddress": "{{Identical|E-mail address}}",
"contactpage-formfootnotes": "Message to notify users that an email address is needed if an answer is required",
"contactpage-includeip": "Used as checkbox label in the ContactPage form.",
"contactpage-usermailererror": "Error message displayed when no email could be sent by the MediWiki UserMailer script."
"contactpage-usermailererror": "Error message displayed when no email could be sent by the MediWiki UserMailer script.",
"contactpage-captcha-error": "Error message displayed when there was a CAPTCHA error (i.e. the user failed to enter the correct CAPTCHA, or didn't enter one at all, etc.)"
}