From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- extensions/ConfirmEdit/MathCaptcha.class.php | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 extensions/ConfirmEdit/MathCaptcha.class.php (limited to 'extensions/ConfirmEdit/MathCaptcha.class.php') diff --git a/extensions/ConfirmEdit/MathCaptcha.class.php b/extensions/ConfirmEdit/MathCaptcha.class.php new file mode 100644 index 00000000..220df31d --- /dev/null +++ b/extensions/ConfirmEdit/MathCaptcha.class.php @@ -0,0 +1,57 @@ +pickSum(); + $index = $this->storeCaptcha( array( 'answer' => $answer ) ); + $resultArr['captcha']['type'] = 'math'; + $resultArr['captcha']['mime'] = 'text/tex'; + $resultArr['captcha']['id'] = $index; + $resultArr['captcha']['question'] = $sum; + } + + /** Produce a nice little form */ + function getForm() { + list( $sum, $answer ) = $this->pickSum(); + $index = $this->storeCaptcha( array( 'answer' => $answer ) ); + + $form = ''; + $form .= '
' . $this->fetchMath( $sum ) . '' . Xml::input( 'wpCaptchaWord', false, false, array( 'tabindex' => '1' ) ) . '
'; + $form .= Html::hidden( '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 ) { + // class_exists() unfortunately doesn't work with HipHop, and + // its replacement, MWInit::classExists(), wasn't added until + // MW 1.18, and is thus unusable here - so instead, we'll + // just duplicate the code of MWInit::classExists(). + try { + $r = new ReflectionClass( 'MathRenderer' ); + } catch( ReflectionException $r ) { + throw new MWException( 'MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.' ); + } + + $math = new MathRenderer( $sum ); + $math->setOutputMode( MW_MATH_PNG ); + $html = $math->render(); + return preg_replace( '/alt=".*?"/', '', $html ); + } +} -- cgit v1.2.3-54-g00ecf