Readd CAPTCHA (ConfirmEdit extension) support
Bug: 66811 Change-Id: I46041c24fedc6643fc56f9f53cd59ea5803ebd85
This commit is contained in:
parent
ec6d99e181
commit
daa666dec4
|
@ -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 = new HTMLForm( $formItems, $this->getContext(), "contactpage-{$this->formType}" );
|
||||||
$form->setWrapperLegendMsg( 'contactpage-legend' );
|
$form->setWrapperLegendMsg( 'contactpage-legend' );
|
||||||
$form->setSubmitTextMsg( 'emailsend' );
|
$form->setSubmitTextMsg( 'emailsend' );
|
||||||
|
@ -214,7 +223,8 @@ class SpecialContact extends UnlistedSpecialPage {
|
||||||
* string: Error message to display
|
* string: Error message to display
|
||||||
*/
|
*/
|
||||||
public function processInput( $formData ) {
|
public function processInput( $formData ) {
|
||||||
global $wgUserEmailUseReplyTo, $wgPasswordSender;
|
global $wgUserEmailUseReplyTo, $wgPasswordSender, $wgCaptcha;
|
||||||
|
|
||||||
$config = $this->getTypeConfig();
|
$config = $this->getTypeConfig();
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
@ -338,6 +348,10 @@ class SpecialContact extends UnlistedSpecialPage {
|
||||||
$text .= "{$name}: $value\n";
|
$text .= "{$name}: $value\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $this->useCaptcha() && !$wgCaptcha->passCaptcha() ) {
|
||||||
|
return wfMessage( 'contactpage-captcha-error' )->plain();
|
||||||
|
}
|
||||||
|
|
||||||
// Stolen from Special:EmailUser
|
// Stolen from Special:EmailUser
|
||||||
$error = '';
|
$error = '';
|
||||||
if ( !wfRunHooks( 'EmailUser', array( &$targetAddress, &$submitterAddress, &$subject, &$text, &$error ) ) ) {
|
if ( !wfRunHooks( 'EmailUser', array( &$targetAddress, &$submitterAddress, &$subject, &$text, &$error ) ) ) {
|
||||||
|
@ -391,4 +405,32 @@ class SpecialContact extends UnlistedSpecialPage {
|
||||||
private static function getYesOrNoMsg( $value ) {
|
private static function getYesOrNoMsg( $value ) {
|
||||||
return wfMessage( $value ? 'htmlform-yes' : 'htmlform-no' )->inContentLanguage()->text();
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
39
i18n/en.json
39
i18n/en.json
|
@ -1,21 +1,22 @@
|
||||||
{
|
{
|
||||||
"@metadata": {
|
"@metadata": {
|
||||||
"authors": [
|
"authors": [
|
||||||
"Daniel Kinzler",
|
"Daniel Kinzler",
|
||||||
"Reedy"
|
"Reedy"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"contactpage": "Contact page",
|
"contactpage": "Contact page",
|
||||||
"contactpage-desc": "[[Special:Contact|Contact form for visitors]]",
|
"contactpage-desc": "[[Special:Contact|Contact form for visitors]]",
|
||||||
"contactpage-title": "Contact",
|
"contactpage-title": "Contact",
|
||||||
"contactpage-pagetext": "Please use the form below to contact us.",
|
"contactpage-pagetext": "Please use the form below to contact us.",
|
||||||
"contactpage-legend": "Send email",
|
"contactpage-legend": "Send email",
|
||||||
"contactpage-defsubject": "Contact message",
|
"contactpage-defsubject": "Contact message",
|
||||||
"contactpage-subject-and-sender": "$1 (from $2)",
|
"contactpage-subject-and-sender": "$1 (from $2)",
|
||||||
"contactpage-subject-and-sender-withip": "$1 (from $2 at $3)",
|
"contactpage-subject-and-sender-withip": "$1 (from $2 at $3)",
|
||||||
"contactpage-fromname": "Your name:",
|
"contactpage-fromname": "Your name:",
|
||||||
"contactpage-fromaddress": "Your email address:",
|
"contactpage-fromaddress": "Your email address:",
|
||||||
"contactpage-formfootnotes": "(needed if you want an answer)",
|
"contactpage-formfootnotes": "(needed if you want an answer)",
|
||||||
"contactpage-includeip": "Include my IP address in this message.",
|
"contactpage-includeip": "Include my IP address in this message.",
|
||||||
"contactpage-usermailererror": "Mail object returned error:"
|
"contactpage-usermailererror": "Mail object returned error:",
|
||||||
|
"contactpage-captcha-error": "CAPTCHA error"
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@
|
||||||
"contactpage-fromaddress": "{{Identical|E-mail address}}",
|
"contactpage-fromaddress": "{{Identical|E-mail address}}",
|
||||||
"contactpage-formfootnotes": "Message to notify users that an email address is needed if an answer is required",
|
"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-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.)"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue