Commit: 7c2b1a43837731a9131bb5cfc0bbfa42b4cf2536 Author: Christoph M. Becker <[email protected]> Wed, 25 Mar 2015 14:10:25 +0100 Parents: cb152975f72becfd94401eaafc6041ed906e5b58 Branches: master
Link: http://git.php.net/?p=web/wiki.git;a=commitdiff;h=7c2b1a43837731a9131bb5cfc0bbfa42b4cf2536 Log: moved registration spam prevention to new plugin Changed paths: M dokuwiki/inc/auth.php M dokuwiki/inc/html.php A dokuwiki/lib/plugins/phpreg/action.php A dokuwiki/lib/plugins/phpreg/plugin.info.txt Diff: diff --git a/dokuwiki/inc/auth.php b/dokuwiki/inc/auth.php index 8fa8ef7..4b1e6ce 100644 --- a/dokuwiki/inc/auth.php +++ b/dokuwiki/inc/auth.php @@ -962,12 +962,11 @@ function register() { // gather input $login = trim($auth->cleanUser($INPUT->post->str('login'))); $fullname = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $INPUT->post->str('fullname'))); - $spam = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $INPUT->post->str('spam'))); $email = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $INPUT->post->str('email'))); $pass = $INPUT->post->str('pass'); $passchk = $INPUT->post->str('passchk'); - if(empty($login) || empty($fullname) || empty($email) || empty($spam)) { + if(empty($login) || empty($fullname) || empty($email)) { msg($lang['regmissing'], -1); return false; } @@ -988,12 +987,6 @@ function register() { return false; } - // make sure the secret spam box was filled out correctly - if($spam != "[email protected]") { - msg("That wasn't the answer we were expecting",-1); - return false; - } - //okay try to create the user if(!$auth->triggerUserMod('create', array($login, $pass, $fullname, $email))) { msg($lang['reguexists'], -1); diff --git a/dokuwiki/inc/html.php b/dokuwiki/inc/html.php index b8135a3..495bdf9 100644 --- a/dokuwiki/inc/html.php +++ b/dokuwiki/inc/html.php @@ -1591,7 +1591,6 @@ function html_register(){ } $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs)); $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs)); - $form->addElement(form_makeTextField('spam', $_POST['spam'], 'To which email address do you have to send an email now?', '', 'block', array('size'=>'50'))); $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); $form->endFieldset(); html_form('register', $form); diff --git a/dokuwiki/lib/plugins/phpreg/action.php b/dokuwiki/lib/plugins/phpreg/action.php new file mode 100644 index 0000000..0a8c6d2 --- /dev/null +++ b/dokuwiki/lib/plugins/phpreg/action.php @@ -0,0 +1,88 @@ +<?php + +/** + * Registration spam prevention. + * + * @license GPL 3 (http://www.gnu.org/licenses/gpl.html) + * @author Christoph M. Becker <[email protected]> + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +/** + * The action class which is automatically instantiated by DokuWiki. + * + * @link https://www.dokuwiki.org/devel:action_plugins + */ +class action_plugin_phpreg extends DokuWiki_Action_Plugin +{ + /** + * Registers event handlers. + * + * @param Doku_Event_Handler $controller DokuWiki's event controller object. + * + * @return not required + */ + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook( + 'HTML_REGISTERFORM_OUTPUT', + 'BEFORE', + $this, + 'handle_registerform_output' + ); + $controller->register_hook( + 'ACTION_ACT_PREPROCESS', + 'BEFORE', + $this, + 'handle_act_preprocess', + array() + ); + } + + /** + * custom event handler + * + * @param Doku_Event $event event object by reference + * @param mixed $param the parameters passed to register_hook when this + * handler was registered + * + * @return not required + */ + public function handle_registerform_output(Doku_Event &$event, $param) + { + $pos = $event->data->findElementByAttribute('type', 'submit'); + if (!$pos) return; + $spam = isset($_POST['spam']) ? $_POST['spam'] : ''; + $out = form_makeTextField( + 'spam', $spam, + 'To which email address do you have to send an email now?', + '', 'block', array('size' => '50') + ); + $event->data->insertElement($pos, $out); + } + + /** + * Checks the spam-prevention. + * + * @param Doku_Event $event event object by reference + * @param mixed $param the parameters passed to register_hook when this + * handler was registered + * + * @return not required + */ + public function handle_act_preprocess(Doku_Event &$event, $param) + { + $act = $event->data; + if ($act != 'register' || !isset($_POST['save'])) { + return; + } + $spam = isset($_POST['spam']) ? $_POST['spam'] : ''; + $spam = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $spam)); + if ($spam != '[email protected]') { + msg("That wasn't the answer we were expecting", -1); + $_POST['save'] = false; + } + } +} diff --git a/dokuwiki/lib/plugins/phpreg/plugin.info.txt b/dokuwiki/lib/plugins/phpreg/plugin.info.txt new file mode 100644 index 0000000..4558050 --- /dev/null +++ b/dokuwiki/lib/plugins/phpreg/plugin.info.txt @@ -0,0 +1,7 @@ +base phpreg +author Christoph M. Becker +email [email protected] +date 2015-03-25 +name PHP Reg +desc Registration spam prevention +url http://git.php.net/?p=web/wiki.git;a=tree;f=dokuwiki/lib/plugins/phpreg -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
