r104064 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104063‎ | r104064 | r104065 >
Date:19:09, 23 November 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (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
Modified paths:
  • /trunk/extensions/ConfirmEdit/Captcha.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/ConfirmEdit.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/ConfirmEditHooks.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/ReCaptcha.php (modified) (history)
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -176,6 +176,8 @@
177177 * wlexcludeuser parameter added to ApiFeedWatchlist.
178178 * (bug 7304) Links on redirect pages no longer cause the redirect page to show
179179 up as a redirect to the linked page on Special:Whatlinkshere.
 180+* (bug 32609) API: Move captchaid/captchaword of action=edit from core
 181+ to Captcha extension(s)
180182
181183 === Languages updated in 1.19 ===
182184
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -239,15 +239,15 @@
240240 $ep->setContextTitle( $titleObj );
241241 $ep->importFormData( $req );
242242
243 - // Run hooks
244 - // Handle CAPTCHA parameters
245 - if ( !is_null( $params['captchaid'] ) ) {
 243+ if ( isset( $params['captchaid'] ) && !is_null( $params['captchaid'] ) ) {
246244 $wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] );
247245 }
248 - if ( !is_null( $params['captchaword'] ) ) {
 246+ if ( isset( $params['captchaword'] ) && !is_null( $params['captchaword'] ) ) {
249247 $wgRequest->setVal( 'wpCaptchaWord', $params['captchaword'] );
250248 }
251249
 250+ // Run hooks
 251+ // Handle APIEditBeforeSave parameters
252252 $r = array();
253253 if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) {
254254 if ( count( $r ) ) {
@@ -422,8 +422,6 @@
423423 'recreate' => false,
424424 'createonly' => false,
425425 'nocreate' => false,
426 - 'captchaword' => null,
427 - 'captchaid' => null,
428426 'watch' => array(
429427 ApiBase::PARAM_DFLT => false,
430428 ApiBase::PARAM_DEPRECATED => true,
@@ -482,8 +480,6 @@
483481 'watch' => 'Add the page to your watchlist',
484482 'unwatch' => 'Remove the page from your watchlist',
485483 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
486 - 'captchaid' => 'CAPTCHA ID from previous request',
487 - 'captchaword' => 'Answer to the CAPTCHA',
488484 'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
489485 'If set, the edit won\'t be done unless the hash is correct' ),
490486 'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
Index: trunk/extensions/ConfirmEdit/ReCaptcha.php
@@ -1,8 +1,8 @@
22 <?php
33
44 /**
5 - * Captcha class using the reCAPTCHA widget.
6 - * Stop Spam. Read Books.
 5+ * Captcha class using the reCAPTCHA widget.
 6+ * Stop Spam. Read Books.
77 *
88 * @addtogroup Extensions
99 * @author Mike Crawford <mike.crawford@gmail.com>
@@ -57,7 +57,7 @@
5858 die ('You need to set $wgReCaptchaPrivateKey and $wgReCaptchaPublicKey in LocalSettings.php to ' .
5959 "use the reCAPTCHA plugin. You can sign up for a key <a href='" .
6060 htmlentities(recaptcha_get_signup_url ($wgServerName, "mediawiki")) . "'>here</a>.");
61 - }
 61+ }
6262 }
6363
6464
@@ -142,4 +142,11 @@
143143 return wfEmptyMsg( $name, $text ) ? wfMsg( 'recaptcha-edit' ) : $text;
144144 }
145145
 146+ public function APIGetAllowedParams( &$module, &$params ) {
 147+ return true;
 148+ }
 149+
 150+ public function APIGetParamDescription( &$module, &$desc ) {
 151+ return true;
 152+ }
146153 }
Index: trunk/extensions/ConfirmEdit/Captcha.php
@@ -44,7 +44,7 @@
4545
4646 /**
4747 * Instantiate a new Captcha object for a given Id
48 - *
 48+ *
4949 * @param $id Int
5050 * @return Captcha
5151 */
@@ -305,7 +305,7 @@
306306 wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
307307 return true;
308308 }
309 - $form->addFooterText(
 309+ $form->addFooterText(
310310 "<div class='captcha'>" .
311311 $wgOut->parse( $this->getMessage( 'sendemail' ) ) .
312312 $this->getForm() .
@@ -692,6 +692,7 @@
693693 $this->addCaptchaAPI( $resultArr );
694694 return false;
695695 }
 696+
696697 return true;
697698 }
698699
@@ -742,7 +743,7 @@
743744 }
744745
745746 /**
746 - * Check the captcha on Special:EmailUser
 747+ * Check the captcha on Special:EmailUser
747748 * @param $from MailAddress
748749 * @param $to MailAddress
749750 * @param $subject String
@@ -759,7 +760,7 @@
760761 }
761762 if ( $this->isIPWhitelisted() )
762763 return true;
763 -
 764+
764765 if ( defined( 'MW_API' ) ) {
765766 # API mode
766767 # Asking for captchas in the API is really silly
@@ -776,6 +777,36 @@
777778 }
778779
779780 /**
 781+ * @param $module ApiBase
 782+ * @param $params array
 783+ * @return bool
 784+ */
 785+ public function APIGetAllowedParams( &$module, &$params ) {
 786+ if ( !$module instanceof ApiEditPage ) {
 787+ return true;
 788+ }
 789+ $params['captchaword'] = null;
 790+ $params['captchaid'] = null;
 791+
 792+ return true;
 793+ }
 794+
 795+ /**
 796+ * @param $module ApiBae
 797+ * @param $desc array
 798+ * @return bool
 799+ */
 800+ public function APIGetParamDescription( &$module, &$desc ) {
 801+ if ( !$module instanceof ApiEditPage ) {
 802+ return true;
 803+ }
 804+ $desc['captchaid'] = 'CAPTCHA ID from previous request';
 805+ $desc['captchaword'] = 'Answer to the CAPTCHA';
 806+
 807+ return true;
 808+ }
 809+
 810+ /**
780811 * Given a required captcha run, test form input for correct
781812 * input on the open session.
782813 * @return bool if passed, false if failed or new session
Index: trunk/extensions/ConfirmEdit/ConfirmEdit.php
@@ -199,6 +199,8 @@
200200 $wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
201201 # Register API hook
202202 $wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
 203+$wgHooks['APIGetAllowedParams'][] = 'ConfirmEditHooks::APIGetAllowedParams';
 204+$wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::APIEditBeforeSave';
203205
204206 $wgAutoloadClasses['ConfirmEditHooks'] = "$wgConfirmEditIP/ConfirmEditHooks.php";
205207 $wgAutoloadClasses['Captcha']= "$wgConfirmEditIP/Captcha.php";
Index: trunk/extensions/ConfirmEdit/ConfirmEditHooks.php
@@ -5,7 +5,7 @@
66 /**
77 * Get the global Captcha instance
88 *
9 - * @return Captcha
 9+ * @return Captcha|SimpleCaptcha
1010 */
1111 static function getInstance() {
1212 global $wgCaptcha, $wgCaptchaClass;
@@ -56,6 +56,14 @@
5757 static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
5858 return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
5959 }
 60+
 61+ public static function APIGetAllowedParams( &$module, &$params ) {
 62+ return self::getInstance()->APIGetAllowedParams( $module, $params );
 63+ }
 64+
 65+ public static function APIGetParamDescription( &$module, &$desc ) {
 66+ return self::getInstance()->APIGetParamDescription( $module, $desc );
 67+ }
6068 }
6169
6270 class CaptchaSpecialPage extends UnlistedSpecialPage {

Follow-up revisions

RevisionCommit summaryAuthorDate
r104083Fix hook copy paste fail...reedy20:37, 23 November 2011
r104467Followup r104064, r104083 for bug 32609...reedy18:55, 28 November 2011

Comments

#Comment by Duplicatebug (talk | contribs)   20:03, 23 November 2011

The AssertEdit extensions is grapping from $wgRequest, so that should work here (untested). The extension is than setting $wgRequest->setVal( 'wpCaptchaWord', $wgRequest->getVal( 'captchaword' ) );

You are register two APIEditBeforeSave hooks:

-$wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::APIEditBeforeSave';
+$wgHooks['APIGetParamDescription'][] = 'ConfirmEditHooks::APIGetParamDescription';

Status & tagging log