-<?php\r
-\r
-/**\r
- * Captcha class using the reCAPTCHA widget. \r
- * Stop Spam. Read Books. \r
- *\r
- * @addtogroup Extensions\r
- * @author Mike Crawford <mike.crawford@gmail.com>\r
- * @copyright Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net\r
- * @licence MIT/X11\r
- */\r
-\r
-if( !defined( 'MEDIAWIKI' ) ) {\r
- exit;\r
-}\r
-\r
-$wgExtensionMessagesFiles['ReCaptcha'] = dirname( __FILE__ ) . '/ReCaptcha.i18n.php';\r
-\r
-require_once( 'recaptchalib.php' );\r
-\r
-// Set these in LocalSettings.php\r
-$wgReCaptchaPublicKey = '';\r
-$wgReCaptchaPrivateKey = '';\r
-// For backwards compatibility\r
-$recaptcha_public_key = '';\r
-$recaptcha_private_key = '';\r
-\r
-\r
-/**\r
- * Make sure the keys are defined.\r
- */\r
-function efReCaptcha() {\r
- global $wgReCaptchaPublicKey, $wgReCaptchaPrivateKey;\r
- global $recaptcha_public_key, $recaptcha_private_key;\r
- global $wgServerName;\r
-\r
- // Backwards compatibility\r
- $wgReCaptchaPublicKey == '' ) {\r
- $wgReCaptchaPublicKey = $recaptcha_public_key;\r
- }\r
- if ( $wgReCaptchaPrivateKey == '' ) {\r
- $wgReCaptchaPrivateKey = $recaptcha_private_key;\r
- }\r
-\r
- if ($wgReCaptchaPublicKey == '' || $wgReCaptchaPrivateKey == '') {\r
- die ('You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' .\r
- "use the reCAPTCHA plugin. You can sign up for a key <a href='" .\r
- htmlentities(recaptcha_get_signup_url ($wgServerName, "mediawiki")) . "'>here</a>.");\r
- } \r
-}\r
-\r
-\r
-class ReCaptcha extends SimpleCaptcha {\r
- \r
- //reCAPTHCA error code returned from recaptcha_check_answer\r
- private $recaptcha_error = null;\r
-\r
- \r
- /** \r
- * Displays the reCAPTCHA widget. \r
- * If $this->recaptcha_error is set, it will display an error in the widget.\r
- *\r
- */\r
- function getForm() {\r
- global $wgReCaptchaPublicKey;\r
- return "<script>var RecaptchaOptions = { tabindex : 1 }; </script> " .\r
- recaptcha_get_html($wgReCaptchaPublicKey, $this->recaptcha_error);\r
- }\r
-\r
-\r
- \r
- /**\r
- * Calls the library function recaptcha_check_answer to verify the users input.\r
- * Sets $this->recaptcha_error if the user is incorrect.\r
- * @return boolean \r
- *\r
- */\r
- function passCaptcha() {\r
- global $wgReCaptchaPrivateKey;\r
- $recaptcha_response = recaptcha_check_answer ($wgReCaptchaPrivateKey,\r
- wfGetIP (),\r
- $_POST['recaptcha_challenge_field'],\r
- $_POST['recaptcha_response_field']);\r
- if (!$recaptcha_response->is_valid) {\r
- $this->recaptcha_error = $recaptcha_response->error;\r
- return false;\r
- }\r
- $recaptcha_error = null;\r
- return true;\r
-\r
- }\r
-\r
-\r
-\r
- /**\r
- * Called on all edit page saves. (EditFilter events)\r
- * @return boolean - true if page save should continue, false if should display Captcha widget.\r
- */\r
- function confirmEdit( $editPage, $newtext, $section ) {\r
- if( $this->shouldCheck( $editPage, $newtext, $section ) ) {\r
-\r
- if (!isset($_POST['recaptcha_response_field'])) {\r
- //User has not yet been presented with Captcha, show the widget.\r
- $editPage->showEditForm( array( &$this, 'editCallback' ) );\r
- return false;\r
- }\r
-\r
- if( $this->passCaptcha() ) {\r
- return true;\r
- } else {\r
- //Try again - show the widget\r
- $editPage->showEditForm( array( &$this, 'editCallback' ) );\r
- return false;\r
- }\r
-\r
- } else {\r
- wfDebug( "ConfirmEdit: no need to show captcha.\n" );\r
- return true;\r
- }\r
- }\r
-\r
- \r
-\r
- /**\r
- * Show a message asking the user to enter a captcha on edit\r
- * The result will be treated as wiki text\r
- *\r
- * @param $action Action being performed\r
- * @return string\r
- */\r
- function getMessage( $action ) {\r
- $name = 'recaptcha-' . $action;\r
- $text = wfMsg( $name );\r
- # Obtain a more tailored message, if possible, otherwise, fall back to\r
- # the default for edits\r
- return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;\r
- }\r
-\r
-}\r
+<?php
+
+/**
+ * Captcha class using the reCAPTCHA widget.
+ * Stop Spam. Read Books.
+ *
+ * @addtogroup Extensions
+ * @author Mike Crawford <mike.crawford@gmail.com>
+ * @copyright Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
+ * @licence MIT/X11
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+ exit;
+}
+
+require_once dirname( __FILE__ ) . '/ConfirmEdit.php';
+$wgCaptchaClass = 'ReCaptcha';
+
+$wgExtensionMessagesFiles['ReCaptcha'] = dirname( __FILE__ ) . '/ReCaptcha.i18n.php';
+
+require_once( 'recaptchalib.php' );
+
+// Set these in LocalSettings.php
+$wgReCaptchaPublicKey = '';
+$wgReCaptchaPrivateKey = '';
+// For backwards compatibility
+$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';
+
+/**
+ * Make sure the keys are defined.
+ */
+function efReCaptcha() {
+ global $wgReCaptchaPublicKey, $wgReCaptchaPrivateKey;
+ global $recaptcha_public_key, $recaptcha_private_key;
+ global $wgServerName;
+
+ // Backwards compatibility
+ if ( $wgReCaptchaPublicKey == '' ) {
+ $wgReCaptchaPublicKey = $recaptcha_public_key;
+ }
+ if ( $wgReCaptchaPrivateKey == '' ) {
+ $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, $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
+ *
+ */
+ 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;
+ }
+
+}