<?php

class MacWikiCaptcha extends SimpleCaptcha {

        function getCaptcha() {
                $a = mt_rand(0, 100);
                $b = mt_rand(0, 10);
                $op = mt_rand(0, 1) ? '+' : '-';

                if ($op == '+') {
                   $answer = ($a + $b);
                   $test = "$a に $b を加算すると";
                } else {
                   $answer = ($a - $b);
                   $test = "$a より $b を減じると";
                }

                return array('question' => $test, 'answer' => $answer);
        }

        function getForm() {
                $captcha = $this->getCaptcha();
                $index = $this->storeCaptcha( $captcha );

                return "<p><label for=\"wpCaptchaWord\">{$captcha['question']}</label> : " .
                        wfElement( 'input', array(
                                'name' => 'wpCaptchaWord',
                                'id'   => 'wpCaptchaWord',
                                'tabindex' => 1 ) ) . // tab in before the edit textarea
                        "</p>\n" .
                        wfElement( 'input', array(
                                'type'  => 'hidden',
                                'name'  => 'wpCaptchaId',
                                'id'    => 'wpCaptchaId',
                                'value' => $index ) );
        }

}
?>
