Merge "Clear PHP entry point and use extension.json for ReCaptcha"

This commit is contained in:
jenkins-bot 2015-05-23 12:54:50 +00:00 committed by Gerrit Code Review
commit b2cadc2a93
3 changed files with 39 additions and 61 deletions

View file

@ -1,63 +1,13 @@
<?php <?php
if ( function_exists( 'wfLoadExtension' ) ) {
/** wfLoadExtension( 'ConfirmEdit/ReCaptcha' );
* Captcha class using the reCAPTCHA widget. // Keep i18n globals so mergeMessageFileList.php doesn't break
* Stop Spam. Read Books. $wgMessagesDirs['ReCaptcha'] = __DIR__ . '/i18n';
* /* wfWarn(
* @addtogroup Extensions 'Deprecated PHP entry point used for ReCaptcha extension. Please use wfLoadExtension instead, ' .
* @author Mike Crawford <mike.crawford@gmail.com> 'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
* @copyright Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net ); */
* @licence MIT/X11 return;
*/ } else {
die( 'This version of the Re^Captcha extension requires MediaWiki 1.25+' );
if ( !defined( 'MEDIAWIKI' ) ) {
exit;
}
require_once dirname( __DIR__ ) . '/ConfirmEdit.php';
$wgCaptchaClass = 'ReCaptcha';
$wgMessagesDirs['ReCaptcha'] = __DIR__ . '/i18n';
$wgAutoloadClasses['ReCaptcha'] = __DIR__ . '/ReCaptcha.class.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>." );
}
} }

21
ReCaptcha/extension.json Normal file
View file

@ -0,0 +1,21 @@
{
"name": "ReCaptcha",
"ExtensionFunctions": [
"efReCaptcha"
],
"MessagesDirs": {
"ReCaptcha": [
"i18n"
]
},
"AutoloadClasses": {
"ReCaptcha": "ReCaptcha.class.php"
},
"config": {
"CaptchaClass": "ReCaptcha",
"ReCaptchaPublicKey": "",
"ReCaptchaPrivateKey": "",
"ReCaptchaTheme": "red"
},
"callback": "ConfirmEditHooks::onReCaptchaSetup",
}

View file

@ -139,4 +139,11 @@ class ConfirmEditHooks {
$wgCaptchaDirectory = "$wgUploadDirectory/captcha"; $wgCaptchaDirectory = "$wgUploadDirectory/captcha";
} }
} }
/**
* Callback for extension.json of ReCaptcha to require the recaptcha library php file.
* FIXME: This should be done in a better way, e.g. only load the libraray, if really needed.
*/
public static function onReCaptchaSetup() {
require_once( "ReCaptcha/recaptchalib.php" );
}
} }