Index: /trunk/admin/configuration.php
===================================================================
--- /trunk/admin/configuration.php	(revision 18163)
+++ /trunk/admin/configuration.php	(revision 18164)
@@ -74,5 +74,7 @@
     'user_can_edit_comment',
     'email_admin_on_comment_edition',
-    'email_admin_on_comment_deletion'
+    'email_admin_on_comment_deletion',
+    'comments_author_mandatory',
+    'comments_email_mandatory',
   );
 
Index: /trunk/admin/themes/default/template/configuration.tpl
===================================================================
--- /trunk/admin/themes/default/template/configuration.tpl	(revision 18163)
+++ /trunk/admin/themes/default/template/configuration.tpl	(revision 18164)
@@ -226,4 +226,18 @@
         <input type="checkbox" name="comments_validation" {if ($comments.comments_validation)}checked="checked"{/if}>
         {'Validation'|@translate}
+      </label>
+    </li>
+    
+    <li>
+      <label>
+        <input type="checkbox" name="comments_author_mandatory" {if ($comments.comments_author_mandatory)}checked="checked"{/if}>
+        {'Username is mandatory'|@translate}
+      </label>
+    </li>
+    
+    <li>
+      <label>
+        <input type="checkbox" name="comments_email_mandatory" {if ($comments.comments_email_mandatory)}checked="checked"{/if}>
+        {'Email address is mandatory'|@translate}
       </label>
     </li>
Index: /trunk/comments.php
===================================================================
--- /trunk/comments.php	(revision 18163)
+++ /trunk/comments.php	(revision 18164)
@@ -384,4 +384,6 @@
        com.author,
        com.author_id,
+       u.'.$conf['user_fields']['email'].' AS user_email,
+       com.email,
        com.date,
        com.website_url,
@@ -474,4 +476,14 @@
         )
       );
+      
+    $email = null;
+    if (!empty($comment['user_email']))
+    {
+      $email = $comment['user_email'];
+    }
+    else if (!empty($comment['email']))
+    {
+      $email = $comment['email'];
+    }
 
     $tpl_comment = array(
@@ -485,4 +497,9 @@
       'CONTENT'=>trigger_event('render_comment_content',$comment['content']),
       );
+      
+    if (is_admin())
+    {
+      $tpl_comment['EMAIL'] = $email;
+    }
 
     if (can_manage_comment('delete', $comment['author_id']))
Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 18163)
+++ /trunk/include/functions.inc.php	(revision 18164)
@@ -1726,3 +1726,22 @@
   }
 }
+
+/**
+ * check email format
+ */
+function email_check_format($mail_address)
+{
+  if (version_compare(PHP_VERSION, '5.2.0') >= 0)
+  {
+    return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
+  }
+  else
+  {
+    $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
+    $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
+    $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
+
+    return (bool)preg_match($regex, $mail_address);
+  }
+}
 ?>
Index: /trunk/include/functions_comment.inc.php
===================================================================
--- /trunk/include/functions_comment.inc.php	(revision 18163)
+++ /trunk/include/functions_comment.inc.php	(revision 18164)
@@ -92,4 +92,9 @@
     if ( empty($comm['author']) )
     {
+      if ($conf['comments_author_mandatory'])
+      {
+        array_push($infos, l10n('Username is mandatory') );
+        $comment_action='reject';
+      }
       $comm['author'] = 'guest';
     }
@@ -129,11 +134,33 @@
   
   // website
-  if ( !empty($comm['website_url']) and !preg_match('/^https?/i', $comm['website_url']) )
-  {
-    $comm['website_url'] = 'http://'.$comm['website_url'];
-  }
-  if ( !empty($comm['website_url']) and !url_check_format($comm['website_url']) )
-  {
-    array_push($infos, l10n('Your website URL is invalid'));
+  if (!empty($comm['website_url']))
+  {
+    if (!preg_match('/^https?/i', $comm['website_url']))
+    {
+      $comm['website_url'] = 'http://'.$comm['website_url'];
+    }
+    if (!url_check_format($comm['website_url']))
+    {
+      array_push($infos, l10n('Your website URL is invalid'));
+      $comment_action='reject';
+    }
+  }
+  
+  // email
+  if (empty($comm['email']))
+  {
+    if (!empty($user['email']))
+    {
+      $comm['email'] = $user['email'];
+    }
+    else if ($conf['comments_email_mandatory'])
+    {
+      array_push($infos, l10n('Email address is missing. Please specify an email address.') );
+      $comment_action='reject';
+    }
+  }
+  else if (!email_check_format($comm['email']))
+  {
+    array_push($infos, l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     $comment_action='reject';
   }
@@ -180,5 +207,5 @@
     $query = '
 INSERT INTO '.COMMENTS_TABLE.'
-  (author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url)
+  (author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url, email)
   VALUES (
     \''.$comm['author'].'\',
@@ -190,5 +217,6 @@
     '.($comment_action=='validate' ? 'NOW()':'NULL').',
     '.$comm['image_id'].',
-    '.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').'
+    '.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').',
+    '.(!empty($comm['email']) ? '\''.$comm['email'].'\'' : 'NULL').'
   )
 ';
@@ -208,4 +236,5 @@
       (
         get_l10n_args('Author: %s', stripslashes($comm['author']) ),
+        get_l10n_args('Email: %s', stripslashes($comm['email']) ),
         get_l10n_args('Comment: %s', stripslashes($comm['content']) ),
         get_l10n_args('', ''),
Index: /trunk/include/functions_user.inc.php
===================================================================
--- /trunk/include/functions_user.inc.php	(revision 18163)
+++ /trunk/include/functions_user.inc.php	(revision 18164)
@@ -42,9 +42,5 @@
   }
 
-  $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
-  $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
-  $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
-
-  if ( !preg_match( $regex, $mail_address ) )
+  if ( !email_check_format($mail_address) )
   {
     return l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
@@ -54,8 +50,8 @@
   {
     $query = '
-select count(*)
-from '.USERS_TABLE.'
-where upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\')
-'.(is_numeric($user_id) ? 'and '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').'
+SELECT count(*)
+FROM '.USERS_TABLE.'
+WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\')
+'.(is_numeric($user_id) ? 'AND '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').'
 ;';
     list($count) = pwg_db_fetch_row(pwg_query($query));
Index: /trunk/include/picture_comment.inc.php
===================================================================
--- /trunk/include/picture_comment.inc.php	(revision 18163)
+++ /trunk/include/picture_comment.inc.php	(revision 18164)
@@ -50,4 +50,5 @@
     'content' => trim( $_POST['content'] ),
     'website_url' => trim( $_POST['website_url'] ),
+    'email' => trim( @$_POST['email'] ),
     'image_id' => $page['image_id'],
    );
@@ -55,5 +56,5 @@
   include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
 
-  $comment_action = insert_user_comment($comm, @$_POST['key'], $page['infos']);
+  $comment_action = insert_user_comment($comm, @$_POST['key'], $page['errors']);
 
   switch ($comment_action)
@@ -144,8 +145,9 @@
     author,
     author_id,
-    '.$conf['user_fields']['username'].' AS username,
+    u.'.$conf['user_fields']['email'].' AS user_email,
     date,
     image_id,
     website_url,
+    com.email,
     content,
     validated
@@ -162,15 +164,17 @@
     while ($row = pwg_db_fetch_assoc($result))
     {
-      if (!empty($row['author']))
-      {
-	$author = $row['author'];
-	if ($author == 'guest')
-	{
-	  $author = l10n('guest');
-	}
-      }
-      else
-      {
-	$author = stripslashes($row['username']);
+      if ($row['author'] == 'guest')
+      {
+        $row['author'] = l10n('guest');
+      }
+      
+      $email = null;
+      if (!empty($row['user_email']))
+      {
+        $email = $row['user_email'];
+      }
+      else if (!empty($row['email']))
+      {
+        $email = $row['email'];
       }
 
@@ -178,5 +182,5 @@
         array(
           'ID' => $row['id'],
-          'AUTHOR' => trigger_event('render_comment_author', $author),
+          'AUTHOR' => trigger_event('render_comment_author', $row['author']),
           'DATE' => format_date($row['date'], true),
           'CONTENT' => trigger_event('render_comment_content',$row['content']),
@@ -216,4 +220,6 @@
       if (is_admin())
       {
+        $tpl_comment['EMAIL'] = $email;
+        
         if ($row['validated'] != 'true')
         {
@@ -245,19 +251,17 @@
   {
     $key = get_ephemeral_key(3, $page['image_id']);
-    $content = $author = $website_url = '';
-    if ('reject'===@$comment_action)
-    {
-      $content = htmlspecialchars( stripslashes($comm['content']) );
-      $author = htmlspecialchars( stripslashes($comm['author']) );
-      $website_url = htmlspecialchars( stripslashes($comm['website_url']) );
-    }
+    
     $template->assign('comment_add',
         array(
-          'F_ACTION' => $url_self,
-          'KEY' => $key,
-          'CONTENT' => $content,
-          'SHOW_AUTHOR' => !is_classic_user(),
-          'AUTHOR' => $author ,
-          'WEBSITE_URL' => $website_url, 
+          'F_ACTION' =>         $url_self,
+          'KEY' =>              $key,
+          'CONTENT' =>          stripslashes(@$_POST['content']),
+          'SHOW_AUTHOR' =>      !is_classic_user(),
+          'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'],
+          'AUTHOR' =>           stripslashes(@$_POST['author']),
+          'WEBSITE_URL' =>      stripslashes(@$_POST['website_url']),
+          'SHOW_EMAIL' =>       !is_classic_user() or empty($user['email']),
+          'EMAIL_MANDATORY' =>  $conf['comments_email_mandatory'],
+          'EMAIL' =>            stripslashes(@$_POST['email']), 
         ));
   }
Index: /trunk/install/config.sql
===================================================================
--- /trunk/install/config.sql	(revision 18163)
+++ /trunk/install/config.sql	(revision 18164)
@@ -7,4 +7,6 @@
 INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_forall','false','even guest not registered can post comments');
 INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_order','ASC','comments order on picture page and cie');
+INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_author_mandatory','false');
+INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_email_mandatory','false');
 INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_delete_comment','false','administrators can allow user delete their own comments');
 INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_edit_comment','false','administrators can allow user edit their own comments');
Index: /trunk/install/db/130-database.php
===================================================================
--- /trunk/install/db/130-database.php	(revision 18164)
+++ /trunk/install/db/130-database.php	(revision 18164)
@@ -0,0 +1,41 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+  die('Hacking attempt!');
+}
+
+$upgrade_description = 'add "email" field in comments table';
+
+include_once(PHPWG_ROOT_PATH.'include/constants.php');
+
+$query = 'ALTER TABLE `'.COMMENTS_TABLE.'` ADD `email` varchar(255) default NULL;';
+pwg_query($query);
+
+conf_update_param('comments_author_mandatory', 'false');
+conf_update_param('comments_email_mandatory', 'false');
+
+echo "\n".$upgrade_description."\n";
+
+?>
Index: /trunk/install/piwigo_structure-mysql.sql
===================================================================
--- /trunk/install/piwigo_structure-mysql.sql	(revision 18163)
+++ /trunk/install/piwigo_structure-mysql.sql	(revision 18164)
@@ -52,4 +52,5 @@
   `date` datetime NOT NULL default '0000-00-00 00:00:00',
   `author` varchar(255) default NULL,
+  `email` varchar(255) default NULL,
   `author_id` smallint(5) DEFAULT NULL,
   `anonymous_id` varchar(45) NOT NULL,
Index: /trunk/language/en_UK/common.lang.php
===================================================================
--- /trunk/language/en_UK/common.lang.php	(revision 18163)
+++ /trunk/language/en_UK/common.lang.php	(revision 18164)
@@ -166,4 +166,5 @@
 $lang['Email address is missing. Please specify an email address.'] = "Email address is missing. Please specify an email address.";
 $lang['Email address'] = "Email address";
+$lang['Email address is mandatory'] = 'Email address is mandatory';
 $lang['Email: %s'] = "Email: %s";
 $lang['Empty query. No criteria has been entered.'] = 'Empty query. No criteria have been entered.';
@@ -385,4 +386,5 @@
 $lang['Username or email'] = 'Username or email';
 $lang['Username'] = "Username";
+$lang['Username is mandatory'] = 'Username is mandatory';
 $lang['Username: %s'] = 'Username: %s';
 $lang['View in'] = 'View in';
@@ -408,3 +410,4 @@
 $lang['Your password has been reset'] = 'Your password has been reset';
 $lang['Your username has been successfully changed to : %s'] = 'Your username has been successfully changed to : %s';
+$lang['mandatory'] = 'mandatory';
 ?>
Index: /trunk/language/fr_FR/common.lang.php
===================================================================
--- /trunk/language/fr_FR/common.lang.php	(revision 18163)
+++ /trunk/language/fr_FR/common.lang.php	(revision 18164)
@@ -408,3 +408,6 @@
 $lang['Permalink for album not found'] = 'Permalink pour l\'album non trouvé';
 $lang['Requested tag does not exist'] = 'Le tag demandée n\'existe pas';
+$lang['Username is mandatory'] = 'Nom d\'utilisateur obligatoire';
+$lang['Email address is mandatory'] = 'Adresse email obligatoire';
+$lang['mandatory'] = 'obligatoire';
 ?>
Index: /trunk/themes/default/template/comment_list.tpl
===================================================================
--- /trunk/themes/default/template/comment_list.tpl	(revision 18163)
+++ /trunk/themes/default/template/comment_list.tpl	(revision 18164)
@@ -55,5 +55,6 @@
 		{/if}
 
-		<span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span> 
+		<span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span>
+      {if $comment.EMAIL}- <a href="mailto:{$comment.EMAIL}">{$comment.EMAIL}</a>{/if}
       - <span class="commentDate">{$comment.DATE}</span>
 		{if isset($comment.IN_EDIT)}
Index: /trunk/themes/default/template/picture.tpl
===================================================================
--- /trunk/themes/default/template/picture.tpl	(revision 18163)
+++ /trunk/themes/default/template/picture.tpl	(revision 18164)
@@ -349,10 +349,14 @@
 			<form method="post" action="{$comment_add.F_ACTION}" id="addComment">
 				{if $comment_add.SHOW_AUTHOR}
-					<p><label for="author">{'Author'|@translate} :</label></p>
+					<p><label for="author">{'Author'|@translate}{if $comment_add.AUTHOR_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p>
 					<p><input type="text" name="author" id="author" value="{$comment_add.AUTHOR}"></p>
 				{/if}
-        <p><label for="website_url">{'Website'|@translate} :</label></p>
-			  <p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p>
-			  <p><label for="contentid">{'Comment'|@translate} :</label></p>
+				{if $comment_add.SHOW_EMAIL}
+					<p><label for="email">{'Email'|@translate}{if $comment_add.EMAIL_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p>
+					<p><input type="text" name="email" id="email" value="{$comment_add.EMAIL}"></p>
+				{/if}
+				<p><label for="website_url">{'Website'|@translate} :</label></p>
+				<p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p>
+				<p><label for="contentid">{'Comment'|@translate} ({'mandatory'|@translate}) :</label></p>
 				<p><textarea name="content" id="contentid" rows="5" cols="50">{$comment_add.CONTENT}</textarea></p>
 				<p><input type="hidden" name="key" value="{$comment_add.KEY}">
