X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/blobdiff_plain/1cccda834ff53e75334a61ac25dce0ecf5022dca..beb6a182ebf8245b424314c4d622930d0ded221c:/ReCaptcha.php diff --git a/ReCaptcha.php b/ReCaptcha.php index 44127c9..a875527 100644 --- a/ReCaptcha.php +++ b/ReCaptcha.php @@ -10,10 +10,13 @@ * @licence MIT/X11 */ -if( !defined( 'MEDIAWIKI' ) ) { +if ( !defined( 'MEDIAWIKI' ) ) { exit; } +require_once dirname( __FILE__ ) . '/ConfirmEdit.php'; +$wgCaptchaClass = 'ReCaptcha'; + $wgExtensionMessagesFiles['ReCaptcha'] = dirname( __FILE__ ) . '/ReCaptcha.i18n.php'; require_once( 'recaptchalib.php' ); @@ -25,6 +28,13 @@ $wgReCaptchaPrivateKey = ''; $recaptcha_public_key = ''; $recaptcha_private_key = ''; +/** + * Sets the theme for ReCaptcha + * + * See http://code.google.com/apis/recaptcha/docs/customization.html + */ +$wgReCaptchaTheme = 'red'; + $wgExtensionFunctions[] = 'efReCaptcha'; /** @@ -52,28 +62,27 @@ function efReCaptcha() { class ReCaptcha extends SimpleCaptcha { - + //reCAPTHCA error code returned from recaptcha_check_answer private $recaptcha_error = null; - - /** - * Displays the reCAPTCHA widget. + /** + * Displays the reCAPTCHA widget. * If $this->recaptcha_error is set, it will display an error in the widget. * */ function getForm() { - global $wgReCaptchaPublicKey; - return " " . - recaptcha_get_html($wgReCaptchaPublicKey, $this->recaptcha_error); - } + global $wgReCaptchaPublicKey, $wgReCaptchaTheme; + $useHttps = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ); + $js = 'var RecaptchaOptions = ' . Xml::encodeJsVar( array( 'theme' => $wgReCaptchaTheme, 'tabindex' => 1 ) ); + return Html::inlineScript( $js ) . recaptcha_get_html($wgReCaptchaPublicKey, $this->recaptcha_error, $useHttps); + } - /** * Calls the library function recaptcha_check_answer to verify the users input. * Sets $this->recaptcha_error if the user is incorrect. - * @return boolean + * @return boolean * */ function passCaptcha() { @@ -91,36 +100,32 @@ class ReCaptcha extends SimpleCaptcha { } - - - /** - * Called on all edit page saves. (EditFilter events) - * @return boolean - true if page save should continue, false if should display Captcha widget. - */ - function confirmEdit( $editPage, $newtext, $section ) { - if( $this->shouldCheck( $editPage, $newtext, $section ) ) { - - if (!isset($_POST['recaptcha_response_field'])) { - //User has not yet been presented with Captcha, show the widget. - $editPage->showEditForm( array( &$this, 'editCallback' ) ); - return false; - } - - if( $this->passCaptcha() ) { - return true; - } else { - //Try again - show the widget - $editPage->showEditForm( array( &$this, 'editCallback' ) ); - return false; - } - - } else { - wfDebug( "ConfirmEdit: no need to show captcha.\n" ); - return true; - } - } - - + /** + * Called on all edit page saves. (EditFilter events) + * @return boolean - true if page save should continue, false if should display Captcha widget. + */ + function confirmEdit( $editPage, $newtext, $section, $merged = false ) { + if( $this->shouldCheck( $editPage, $newtext, $section ) ) { + + if (!isset($_POST['recaptcha_response_field'])) { + //User has not yet been presented with Captcha, show the widget. + $editPage->showEditForm( array( &$this, 'editCallback' ) ); + return false; + } + + if( $this->passCaptcha() ) { + return true; + } else { + //Try again - show the widget + $editPage->showEditForm( array( &$this, 'editCallback' ) ); + return false; + } + + } else { + wfDebug( "ConfirmEdit: no need to show captcha.\n" ); + return true; + } + } /** * Show a message asking the user to enter a captcha on edit