Left setting of wpCaptchaId and wpCaptchaWord in core. Can't think of a sane way to check and set them via an extension (subclass and override, or a hook). Annoyingly APIEditBeforeSave doesn't pass the params array
/**
* Instantiate a new Captcha object for a given Id
- *
+ *
* @param $id Int
* @return Captcha
*/
wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
return true;
}
- $form->addFooterText(
+ $form->addFooterText(
"<div class='captcha'>" .
$wgOut->parse( $this->getMessage( 'sendemail' ) ) .
$this->getForm() .
$this->addCaptchaAPI( $resultArr );
return false;
}
+
return true;
}
}
/**
- * Check the captcha on Special:EmailUser
+ * Check the captcha on Special:EmailUser
* @param $from MailAddress
* @param $to MailAddress
* @param $subject String
}
if ( $this->isIPWhitelisted() )
return true;
-
+
if ( defined( 'MW_API' ) ) {
# API mode
# Asking for captchas in the API is really silly
return true;
}
+ /**
+ * @param $module ApiBase
+ * @param $params array
+ * @return bool
+ */
+ public function APIGetAllowedParams( &$module, &$params ) {
+ if ( !$module instanceof ApiEditPage ) {
+ return true;
+ }
+ $params['captchaword'] = null;
+ $params['captchaid'] = null;
+
+ return true;
+ }
+
+ /**
+ * @param $module ApiBae
+ * @param $desc array
+ * @return bool
+ */
+ public function APIGetParamDescription( &$module, &$desc ) {
+ if ( !$module instanceof ApiEditPage ) {
+ return true;
+ }
+ $desc['captchaid'] = 'CAPTCHA ID from previous request';
+ $desc['captchaword'] = 'Answer to the CAPTCHA';
+
+ return true;
+ }
+
/**
* Given a required captcha run, test form input for correct
* input on the open session.
$wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
# Register API hook
$wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
+$wgHooks['APIGetAllowedParams'][] = 'ConfirmEditHooks::APIGetAllowedParams';
+$wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::APIEditBeforeSave';
$wgAutoloadClasses['ConfirmEditHooks'] = "$wgConfirmEditIP/ConfirmEditHooks.php";
$wgAutoloadClasses['Captcha']= "$wgConfirmEditIP/Captcha.php";
/**
* Get the global Captcha instance
*
- * @return Captcha
+ * @return Captcha|SimpleCaptcha
*/
static function getInstance() {
global $wgCaptcha, $wgCaptchaClass;
static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
}
+
+ public static function APIGetAllowedParams( &$module, &$params ) {
+ return self::getInstance()->APIGetAllowedParams( $module, $params );
+ }
+
+ public static function APIGetParamDescription( &$module, &$desc ) {
+ return self::getInstance()->APIGetParamDescription( $module, $desc );
+ }
}
class CaptchaSpecialPage extends UnlistedSpecialPage {
<?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>
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>.");
- }
+ }
}
return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;
}
+ public function APIGetAllowedParams( &$module, &$params ) {
+ return true;
+ }
+
+ public function APIGetParamDescription( &$module, &$desc ) {
+ return true;
+ }
}