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 $ip = $wgRequest->getIP();
41 $recaptcha_response = recaptcha_check_answer(
42 $wgReCaptchaPrivateKey,
48 if ( !$recaptcha_response->is_valid ) {
49 $this->recaptcha_error = $recaptcha_response->error;
53 $recaptcha_error = null;
59 function addCaptchaAPI( &$resultArr ) {
60 global $wgReCaptchaPublicKey;
62 $resultArr['captcha']['type'] = 'recaptcha';
63 $resultArr['captcha']['mime'] = 'image/png';
64 $resultArr['captcha']['key'] = $wgReCaptchaPublicKey;
65 $resultArr['captcha']['error'] = $this->recaptcha_error;
69 * Show a message asking the user to enter a captcha on edit
70 * The result will be treated as wiki text
72 * @param $action string Action being performed
75 function getMessage( $action ) {
76 $name = 'recaptcha-' . $action;
77 $text = wfMessage( $name )->text();
79 # Obtain a more tailored message, if possible, otherwise, fall back to
80 # the default for edits
81 return wfMessage( $name, $text )->isDisabled() ? wfMessage( 'recaptcha-edit' )->text() : $text;
84 public function APIGetAllowedParams( &$module, &$params ) {
88 public function APIGetParamDescription( &$module, &$desc ) {