Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.621
diff -u -p -r1.621 comment.module
--- modules/comment/comment.module	23 Feb 2008 08:02:48 -0000	1.621
+++ modules/comment/comment.module	21 Mar 2008 22:09:32 -0000
@@ -575,6 +575,13 @@ function comment_form_alter(&$form, $for
       '#options' => array(t('Disabled'), t('Enabled')),
       '#description' => t('Can users provide a unique subject for their comments?'),
     );
+    $form['comment']['comment_default_subject'] = array(
+      '#type' => 'radios',
+      '#title' => t('Default comment subject'),
+      '#default_value' => variable_get('comment_default_subject_'. $form['#node_type']->type, 0),
+      '#options' => array(t('None'), t('Inherit from parent')),
+      '#description' => t('Set a default value for the comment subject field.'),
+    );
     $form['comment']['comment_preview'] = array(
       '#type' => 'radios',
       '#title' => t('Preview comment'),
@@ -1376,8 +1383,28 @@ function comment_form(&$form_state, $edi
     $form['homepage'] = array('#type' => 'textfield', '#title' => t('Homepage'), '#maxlength' => 255, '#size' => 30, '#default_value' => $edit['homepage']);
   }
 
+  $subject = array_key_exists('subject', $edit) ? $edit['subject']:'';
+
+  if (empty($subject) && variable_get('comment_default_subject_'. $node->type, 0) == 1) {
+    // Create subject from node title or parent comment subject.
+    if (!empty($edit['pid']) && $edit['pid'] > 0) {
+      $parent = _comment_load($edit['pid']);
+      $subject = $parent->subject;
+    }
+    else {
+      $subject = $node->title;
+    }
+    $pattern = '/^'. preg_quote(t('Re:')) .'/i';
+    if (!preg_match($pattern, $subject)) {
+      $subject = t('Re:') ." $subject";
+    }
+  }
+
   if (variable_get('comment_subject_field_'. $node->type, 1) == 1) {
-    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => !empty($edit['subject']) ? $edit['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'])) {
