? .DS_Store
? modules/system/system.admin
? sites/.DS_Store
? sites/all/modules/devel
? sites/default/files
? sites/default/settings.php
? themes/.DS_Store
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.930
diff -u -p -r1.930 comment.module
--- modules/comment/comment.module	28 Dec 2010 18:19:23 -0000	1.930
+++ modules/comment/comment.module	31 Dec 2010 19:14:44 -0000
@@ -1491,7 +1491,7 @@ function comment_save($comment) {
       db_ignore_slave();
 
       // Update the {node_comment_statistics} table prior to executing hooks.
-       _comment_update_node_statistics($comment->nid);
+      _comment_update_node_statistics($comment->nid);
 
       field_attach_update('comment', $comment);
       // Allow modules to respond to the updating of a comment.
@@ -1931,11 +1931,9 @@ function comment_form($form, &$form_stat
       '#default_value' => $author,
       '#maxlength' => 60,
       '#size' => 30,
+      '#description' => !empty($comment->cid) ? t('Leave this field blank to make this an anonymous comment.') : '',
+      '#autocomplete_path' => 'user/autocomplete',
     );
-    // If the comment is by a registered user, allow to autocomplete username.
-    if ($comment->registered_name != '') {
-      $form['author']['name']['#autocomplete_path'] = 'user/autocomplete';
-    }
   }
   elseif ($user->uid) {
     $form['author']['_author'] = array(
@@ -2123,21 +2121,22 @@ function comment_form_validate($form, &$
       form_set_error('name', t('You have to specify a valid author.'));
     }
   }
-
-  // Validate anonymous comment author fields (if given).
-  if ($form_state['values']['is_anonymous']) {
-    // If the (original) author of this comment was an anonymous user, verify
-    // that no registered user with this name exists.
-    if ($form_state['values']['name']) {
-      $query = db_select('users', 'u');
-      $query->addField('u', 'uid', 'uid');
-      $taken = $query
-        ->condition('name', db_like($form_state['values']['name']), 'LIKE')
-        ->countQuery()
-        ->execute()
-        ->fetchField();
-      if ($taken) {
-        form_set_error('name', t('The name you used belongs to a registered user.'));
+  else {
+    // Validate anonymous comment author fields (if given).
+    if ($form_state['values']['is_anonymous']) {
+      // If the (original) author of this comment was an anonymous user, verify
+      // that no registered user with this name exists.
+      if ($form_state['values']['name']) {
+        $query = db_select('users', 'u');
+        $query->addField('u', 'uid', 'uid');
+        $taken = $query
+          ->condition('name', db_like($form_state['values']['name']), 'LIKE')
+          ->countQuery()
+          ->execute()
+          ->fetchField();
+        if ($taken) {
+          form_set_error('name', t('The name you used belongs to a registered user.'));
+        }
       }
     }
   }
@@ -2217,6 +2216,18 @@ function comment_form_submit($form, &$fo
   $node = node_load($form_state['values']['nid']);
   $comment = comment_form_submit_build_comment($form, $form_state);
   if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
+    // If the name field has been emptied then make this an anonymous comment.
+    if (empty($comment->name)) {
+      $comment->uid = 0;
+      $comment->name = variable_get('anonymous', t('Anonymous'));
+    }
+
+    if (!$comment->new) {
+      // Verify the name in case it is being changed from being anonymous.
+      $user = user_load_by_name($comment->name);
+      $comment->uid = $user ? $user->uid : 0;
+    }
+
     // Save the anonymous user information to a cookie for reuse.
     if (!$comment->uid) {
       user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage'))));
Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.97
diff -u -p -r1.97 comment.test
--- modules/comment/comment.test	28 Dec 2010 18:19:23 -0000	1.97
+++ modules/comment/comment.test	31 Dec 2010 19:14:44 -0000
@@ -303,6 +303,27 @@ class CommentInterfaceTest extends Comme
     $this->drupalLogin($this->admin_user);
     $this->setCommentSubject(TRUE);
     $this->setCommentPreview(DRUPAL_OPTIONAL);
+
+    // Test changing the comment author to "Anonymous".
+    $comment->name = '';
+    $this->drupalPost('comment/' . $comment->id . '/edit', $comment, t('Save'));
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($comment_loaded->name == variable_get('anonymous', t('Anonymous')) && $comment_loaded->uid == 0, t('Comment author successfully changed to anonymous.'));
+
+    // Test changing the comment author to an unverified user.
+    $random_name = $this->randomName();
+    $comment->name = $random_name;
+    $this->drupalPost('comment/' . $comment->id . '/edit', $comment, t('Save'));
+    $comment_loaded = comment_load($comment->id);
+    $this->drupalGet('node/' . $this->node->nid);
+    $this->assertText($random_name . ' (' . t('not verified') . ')', t('Comment author successfully changed to an unverified user.'));
+
+    // Test changing the comment author to a verified user.
+    $comment->name = $this->web_user->name;
+    $this->drupalPost('comment/' . $comment->id . '/edit', $comment, t('Save'));
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($comment_loaded->name == $this->web_user->name && $comment_loaded->uid == $this->web_user->uid, t('Comment author successfully changed to a registered user.'));
+
     $this->drupalLogout();
 
     // Reply to comment #2 creating comment #3 with optional preview and no
