Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.395
diff -u -F^f -r1.395 comment.module
--- modules/comment.module	25 Nov 2005 10:11:59 -0000	1.395
+++ modules/comment.module	26 Nov 2005 08:43:09 -0000
@@ -486,52 +486,26 @@ function comment_reply($nid, $pid = NULL
   return $output;
 }
 
-function comment_validate(&$edit) {
+function comment_validate($edit) {
   global $user;
 
   // Invoke other validation handlers
   comment_invoke_comment($edit, 'validate');
 
   // only admins can change these fields
-  if (!user_access('administer comments')) {
-    $edit['uid'] = $user->uid;
-    $edit['timestamp'] = time();
-    $edit['status'] = user_access('post comments without approval') ? 0 : 1;
-  }
-  else {
+  if (user_access('administer comments')) {
     $date = isset($edit['date']) ? $edit['date'] : 'now';
-    if (strtotime($date) != -1) {
-      $edit['timestamp'] = strtotime($date);
-    }
-    else {
+    if (strtotime($date) == -1) {
       form_set_error('date', t('You have to specify a valid date.'));
     }
 
     if ($edit['uid']) {
       // if a registered user posted the comment, we assume you only want to transfer authorship
       // to another registered user. Name changes are freely allowed on anon comments.
-      if ($account = user_load(array('name' => $edit['author']))) {
-        $edit['uid'] = $account->uid;
-      }
-      else {
+      if (!user_load(array('name' => $edit['author']))) {
         form_set_error('author', t('You have to specify a valid author.'));
       }
     }
-    else {
-      $edit['uid'] = 0;
-      $edit['name'] = $edit['author'];
-    }
-  }
-
-  // Validate the comment's subject.  If not specified, extract
-  // one from the comment's body.
-  if (trim($edit['subject']) == '') {
-    // The body may be in any format, so we:
-    // 1) Filter it into HTML
-    // 2) Strip out all HTML tags
-    // 3) Convert entities back to plain-text.
-  // Note: format is checked by check_markup().
-    $edit['subject'] = truncate_utf8(decode_entities(strip_tags(check_markup($edit['comment'], $edit['format']))), 29, TRUE);
   }
 
   // Validate the comment's body.
@@ -575,8 +549,6 @@ function comment_validate(&$edit) {
       }
     }
   }
-
-  return $edit;
 }
 
 /**
@@ -1189,8 +1161,9 @@ function comment_form_add_preview($form,
 
   $output = '';
 
-  $comment = array2object(comment_validate($edit));
-
+  comment_validate($edit);
+  $comment = array2object($edit);
+  
   // Attach the user and time information.
   if ($edit['author']) {
     $account = user_load(array('name' => $edit['author']));
@@ -1204,6 +1177,8 @@ function comment_form_add_preview($form,
   }
   $comment->timestamp = $edit['timestamp'] ? $edit['timestamp'] : time();
 
+  $comment->subject = _comment_form_subject($edit);
+
   // Preview the comment with security check.
   if (!form_get_errors()) {
     $output .= theme('comment_view', $comment);
@@ -1233,10 +1208,38 @@ function comment_form_validate($form_id,
 }
 
 function comment_form_execute($form_id, $form_values) {
+  global $user;
 
   $op = isset($_POST['op']) ? $_POST['op'] : '';
   $nid = $form_values['nid'];
 
+  // only admins can change these fields
+  if (!user_access('administer comments')) {
+    $form_values['uid'] = $user->uid;
+    $form_values['timestamp'] = time();
+    $form_values['status'] = user_access('post comments without approval') ? 0 : 1;
+  }
+  else {
+    $date = isset($form_values['date']) ? $form_values['date'] : 'now';
+    if (strtotime($date) != -1) {
+      $form_values['timestamp'] = strtotime($date);
+    }
+
+    if ($form_values['uid']) {
+      // if a registered user posted the comment, we assume you only want to transfer authorship
+      // to another registered user. Name changes are freely allowed on anon comments.
+      if ($account = user_load(array('name' => $form_values['author']))) {
+        $form_values['uid'] = $account->uid;
+      }
+    }
+    else {
+      $form_values['uid'] = 0;
+      $form_values['name'] = $form_values['author'];
+    }
+  }
+
+  $form_values['subject'] = _comment_form_subject($form_values);
+
   // are we posting or previewing a reply?
   if ($op == t('Post comment')) {
     drupal_set_title(t('Post comment'));
@@ -1244,7 +1247,7 @@ function comment_form_execute($form_id, 
       drupal_goto("node/$nid#comment-$cid");
     }
   }
-  else if ($_POST['op'] == t('Preview comment')) {
+  else if ($op == t('Preview comment')) {
     drupal_set_title(t('Preview comment'));
   }
 }
@@ -1255,7 +1258,9 @@ function comment_form_execute($form_id, 
 */
 
 function theme_comment_form($form) {
-  return form_render($form);
+  $output = "<a id=\"comment-form\"></a>\n";
+  $output .= form_render($form);
+  return $output;
 }
 
 function theme_comment_preview($comment, $links = array(), $visible = 1) {
@@ -1508,3 +1513,19 @@ function comment_invoke_comment(&$commen
   }
   return $return;
 }
+
+function _comment_form_subject($edit) {
+  // If a comment's subject is not specified, extract
+  // one from the comment's body.
+  if (trim($edit['subject']) == '') {
+    // The body may be in any format, so we:
+    // 1) Filter it into HTML
+    // 2) Strip out all HTML tags
+    // 3) Convert entities back to plain-text.
+    // Note: format is checked by check_markup().
+    $subject = truncate_utf8(decode_entities(strip_tags(check_markup($edit['comment'], $edit['format']))), 29, TRUE);
+  } else {
+    $subject = $edit['subject'];
+  }
+  return $subject;
+}
