--- C:\Documents and Settings\Aldo\Local Settings\Temp\TCV8e57.tmp\comment.1.569.module	Sun Jul 29 15:53:46 2007
+++ D:\drupal cvs\6.x\drupal\modules\comment\comment.module	Sun Jul 29 15:52:57 2007
@@ -576,6 +576,14 @@
     '#description' => t('Can users provide a unique subject for their comments?'),
   );
 
+  $form['posting_settings']['comment_subject_create'] = array(
+    '#type' => 'radios',
+    '#title' => t('Generate comment subject automatically'),
+    '#default_value' => variable_get('comment_subject_create', 0),
+    '#options' => array(t('Disabled'), t('Enabled')),
+    '#description' => t('Should comment subjects be automatically generated from their parent\'s subjects? If the comment subject field is enabled, user will still be able to change the generated comment.'),
+  );
+
   $form['posting_settings']['comment_preview'] = array(
     '#type' => 'radios',
     '#title' => t('Preview comment'),
@@ -1556,8 +1564,29 @@
     $form['homepage'] = array('#type' => 'textfield', '#title' => t('Homepage'), '#maxlength' => 255, '#size' => 30, '#default_value' => $edit['homepage']);
   }
 
-  if (variable_get('comment_subject_field', 1) == 1) {
-    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => !empty($edit['subject']) ? $edit['subject'] : '');
+  $create_subject = (variable_get('comment_subject_create', 0) == 1);
+  $subject = !empty($edit['subject']) ? $edit['subject']:'';
+
+  if (empty($subject) && $create_subject) {
+    // create subject from node title or parent comment subject
+    if(!empty($edit['pid']) && $edit['pid'] > 0) {
+      $parent = _comment_load(arg($edit['pid']));
+    }
+    else {
+      $parent = node_load(array('nid' => $edit['nid']));
+    }
+    $subject = $parent->title;
+    $pattern = '/^'.preg_quote(t('Re:')).'/i';
+    if(!preg_match($pattern, $subject)) {
+      $subject = t('Re:')." $subject";
+    }
+  }
+
+  if ($create_subject) {
+    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => $subject);
+  }
+  else if(!empty($subject)) {
+    $form['subject'] = array('#type' => 'hidden', '#value' => $subject);
   }
 
   if (!empty($edit['comment'])) {
