From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- .../ConfirmEdit/MathCaptcha/MathCaptcha.class.php | 50 ++++++++++++++++++++++ extensions/ConfirmEdit/MathCaptcha/MathCaptcha.php | 13 ++++++ extensions/ConfirmEdit/MathCaptcha/extension.json | 9 ++++ 3 files changed, 72 insertions(+) create mode 100644 extensions/ConfirmEdit/MathCaptcha/MathCaptcha.class.php create mode 100644 extensions/ConfirmEdit/MathCaptcha/MathCaptcha.php create mode 100644 extensions/ConfirmEdit/MathCaptcha/extension.json (limited to 'extensions/ConfirmEdit/MathCaptcha') diff --git a/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.class.php b/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.class.php new file mode 100644 index 00000000..d3e4af69 --- /dev/null +++ b/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.class.php @@ -0,0 +1,50 @@ +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 ) . '' . Html::input( 'wpCaptchaWord', false, false, array( 'tabindex' => '1', 'autocomplete' => 'off', 'required' ) ) . '
'; + $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 ) { + if ( class_exists( 'MathRenderer' ) ) { + $math = MathRenderer::getRenderer( $sum, array(), MW_MATH_PNG ); + } else { + throw new Exception( 'MathCaptcha requires the Math extension for MediaWiki versions 1.18 and above.' ); + } + $html = $math->render(); + return preg_replace( '/alt=".*?"/', '', $html ); + } +} diff --git a/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.php b/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.php new file mode 100644 index 00000000..192b49a9 --- /dev/null +++ b/extensions/ConfirmEdit/MathCaptcha/MathCaptcha.php @@ -0,0 +1,13 @@ +