Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/156052
Change subject: Readd CAPTCHA (ConfirmEdit extension) support ...................................................................... Readd CAPTCHA (ConfirmEdit extension) support Bug: 66811 Change-Id: I46041c24fedc6643fc56f9f53cd59ea5803ebd85 --- M ContactPage_body.php M i18n/en.json 2 files changed, 49 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContactPage refs/changes/52/156052/1 diff --git a/ContactPage_body.php b/ContactPage_body.php index 02eb34b..0f406ac 100644 --- a/ContactPage_body.php +++ b/ContactPage_body.php @@ -182,6 +182,16 @@ ); } + if ( $this->useCaptcha() ) { + $captchaHTML = $this->getCaptcha(); + $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' ); @@ -215,6 +225,8 @@ */ public function processInput( $formData ) { global $wgUserEmailUseReplyTo, $wgPasswordSender; + global $wgCaptcha; + $config = $this->getTypeConfig(); $request = $this->getRequest(); @@ -338,6 +350,11 @@ $text .= "{$name}: $value\n"; } + if ( $this->useCaptcha() && !$wgCaptcha->passCaptcha() ) { + // TODO proper i18n message + return wfMessage( 'contactpage-captcha-error' )->plain(); + } + // Stolen from Special:EmailUser $error = ''; if ( !wfRunHooks( 'EmailUser', array( &$targetAddress, &$submitterAddress, &$subject, &$text, &$error ) ) ) { @@ -391,4 +408,34 @@ 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() { + global $wgCaptcha; + + // 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"; + } } diff --git a/i18n/en.json b/i18n/en.json index 7ab032c..6c00184 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -17,5 +17,6 @@ "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-usermailererror": "Mail object returned error:", + "contactpage-captcha-error": "CAPTCHA error" } -- To view, visit https://gerrit.wikimedia.org/r/156052 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I46041c24fedc6643fc56f9f53cd59ea5803ebd85 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContactPage Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Cook879 <cook...@shoutwiki.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits