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 // Compat: WebRequest::getIP is only available since MW 1.19.
40 $ip = method_exists( $wgRequest, 'getIP' ) ? $wgRequest->getIP() : wfGetIP();
42 $recaptcha_response = recaptcha_check_answer(
43 $wgReCaptchaPrivateKey,
49 if ( !$recaptcha_response->is_valid ) {
50 $this->recaptcha_error = $recaptcha_response->error;
54 $recaptcha_error = null;
60 function addCaptchaAPI( &$resultArr ) {
61 global $wgReCaptchaPublicKey;
63 $resultArr['captcha']['type'] = 'recaptcha';
64 $resultArr['captcha']['mime'] = 'image/png';
65 $resultArr['captcha']['key'] = $wgReCaptchaPublicKey;
66 $resultArr['captcha']['error'] = $this->recaptcha_error;
70 * Show a message asking the user to enter a captcha on edit
71 * The result will be treated as wiki text
73 * @param $action Action being performed
76 function getMessage( $action ) {
77 $name = 'recaptcha-' . $action;
78 $text = wfMsg( $name );
80 # Obtain a more tailored message, if possible, otherwise, fall back to
81 # the default for edits
82 return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;
85 public function APIGetAllowedParams( &$module, &$params ) {
89 public function APIGetParamDescription( &$module, &$desc ) {