3 class ReCaptcha extends SimpleCaptcha {
4 // reCAPTHCA error code returned from recaptcha_check_answer
5 private $recaptcha_error = null;
8 * Displays the reCAPTCHA widget.
9 * If $this->recaptcha_error is set, it will display an error in the widget.
13 global $wgReCaptchaPublicKey, $wgReCaptchaTheme;
15 $useHttps = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
16 $js = 'var RecaptchaOptions = ' . Xml::encodeJsVar( array( 'theme' => $wgReCaptchaTheme, 'tabindex' => 1 ) );
18 return Html::inlineScript( $js ) . recaptcha_get_html( $wgReCaptchaPublicKey, $this->recaptcha_error, $useHttps );
22 * Calls the library function recaptcha_check_answer to verify the users input.
23 * Sets $this->recaptcha_error if the user is incorrect.
27 function passCaptcha() {
28 global $wgReCaptchaPrivateKey, $wgRequest;
30 // API is hardwired to return wpCaptchaId and wpCaptchaWord, so use that if the standard two are empty
31 $challenge = $wgRequest->getVal( 'recaptcha_challenge_field', $wgRequest->getVal( 'wpCaptchaId' ) );
32 $response = $wgRequest->getVal( 'recaptcha_response_field', $wgRequest->getVal( 'wpCaptchaWord' ) );
34 if ( $response === null ) {
35 // new captcha session
39 $recaptcha_response = recaptcha_check_answer(
40 $wgReCaptchaPrivateKey,
46 if ( !$recaptcha_response->is_valid ) {
47 $this->recaptcha_error = $recaptcha_response->error;
51 $recaptcha_error = null;
57 function addCaptchaAPI( &$resultArr ) {
58 global $wgReCaptchaPublicKey;
60 $resultArr['captcha']['type'] = 'recaptcha';
61 $resultArr['captcha']['mime'] = 'image/png';
62 $resultArr['captcha']['key'] = $wgReCaptchaPublicKey;
63 $resultArr['captcha']['error'] = $this->recaptcha_error;
67 * Show a message asking the user to enter a captcha on edit
68 * The result will be treated as wiki text
70 * @param $action Action being performed
73 function getMessage( $action ) {
74 $name = 'recaptcha-' . $action;
75 $text = wfMsg( $name );
77 # Obtain a more tailored message, if possible, otherwise, fall back to
78 # the default for edits
79 return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;
82 public function APIGetAllowedParams( &$module, &$params ) {
86 public function APIGetParamDescription( &$module, &$desc ) {