X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/blobdiff_plain/3578c2650437356874afa4b624f91da198a97b2b..c7b30198527052bc7db36acd3ee9e826bc1029db:/MathCaptcha.php?ds=sidebyside diff --git a/MathCaptcha.php b/MathCaptcha.php index ac214cf..8c815bf 100644 --- a/MathCaptcha.php +++ b/MathCaptcha.php @@ -4,55 +4,18 @@ * Captcha class using simple sums and the math renderer * Not brilliant, but enough to dissuade casual spam bots * - * @addtogroup Extensions + * @file + * @ingroup Extensions * @author Rob Church * @copyright © 2006 Rob Church * @licence GNU General Public Licence 2.0 */ -if( defined( 'MEDIAWIKI' ) ) { - - class MathCaptcha extends SimpleCaptcha { - - /** Validate a captcha response */ - function keyMatch( $req, $info ) { - return (int)$req->getVal( 'wpCaptchaAnswer' ) == (int)$info['answer']; - } - - /** Produce a nice little form */ - function getForm() { - list( $sum, $answer ) = $this->pickSum(); - $index = $this->storeCaptcha( array( 'answer' => $answer ) ); - - $form = ''; - $form .= '
' . $this->fetchMath( $sum ) . '' . wfInput( 'wpCaptchaAnswer', false, false, array( 'tabindex' => '1' ) ) . '
'; - $form .= wfHidden( 'wpCaptchaId', $index ); - return $form; - } - - /** Pick a random sum */ - function pickSum() { - $a = mt_rand( 0, 100 ); - $b = mt_rand( 0, 10 ); - $op = mt_rand( 0, 1 ) ? '+' : '-'; - $sum = "{$a} {$op} {$b} = "; - $ans = $op == '+' ? ( $a + $b ) : ( $a - $b ); - return array( $sum, $ans ); - } - - /** Fetch the math */ - function fetchMath( $sum ) { - $math = new MathRenderer( $sum ); - $math->setOutputMode( MW_MATH_PNG ); - $html = $math->render(); - return preg_replace( '/alt=".*"/', '', $html ); - } - - } - -} else { - echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); - die( 1 ); +if ( !defined( 'MEDIAWIKI' ) ) { + exit; } -?> \ No newline at end of file +require_once dirname( __FILE__ ) . '/ConfirmEdit.php'; +$wgCaptchaClass = 'MathCaptcha'; + +$wgAutoloadClasses['MathCaptcha'] = dirname( __FILE__ ) . '/MathCaptcha.class.php';