summaryrefslogtreecommitdiff
path: root/extensions/ConfirmEdit/ReCaptcha.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-04-26 18:23:31 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-04-26 18:23:31 +0200
commitc4372dd38a4d109b4f3881ea63b667e33adbe503 (patch)
treee8e6dae1229a68c26b7a348c73dc0c8c77da97e5 /extensions/ConfirmEdit/ReCaptcha.php
parentcf566324cfb218f0c7323d97d2a103bbb8d60ba4 (diff)
Update to MediaWiki 1.18.3
Diffstat (limited to 'extensions/ConfirmEdit/ReCaptcha.php')
-rw-r--r--extensions/ConfirmEdit/ReCaptcha.php113
1 files changed, 22 insertions, 91 deletions
diff --git a/extensions/ConfirmEdit/ReCaptcha.php b/extensions/ConfirmEdit/ReCaptcha.php
index b068b86e..cedaae10 100644
--- a/extensions/ConfirmEdit/ReCaptcha.php
+++ b/extensions/ConfirmEdit/ReCaptcha.php
@@ -1,8 +1,8 @@
<?php
/**
- * Captcha class using the reCAPTCHA widget.
- * Stop Spam. Read Books.
+ * Captcha class using the reCAPTCHA widget.
+ * Stop Spam. Read Books.
*
* @addtogroup Extensions
* @author Mike Crawford <mike.crawford@gmail.com>
@@ -10,11 +10,18 @@
* @licence MIT/X11
*/
-if( !defined( 'MEDIAWIKI' ) ) {
+if ( !defined( 'MEDIAWIKI' ) ) {
exit;
}
-$wgExtensionMessagesFiles['ReCaptcha'] = dirname( __FILE__ ) . '/ReCaptcha.i18n.php';
+require_once dirname( __FILE__ ) . '/ConfirmEdit.php';
+$wgCaptchaClass = 'ReCaptcha';
+
+$dir = dirname( __FILE__ );
+
+$wgExtensionMessagesFiles['ReCaptcha'] = $dir . '/ReCaptcha.i18n.php';
+
+$wgAutoloadClasses['ReCaptcha'] = $dir . '/ReCaptcha.class.php';
require_once( 'recaptchalib.php' );
@@ -25,6 +32,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';
/**
@@ -43,92 +57,9 @@ function efReCaptcha() {
$wgReCaptchaPrivateKey = $recaptcha_private_key;
}
- if ($wgReCaptchaPublicKey == '' || $wgReCaptchaPrivateKey == '') {
- die ('You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' .
- "use the reCAPTCHA plugin. You can sign up for a key <a href='" .
- htmlentities(recaptcha_get_signup_url ($wgServerName, "mediawiki")) . "'>here</a>.");
- }
-}
-
-
-class ReCaptcha extends SimpleCaptcha {
-
- //reCAPTHCA error code returned from recaptcha_check_answer
- private $recaptcha_error = null;
-
- /**
- * Displays the reCAPTCHA widget.
- * If $this->recaptcha_error is set, it will display an error in the widget.
- *
- */
- function getForm() {
- global $wgReCaptchaPublicKey;
- $useHttps = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
- return "<script>var RecaptchaOptions = { tabindex : 1 }; </script> " .
- recaptcha_get_html($wgReCaptchaPublicKey, $this->recaptcha_error, $useHttps);
+ if ( $wgReCaptchaPublicKey == '' || $wgReCaptchaPrivateKey == '' ) {
+ die ( 'You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' .
+ "use the reCAPTCHA plugin. You can sign up for a key <a href='" .
+ htmlentities( recaptcha_get_signup_url ( $wgServerName, "mediawiki" ) ) . "'>here</a>." );
}
-
- /**
- * Calls the library function recaptcha_check_answer to verify the users input.
- * Sets $this->recaptcha_error if the user is incorrect.
- * @return boolean
- *
- */
- function passCaptcha() {
- global $wgReCaptchaPrivateKey;
- $recaptcha_response = recaptcha_check_answer ($wgReCaptchaPrivateKey,
- wfGetIP (),
- $_POST['recaptcha_challenge_field'],
- $_POST['recaptcha_response_field']);
- if (!$recaptcha_response->is_valid) {
- $this->recaptcha_error = $recaptcha_response->error;
- return false;
- }
- $recaptcha_error = null;
- 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
- * The result will be treated as wiki text
- *
- * @param $action Action being performed
- * @return string
- */
- function getMessage( $action ) {
- $name = 'recaptcha-' . $action;
- $text = wfMsg( $name );
- # Obtain a more tailored message, if possible, otherwise, fall back to
- # the default for edits
- return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;
- }
-
}