From: Sam Reed Date: Wed, 23 Nov 2011 19:09:57 +0000 (+0000) Subject: * (bug 32609) API: Move captchaid/captchaword of action=edit from core to Captcha... X-Git-Url: https://git.toastfreeware.priv.at/toast/cookiecaptcha.git/commitdiff_plain/64b623934855201ace5de2a0321ccf6db1a9109b?hp=332070c4a71caf02f9644806ffcdbbdb9e86732d;ds=sidebyside * (bug 32609) API: Move captchaid/captchaword of action=edit from core to Captcha extension(s) 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 --- diff --git a/Captcha.php b/Captcha.php index 0124c77..a67870c 100644 --- a/Captcha.php +++ b/Captcha.php @@ -44,7 +44,7 @@ abstract class Captcha { /** * Instantiate a new Captcha object for a given Id - * + * * @param $id Int * @return Captcha */ @@ -305,7 +305,7 @@ class SimpleCaptcha { wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" ); return true; } - $form->addFooterText( + $form->addFooterText( "
" . $wgOut->parse( $this->getMessage( 'sendemail' ) ) . $this->getForm() . @@ -692,6 +692,7 @@ class SimpleCaptcha { $this->addCaptchaAPI( $resultArr ); return false; } + return true; } @@ -742,7 +743,7 @@ class SimpleCaptcha { } /** - * Check the captcha on Special:EmailUser + * Check the captcha on Special:EmailUser * @param $from MailAddress * @param $to MailAddress * @param $subject String @@ -759,7 +760,7 @@ class SimpleCaptcha { } if ( $this->isIPWhitelisted() ) return true; - + if ( defined( 'MW_API' ) ) { # API mode # Asking for captchas in the API is really silly @@ -775,6 +776,36 @@ class SimpleCaptcha { 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. diff --git a/ConfirmEdit.php b/ConfirmEdit.php index 8a18a84..1231212 100644 --- a/ConfirmEdit.php +++ b/ConfirmEdit.php @@ -199,6 +199,8 @@ $wgHooks['EmailUserForm'][] = 'ConfirmEditHooks::injectEmailUser'; $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"; diff --git a/ConfirmEditHooks.php b/ConfirmEditHooks.php index dcdf49f..137821c 100644 --- a/ConfirmEditHooks.php +++ b/ConfirmEditHooks.php @@ -5,7 +5,7 @@ class ConfirmEditHooks { /** * Get the global Captcha instance * - * @return Captcha + * @return Captcha|SimpleCaptcha */ static function getInstance() { global $wgCaptcha, $wgCaptchaClass; @@ -56,6 +56,14 @@ class ConfirmEditHooks { 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 { diff --git a/ReCaptcha.php b/ReCaptcha.php index a875527..7837bb7 100644 --- a/ReCaptcha.php +++ b/ReCaptcha.php @@ -1,8 +1,8 @@ @@ -57,7 +57,7 @@ function efReCaptcha() { die ('You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' . "use the reCAPTCHA plugin. You can sign up for a key here."); - } + } } @@ -142,4 +142,11 @@ class ReCaptcha extends SimpleCaptcha { return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text; } + public function APIGetAllowedParams( &$module, &$params ) { + return true; + } + + public function APIGetParamDescription( &$module, &$desc ) { + return true; + } }