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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,6 @@
|
||||||
"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