r64908 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64907‎ | r64908 | r64909 >
Date:21:26, 10 April 2010
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Implement captchas for sending emails via Special:EmailUser.
Modified paths:
  • /trunk/extensions/ConfirmEdit/ConfirmEdit.i18n.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/ConfirmEdit.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/ConfirmEdit_body.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/FancyCaptcha.i18n.php (modified) (history)
  • /trunk/extensions/ConfirmEdit/QuestyCaptcha.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmEdit/QuestyCaptcha.i18n.php
@@ -16,6 +16,7 @@
1717 'questycaptcha-createaccount' => 'To help protect against automated account creation, please answer the question that appears below ([[Special:Captcha/help|more info]]):',
1818 'questycaptcha-create' => 'To create the page, please answer the question that appears below ([[Special:Captcha/help|more info]]):',
1919 'questycaptcha-edit' => 'To edit this page, please answer the question that appears below ([[Special:Captcha/help|more info]]):',
 20+ 'questycaptcha-sendemail' => 'To help protect against automated spamming, please answer the question that appears below ([[Special:Captcha/help|more info]]):',
2021 'questycaptchahelp-text' => "Web sites that accept contributions from the public, like this wiki, are often abused by spammers who use automated tools to add their links to many sites.
2122 While these spam links can be removed, they are a significant nuisance.
2223
Index: trunk/extensions/ConfirmEdit/ConfirmEdit_body.php
@@ -46,6 +46,14 @@
4747 static function confirmUserLogin( $u, $pass, &$retval ) {
4848 return self::getInstance()->confirmUserLogin( $u, $pass, $retval );
4949 }
 50+
 51+ static function injectEmailUser( &$form ) {
 52+ return self::getInstance()->injectEmailUser( $form );
 53+ }
 54+
 55+ static function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
 56+ return self::getInstance()->confirmEmailUser( $from, $to, $subject, $text, $error );
 57+ }
5058 }
5159
5260 class CaptchaSpecialPage extends UnlistedSpecialPage {
@@ -141,6 +149,28 @@
142150 /**
143151 * Inject whazawhoo
144152 * @fixme if multiple thingies insert a header, could break
 153+ * @param HTMLForm
 154+ * @return bool true to keep running callbacks
 155+ */
 156+ function injectEmailUser( &$form ) {
 157+ global $wgCaptchaTriggers, $wgOut, $wgUser;
 158+ if ( $wgCaptchaTriggers['sendemail'] ) {
 159+ if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
 160+ wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
 161+ return true;
 162+ }
 163+ $form->addFooterText(
 164+ "<div class='captcha'>" .
 165+ $wgOut->parse( $this->getMessage( 'sendemail' ) ) .
 166+ $this->getForm() .
 167+ "</div>\n" );
 168+ }
 169+ return true;
 170+ }
 171+
 172+ /**
 173+ * Inject whazawhoo
 174+ * @fixme if multiple thingies insert a header, could break
145175 * @param SimpleTemplate $template
146176 * @return bool true to keep running callbacks
147177 */
@@ -565,6 +595,40 @@
566596 }
567597
568598 /**
 599+ * Check the captcha on Special:EmailUser
 600+ * @param $from MailAddress
 601+ * @param $to MailAddress
 602+ * @param $subject String
 603+ * @param $text String
 604+ * @param $error String reference
 605+ * @return Bool true to continue saving, false to abort and show a captcha form
 606+ */
 607+ function confirmEmailUser( $from, $to, $subject, $text, &$error ) {
 608+ global $wgCaptchaTriggers, $wgUser;
 609+ if ( $wgCaptchaTriggers['sendemail'] ) {
 610+ if ( $wgUser->isAllowed( 'skipcaptcha' ) ) {
 611+ wfDebug( "ConfirmEdit: user group allows skipping captcha on email sending\n" );
 612+ return true;
 613+ }
 614+ if ( $this->isIPWhitelisted() )
 615+ return true;
 616+
 617+ if ( defined( 'MW_API' ) ) {
 618+ # API mode
 619+ # Asking for captchas in the API is really silly
 620+ $error = wfMsg( 'captcha-disabledinapi' );
 621+ return false;
 622+ }
 623+ $this->trigger = "{$wgUser->getName()} sending email";
 624+ if ( !$this->passCaptcha() ) {
 625+ $error = wfMsg( 'captcha-sendemail-fail' );
 626+ return false;
 627+ }
 628+ }
 629+ return true;
 630+ }
 631+
 632+ /**
569633 * Given a required captcha run, test form input for correct
570634 * input on the open session.
571635 * @return bool if passed, false if failed or new session
Index: trunk/extensions/ConfirmEdit/ConfirmEdit.i18n.php
@@ -16,6 +16,9 @@
1717 'captcha-createaccount' => 'To help protect against automated account creation, please solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):',
1818 'captcha-createaccount-fail' => "Incorrect or missing confirmation code.",
1919 'captcha-create' => 'To create the page, please solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):',
 20+ 'captcha-sendemail' => 'To help protect against automated spamming, please solve the simple sum below and enter the answer in the box ([[Special:Captcha/help|more info]]):',
 21+ 'captcha-sendemail-fail' => 'Incorrect or missing confirmation code.',
 22+ 'captcha-disabledinapi' => 'This action requires a captcha, so it cannot be performed through the API.',
2023 'captchahelp-title' => 'Captcha help',
2124 'captchahelp-cookies-needed' => "You will need to have cookies enabled in your browser for this to work.",
2225 'captchahelp-text' => "Web sites that accept postings from the public, like this wiki, are often abused by spammers who use automated tools to post their links to many sites.
Index: trunk/extensions/ConfirmEdit/FancyCaptcha.i18n.php
@@ -16,6 +16,7 @@
1717 'fancycaptcha-createaccount' => 'To help protect against automated account creation, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):',
1818 'fancycaptcha-create' => 'To create the page, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):',
1919 'fancycaptcha-edit' => 'To edit this page, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):',
 20+ 'fancycaptcha-sendemail' => 'To help protect against automated spamming, please enter the words that appear below in the box ([[Special:Captcha/help|more info]]):',
2021 );
2122
2223 /** Message documentation (Message documentation)
Index: trunk/extensions/ConfirmEdit/ConfirmEdit.php
@@ -88,6 +88,7 @@
8989 $wgCaptchaTriggers = array();
9090 $wgCaptchaTriggers['edit'] = false; // Would check on every edit
9191 $wgCaptchaTriggers['create'] = false; // Check on page creation.
 92+$wgCaptchaTriggers['sendemail'] = false; // Special:Emailuser
9293 $wgCaptchaTriggers['addurl'] = true; // Check on edits that add URLs
9394 $wgCaptchaTriggers['createaccount'] = true; // Special:Userlogin&type=signup
9495 $wgCaptchaTriggers['badlogin'] = true; // Special:Userlogin after failure
@@ -190,6 +191,8 @@
191192 $wgHooks['LoginAuthenticateAudit'][] = 'ConfirmEditHooks::triggerUserLogin';
192193 $wgHooks['UserLoginForm'][] = 'ConfirmEditHooks::injectUserLogin';
193194 $wgHooks['AbortLogin'][] = 'ConfirmEditHooks::confirmUserLogin';
 195+$wgHooks['EmailUserForm'][] = 'ConfirmEditHooks::injectEmailUser';
 196+$wgHooks['EmailUser'][] = 'ConfirmEditHooks::confirmEmailUser';
194197 # Register API hook
195198 $wgHooks['APIEditBeforeSave'][] = 'ConfirmEditHooks::confirmEditAPI';
196199

Comments

#Comment by Werdna (talk | contribs)   03:22, 9 December 2010

I really don't like the "tack the captcha form on the end of my existing form" pattern. I'd really prefer that a proper subclass of HTMLFormField were implemented to present captchas to users.

#Comment by 😂 (talk | contribs)   04:14, 8 February 2011

I can go either way on this. It works, but it's not pretty like Andrew says.

It does unmerge cleanly, if we just want to revert.

#Comment by 😂 (talk | contribs)   06:51, 8 February 2011

Per IRC: this is ok for now, and $wgCaptchaTriggers['sendemail'] is false by default so it doesn't change current behavior.

Long-term, it'd be nice to handle captchas in HTMLForm, like Andrew says.

Status & tagging log