r104875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104874‎ | r104875 | r104876 >
Date:16:59, 1 December 2011
Author:mah
Status:ok (Comments)
Tags:miscextensions 
Comment:
Initial, pre-test, commit of modified patch for Bug 31608 - API edit support for reCAPTCHA

From the comment:

This patch implements addCaptchaAPI and removes ConfirmEdit, since
it's unnecessary - it seems it was reimplemented in ReCaptcha to
detect when the captcha had to be shown for the first time and not
show an error message, but a minor change to passCaptcha ( if (
$response === null ) { return false; } ) accomplishes that.

Because the api edit module sets wpCaptchaId and wpCaptchaWord,
those are passed to recaptcha as recaptcha_challenge_field and
recaptcha_response_field if the latter two are not set. The api
returns only the public key and the error message - the client can
use this to ask the recaptcha server for a captcha, it works in
javascript at least.

Will test and comment further.
Modified paths:
  • /trunk/extensions/ConfirmEdit/ReCaptcha.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmEdit/ReCaptcha.php
@@ -87,12 +87,22 @@
8888 */
8989 function passCaptcha() {
9090 global $wgReCaptchaPrivateKey;
 91+ global $wgRequest;
 92+
 93+ //API is hardwired to return wpCaptchaId and wpCaptchaWord, so use that if the standard two are empty
 94+ $challenge = $wgRequest->getVal('recaptcha_challenge_field',$wgRequest->getVal('wpCaptchaId'));
 95+ $response = $wgRequest->getVal('recaptcha_response_field',$wgRequest->getVal('wpCaptchaWord'));
 96+ if ( $response === null ) {
 97+ //new captcha session
 98+ return false;
 99+ }
 100+
91101 $recaptcha_response =
92102 recaptcha_check_answer (
93103 $wgReCaptchaPrivateKey,
94104 wfGetIP (),
95 - $_POST['recaptcha_challenge_field'],
96 - $_POST['recaptcha_response_field']
 105+ $challenge,
 106+ $response
97107 );
98108 if (!$recaptcha_response->is_valid) {
99109 $this->recaptcha_error = $recaptcha_response->error;
@@ -103,31 +113,12 @@
104114
105115 }
106116
107 - /**
108 - * Called on all edit page saves. (EditFilter events)
109 - * @return boolean - true if page save should continue, false if should display Captcha widget.
110 - */
111 - function confirmEdit( $editPage, $newtext, $section, $merged = false ) {
112 - if( $this->shouldCheck( $editPage, $newtext, $section ) ) {
113 -
114 - if (!isset($_POST['recaptcha_response_field'])) {
115 - //User has not yet been presented with Captcha, show the widget.
116 - $editPage->showEditForm( array( &$this, 'editCallback' ) );
117 - return false;
118 - }
119 -
120 - if( $this->passCaptcha() ) {
121 - return true;
122 - } else {
123 - //Try again - show the widget
124 - $editPage->showEditForm( array( &$this, 'editCallback' ) );
125 - return false;
126 - }
127 -
128 - } else {
129 - wfDebug( "ConfirmEdit: no need to show captcha.\n" );
130 - return true;
131 - }
 117+ function addCaptchaAPI( &$resultArr ) {
 118+ global $wgReCaptchaPublicKey;
 119+ $resultArr['captcha']['type'] = 'recaptcha';
 120+ $resultArr['captcha']['mime'] = 'image/png';
 121+ $resultArr['captcha']['key'] = $wgReCaptchaPublicKey;
 122+ $resultArr['captcha']['error'] = $this->recaptcha_error;
132123 }
133124
134125 /**

Comments

#Comment by MarkAHershberger (talk | contribs)   17:22, 1 December 2011

tested old pre-api use and it worked

#Comment by Duplicatebug (talk | contribs)   21:00, 1 December 2011
Because the api edit module sets wpCaptchaId and wpCaptchaWord

That was changed with r104064

#Comment by Reedy (talk | contribs)   21:29, 27 January 2012

Does this need any further work?

Status & tagging log