Recaptcha & Discussion

I wrote 2 patches to enable reCaptcha in the discussion plugins.

These 2 modifications are link together, don't try to change discussion without modifying recaptcha, it will lead to error. And change only recaptcha, will display useless captcha form on your discussion.

ReCaptcha

2 modifications here:

  • Display the captcha on the discussion form if the user is not registred.
  • A small modification in the recaptcha validation method.

I only modified the file action.php in /lib/plugins/recaptcha (version 2008-06-17)

49a50,63
> 	     // old hook
> 		$controller->register_hook('HTML_EDITFORM_INJECTION',
> 					   'BEFORE',
> 					   $this,
> 					   'insert',
> 					   array('editform' => true, 'oldhook' => true)); 
> 	
> 		// new hook
> 		$controller->register_hook('HTML_EDITFORM_OUTPUT',
> 					   'BEFORE',
> 					   $this,
> 					   'insert',
> 					   array('editform' => true, 'oldhook' => false));
> 
61a76,80
> 	// do nothing if logged in user and no CAPTCHA required
> 	if(!$this->getConf('forusers') && $_SERVER['REMOTE_USER']){
> 		return;
> 	}
> 
95,97c114,117
<         // check if we are in a registration process
<         if(!('register' == $act && $_POST['save'])) {
<             return;
---
> 	
> 	// do nothing if logged in user and no CAPTCHA required
> 	if(!$this->getConf('forusers') && $_SERVER['REMOTE_USER']){
> 		return(0);
98a119,120
> 	
> 	if (($act == 'register' && $_POST['save']) || ($act == 'show' && $_REQUEST['comment'] == 'add')) {
106c128,129
<             $_POST['save']  = false;
---
> 			$_POST['save']  = 0;  #for register
> 			return 'recapchta not valid';
108c131,133
< 
---
> 		return (0);
> 	}
> 	return 'unknown action';

You can also see the action.php file with this diff applied. action.php.recaptcha.20080617.txt

You can also download this file, rename it “action.php” & put it in your recaptcha plugins directory. But be sure you are using the same version as me.

Discussion

In this plugins, I just added a support for Recaptcha:

  • Discussion detect if ReCaptache plugins is present.
  • define a new method for the captcha validation.

I only modified the file action.php in /lib/plugins/discussion (version 2008-08-08)

70,72c70,75
<         // enable captchas
<         if ((in_array($_REQUEST['comment'], array('add', 'save')))
<                 && (@file_exists(DOKU_PLUGIN.'captcha/action.php'))) {
---
>         // enable [re]captchas
>         if (in_array($_REQUEST['comment'], array('add', 'save'))) {
> 		if(@file_exists(DOKU_PLUGIN.'recaptcha/action.php')) {
> 			$this->_recaptchaCheck($event);
> 		}
> 		if (@file_exists(DOKU_PLUGIN.'captcha/action.php')) {
74a78
> 	}
1103a1108,1130
> * Checks if the RECAPTCHA string submitted is valid
> *
> * @author     Aurélien ANTOINE http://ilpleut.be
> */
> function _recaptchaCheck(&$event) {
> 	require_once(DOKU_PLUGIN.'recaptcha/action.php');
> 	
> 	// do nothing if logged in user and no CAPTCHA required
> 	if(!$this->getConf('forusers') && $_SERVER['REMOTE_USER']){
> 		return;
> 	}
> 	
> 	$recaptcha = new action_plugin_recaptcha;
> 
> 	$recaptcha_error = $recaptcha->preprocess($event, array());
> 
> 	if($recaptcha_error) {
> 		if ($_REQUEST['comment'] == 'save') $_REQUEST['comment'] = 'edit';
> 		elseif ($_REQUEST['comment'] == 'add') $_REQUEST['comment'] = 'show';
> 	}
> }
> 
>     /**

You can also see the action.php file with this diff applied. action.php.discussion.20080808.txt

You can also download this file, rename it “action.php” & put it in your discussion plugins directory. But be sure you are using the same version as me.

code/dokuwiki/recaptcha_discussion.txt · Last modified: 2008/12/28 16:03 by aurelien
Creative Commons License Driven by DokuWiki Recent changes RSS feed