MediaWiki r26698 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r26697‎ | r26698 (on ViewVC)‎ | r26699 >
Date:11:41, 13 October 2007
Author:daniel
Status:old
Tags:
Comment:
Captchas for ContactPage
Modified paths:

Diff [purge]

Index: trunk/extensions/ContactPage/ContactPage.i18n.php
===================================================================
--- trunk/extensions/ContactPage/ContactPage.i18n.php	(revision 26697)
+++ trunk/extensions/ContactPage/ContactPage.i18n.php	(revision 26698)
@@ -25,3 +25,5 @@
 ** optional but needed if you want an answer
 ';
 
+$messages['contactpage-captcha']= 'To send the message, please solve the captcha ([[Special:Captcha/help|more info]])';
+$messages['contactpage-captcha-failed']= 'Captcha test failed! ([[Special:Captcha/help|more info]])';
Index: trunk/extensions/ContactPage/SpecialContact.php
===================================================================
--- trunk/extensions/ContactPage/SpecialContact.php	(revision 26697)
+++ trunk/extensions/ContactPage/SpecialContact.php	(revision 26698)
@@ -71,13 +71,17 @@
 				$tokenOk = $wgUser->matchEditToken( $token );
 			}
 
-			if ( $tokenOk ) {
-				wfDebug( "$fname: submit\n" );
-				$f->doSubmit();
-			} else {
+			if ( !$tokenOk ) {
 				wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
 				$wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
 				$f->showForm();
+			} else if ( !$f->passCaptcha() ) {
+				wfDebug( "$fname: captcha failed" );
+				$wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
+				$f->showForm();
+			} else {
+				wfDebug( "$fname: submit\n" );
+				$f->doSubmit();
 			}
 		} else {
 			wfDebug( "$fname: form\n" );
@@ -101,6 +105,8 @@
 	 */
 	function EmailContactForm( $target ) {
 		global $wgRequest, $wgUser;
+		global $wgCaptcha, $wgCaptchaTriggers;
+
 		$this->target = $target;
 		$this->text = $wgRequest->getText( 'wpText' );
 		$this->subject = $wgRequest->getText( 'wpSubject' );
@@ -113,6 +119,12 @@
 			if (!$this->fromname) $this->fromname = $wgUser->getName();
 			if (!$this->fromaddress) $this->fromaddress = $wgUser->getEmail();
 		}
+
+		//prepare captcha if applicable
+		if ( $wgCaptcha && @$wgCaptchaTriggers['contactpage'] ) {
+			$wgCaptcha->trigger = 'contactpage';
+			$wgCaptcha->action = 'contact';
+		}
 	}
 
 	function showForm() {
@@ -176,12 +188,32 @@
 <textarea name=\"wpText\" rows='20' cols='80' wrap='virtual' style=\"width: 100%;\">" . htmlspecialchars( $this->text ) .
 "</textarea>
 " . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "<br />
+" . $this->getCaptcha() . "
 <input type='submit' name=\"wpSend\" value=\"{$ems}\" />
 <input type='hidden' name='wpEditToken' value=\"$token\" />
 </form>\n" );
 
 	}
 
+	function getCaptcha() {
+		global $wgCaptcha, $wgCaptchaTriggers;
+		if ( !$wgCaptcha ) return ""; //no captcha installed
+		if ( !@$wgCaptchaTriggers['contactpage'] ) return ""; //don't trigger on contact form
+
+		return "<div class='captcha'>" .
+		$wgCaptcha->getForm() .
+		wfMsgWikiHtml( 'contactpage-captcha' ) .
+		"</div>\n";
+	}
+
+	function passCaptcha() {
+		global $wgCaptcha, $wgCaptchaTriggers;
+		if ( !$wgCaptcha ) return true; //no captcha installed
+		if ( !@$wgCaptchaTriggers['contactpage'] ) return true; //don't trigger on contact form
+
+		return $wgCaptcha->passCaptcha();
+	}
+
 	function doSubmit( ) {
 		global $wgOut, $wgContactSender, $wgContactSenderName;
 
Index: trunk/extensions/ContactPage/ContactPage.i18n.de.php
===================================================================
--- trunk/extensions/ContactPage/ContactPage.i18n.de.php	(revision 26697)
+++ trunk/extensions/ContactPage/ContactPage.i18n.de.php	(revision 26698)
@@ -25,3 +25,6 @@
 ** optional, wird aber benötigt um Ihnen antworten zu können
 ';
 
+$messages['contactpage-captcha']= 'Um die Nachricht senden zu können, lösen Sie bitte das Captcha ([[Special:Captcha/help|weitere Informationen]])';
+$messages['contactpage-captcha-failed']= 'Captcha-Test nicht bestanden! ([[Special:Captcha/help|weitere Informationen]])';
+
Index: trunk/extensions/ContactPage/README
===================================================================
--- trunk/extensions/ContactPage/README	(revision 26697)
+++ trunk/extensions/ContactPage/README	(revision 26698)
@@ -46,3 +46,8 @@
 $wgContactSenderName is the name associated with the contact sender.
 This will be shown in the recipient's email program.
 
+If you are using the ConfirmEdit extension (captchas), you can require
+a captcha test for sending contact messages by using the following:
+
+   $wgCaptchaTriggers['contactpage'] = true;
+

Status & tagging log

  • 15:21, 12 September 2011 Meno25 (Talk | contribs) changed the status of r26698 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox