r37136 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r37135 | r37136 (on ViewVC) | r37137 >
Date:21:20, 5 July 2008
Author:daniel
Status:ok
Tags:
Comment:added option that forces visitors to enter name and email address
Modified paths:

Diff [purge]

Index: trunk/extensions/ContactPage/SpecialContact.php
===================================================================
--- trunk/extensions/ContactPage/SpecialContact.php	(revision 37135)
+++ trunk/extensions/ContactPage/SpecialContact.php	(revision 37136)
@@ -59,7 +59,7 @@
 		if ( "success" == $action ) {
 			wfDebug( "$fname: success.\n" );
 			$f->showSuccess( );
-		} else if ( "submit" == $action && $wgRequest->wasPosted() && $f->text !== NULL ) {
+		} else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
 			$token = $wgRequest->getVal( 'wpEditToken' );
 
 			if( $wgUser->isAnon() ) {
@@ -111,9 +111,6 @@
 		$this->subject = $wgRequest->getText( 'wpSubject' );
 		$this->cc_me = $wgRequest->getBool( 'wpCCMe' );
 
-		if ( $this->text !== NULL ) $this->text = trim( $this->text );
-		if ( $this->text === '' ) $this->text = NULL;
-
 		$this->fromname = $wgRequest->getText( 'wpFromName' );
 		$this->fromaddress = $wgRequest->getText( 'wpFromAddress' );
 
@@ -130,8 +127,28 @@
 		}
 	}
 
+	function hasAllInfo() {
+		global $wgContactRequireAll;
+
+		if ( $this->text === NULL ) return false;
+		else $this->text = trim( $this->text );
+		if ( $this->text === '' ) return false;
+
+		if ( $wgContactRequireAll ) {
+			if ( $this->fromname === NULL ) return false;
+			else $this->fromname = trim( $this->fromname );
+			if ( $this->fromname === '' ) return false;
+
+			if ( $this->fromaddress === NULL ) return false;
+			else $this->fromaddress = trim( $this->fromaddress );
+			if ( $this->fromaddress === '' ) return false;
+		}
+
+		return true;
+	}
+
 	function showForm() {
-		global $wgOut, $wgUser;
+		global $wgOut, $wgUser, $wgContactRequireAll;
 
 		#TODO: show captcha
 
@@ -142,14 +159,16 @@
 			$this->subject = wfMsgForContent( "contactpage-defsubject" );
 		}
 
+		$msgSuffix = $wgContactRequireAll ? '-required' : '';
+
 		$emt = wfMsg( "emailto" );
 		$rcpt = $this->target->getName();
 		$emr = wfMsg( "emailsubject" );
 		$emm = wfMsg( "emailmessage" );
 		$ems = wfMsg( "emailsend" );
 		$emc = wfMsg( "emailccme" );
-		$emfn = wfMsg( "contactpage-fromname" );
-		$emfa = wfMsg( "contactpage-fromaddress" );
+		$emfn = wfMsg( "contactpage-fromname$msgSuffix" );
+		$emfa = wfMsg( "contactpage-fromaddress$msgSuffix" );
 		$encSubject = htmlspecialchars( $this->subject );
 		$encFromName = htmlspecialchars( $this->fromname );
 		$encFromAddress = htmlspecialchars( $this->fromaddress );
@@ -181,7 +200,7 @@
 <tr>
 <td></td>
 <td align='left'>
-<small>".wfMsg( "contactpage-formfootnotes" )."</small>
+<small>".wfMsg( "contactpage-formfootnotes$msgSuffix" )."</small>
 </td>
 </tr>
 </table>
Index: trunk/extensions/ContactPage/ContactPage.i18n.php
===================================================================
--- trunk/extensions/ContactPage/ContactPage.i18n.php	(revision 37135)
+++ trunk/extensions/ContactPage/ContactPage.i18n.php	(revision 37136)
@@ -22,6 +22,9 @@
 	'contactpage-fromaddress' => 'your e-mail **',
 	'contactpage-formfootnotes' => '* optional<br />
 ** optional but needed if you want an answer',
+	'contactpage-fromname-required' => 'your name',
+	'contactpage-fromaddress-required' => 'your e-mail',
+	'contactpage-formfootnotes-required' => 'All fields are required.',
 	'contactpage-captcha' => 'To send the message, please solve the captcha ([[Special:Captcha/help|more info]])',
 	'contactpage-captcha-failed' => 'Captcha test failed! ([[Special:Captcha/help|more info]])',
 );
@@ -119,6 +122,9 @@
 	'contactpage-fromaddress'        => 'Deine E-Mail-Adresse **',
 	'contactpage-formfootnotes'      => '* optional<br />
 ** optional, wird aber benötigt, um dir antworten zu können',
+	'contactpage-fromname-required' => 'Dein Name',
+	'contactpage-fromaddress-required' => 'Deine E-Mail-Adresse',
+	'contactpage-formfootnotes-required' => 'Alle Felder müssen ausgefüllt sein.',
 	'contactpage-captcha'            => 'Um die Nachricht senden zu können, löse bitte das Captcha ([[Special:Captcha/help|weitere Informationen]])',
 	'contactpage-captcha-failed'     => 'Captcha-Test nicht bestanden! ([[Special:Captcha/help|weitere Informationen]])',
 );
@@ -128,10 +134,12 @@
  */
 $messages['de-formal'] = array(
 	'contactpage-pagetext'           => 'Mit diesem Formular können Sie uns Nachrichten zukommen lassen.',
-	'contactpage-fromname'           => 'Ihre Name *',
+	'contactpage-fromname'           => 'Ihr Name *',
 	'contactpage-fromaddress'        => 'Ihre E-Mail-Adresse **',
 	'contactpage-formfootnotes'      => '* optional<br />
 ** optional, wird aber benötigt, um Ihnen antworten zu können',
+	'contactpage-fromname-required' => 'Ihr Name',
+	'contactpage-fromaddress-required' => 'Ihre E-Mail-Adresse',
 	'contactpage-captcha'            => 'Um die Nachricht senden zu können, lösen Sie bitte das Captcha ([[Special:Captcha/help|weitere Informationen]])',
 );
 
Index: trunk/extensions/ContactPage/ContactPage.php
===================================================================
--- trunk/extensions/ContactPage/ContactPage.php	(revision 37135)
+++ trunk/extensions/ContactPage/ContactPage.php	(revision 37136)
@@ -33,3 +33,5 @@
 $wgContactUser = NULL;
 $wgContactSender = NULL;
 $wgContactSenderName = 'Contact Form on ' . $wgSitename;
+
+$wgContactRequireAll = false;
Views
Toolbox