Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.373
diff -u -r1.373 comment.module
--- modules/comment.module	19 Sep 2005 19:13:35 -0000	1.373
+++ modules/comment.module	23 Sep 2005 23:55:59 -0000
@@ -394,7 +394,7 @@
       drupal_goto("node/$nid#comment-$cid");
     }
   }
-  else if ($_POST['op'] == t('Preview comment')) {
+  else if ($_POST['op'] == t('Preview comment') || $_POST['fileop'] == t('Attach')) {
     $edit = $_POST['edit'];
     $edit = comment_validate($edit);
     drupal_set_title(t('Preview comment'));
@@ -803,6 +803,9 @@
 
       if ($comment = db_fetch_object($result)) {
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
+        if (isset($node->comment_files[$comment->cid])) {
+          $comment->files = $node->comment_files[$comment->cid];
+        }
         $output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 1)));
       }
 
@@ -921,6 +924,9 @@
         $comment = drupal_unpack($comment);
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
         $comment->depth = count(explode('.', $comment->thread)) - 1;
+        if (isset($node->comment_files[$comment->cid])) {
+          $comment->files = $node->comment_files[$comment->cid];
+        }
 
         if ($mode == 1) {
           $output .= theme('comment_flat_collapsed', $comment, $threshold_min);
@@ -1425,6 +1431,8 @@
 
   $form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 60, 15, '', NULL, TRUE);
 
+  $form .= implode('', module_invoke_all('comment', 'form post', $edit));
+
   $form .= filter_form('format', $edit['format']);
   $form .= form_hidden('cid', $edit['cid']);
   $form .= form_hidden('pid', $edit['pid']);
@@ -1443,7 +1451,8 @@
   }
 
   $destination = $_REQUEST['destination'] ? 'destination='. $_REQUEST['destination'] : '';
-  return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination)));
+  $param = module_invoke_all('comment', 'form param', NULL);
+  return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'], $destination), $param));
 }
 
 function theme_comment_preview($comment, $links = '', $visible = 1) {
@@ -1541,6 +1550,7 @@
   $output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
   $output .= '<div class="credit">'. t('by %a on %b', array('%a' => theme('username', $comment), '%b' => format_date($comment->timestamp))) ."</div>\n";
   $output .= "<div class=\"body\">$comment->comment</div>\n";
+  $output .= implode('', module_invoke_all('comment', 'view', $comment));
   $output .= "<div class=\"links\">$links</div>\n";
   $output .= "</div>\n";
   return $output;
Index: modules/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload.module,v
retrieving revision 1.51
diff -u -r1.51 upload.module
--- modules/upload.module	2 Sep 2005 02:11:41 -0000	1.51
+++ modules/upload.module	23 Sep 2005 23:55:59 -0000
@@ -90,6 +90,7 @@
   system_settings_save();
 
   $group .= form_textfield(t('Maximum resolution for uploaded images'), 'upload_max_resolution', variable_get('upload_max_resolution', 0), 15, 10, t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
+  $group .= form_radios(t('Attachments on comments'), 'upload_comment', variable_get('upload_comment', 0), array(0 => t('Disabled'), 1 => t('Enabled')), t('Attachments only displayed if parent node type also accepts attachments.'));
 
   $output = form_group(t('General settings'), $group);
 
@@ -143,7 +144,7 @@
       break;
 
     case 'validate':
-      $node->files = upload_load($node);
+      list ($node->files) = upload_load($node);
 
       // Double check existing files:
       if (is_array($node->list)) {
@@ -230,7 +231,10 @@
 
     case 'load':
       if (variable_get("upload_$node->type", 1) == 1) {
-        $output['files'] = upload_load($node);
+        list ($output['files'], $comment_files) = upload_load($node);
+        if (!empty($comment_files)) {
+          $output['comment_files'] = $comment_files;
+        }
       }
       break;
 
@@ -342,8 +346,8 @@
       // Insert new files:
       if ($file = file_save_upload($file, $file->filename)) {
         $fid = db_next_id('{files}_fid');
-        db_query("INSERT INTO {files} (fid, nid, vid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, %d)",
-                 $fid, $node->nid, $node->vid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
+        db_query("INSERT INTO {files} (fid, nid, vid, cid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d)",
+                 $fid, $node->nid, $node->vid, isset($node->cid) ? $node->cid : 0, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
       }
     }
   }
@@ -376,11 +380,18 @@
 }
 
 function upload_delete($node) {
-  $node->files = upload_load($node);
-  foreach ($node->files as $file) {
+  list ($files, $comment_files) = upload_load($node);
+  foreach ($comment_files as $list) {
+    $files = array_merge($files, $list);
+  }
+  foreach ($files as $file) {
     file_delete($file->filepath);
   }
-  db_query("DELETE FROM {files} WHERE nid = %d", $node->nid);
+  if ($node->nid && !$node->is_comment) {
+    db_query("DELETE FROM {files} WHERE nid = %d", $node->nid);
+  } else if ($node->cid) {
+    db_query("DELETE FROM {files} WHERE cid = %d", $node->cid);
+  }
 }
 
 function upload_form($node) {
@@ -425,16 +436,25 @@
 }
 
 function upload_load($node) {
-  $files = array();
+  $files = $comment_files = array();
 
-  if ($node->vid) {
+  if ($node->vid && !$node->is_comment) {
     $result = db_query("SELECT * FROM {files} WHERE vid = %d", $node->vid);
     while ($file = db_fetch_object($result)) {
+      if ($file->cid) {
+        $comment_files[$file->cid][$file->fid] = $file;
+      } else {
+        $files[$file->fid] = $file;
+      }
+    }
+  } else if ($node->cid) {
+    $result = db_query("SELECT * FROM {files} WHERE cid = %d", $node->cid);
+    while ($file = db_fetch_object($result)) {
       $files[$file->fid] = $file;
     }
   }
 
-  return $files;
+  return array($files, $comment_files);
 }
 
 /**
@@ -471,3 +491,39 @@
   print drupal_call_js('window.parent.iframeHandler', $output);
   exit;
 }
+
+function upload_comment($op, $comment) {
+  switch ($op) {
+    case 'view':
+      upload_nodeapi($comment, 'view', NULL);
+      return $comment->body;
+
+    case 'delete':
+      $comment->is_comment = true;
+      upload_delete($comment);
+      break;
+  }
+  if (variable_get('upload_comment', 0) == 0 || !user_access('upload files')) {
+    return;
+  }
+  if (isset($comment)) {
+    $comment = array2object($comment);
+    $comment->is_comment = true;
+  }
+  switch ($op) {
+    case 'form post':
+      upload_nodeapi($comment, 'validate', NULL);
+      return upload_form($comment);
+
+    case 'form param':
+      return array('enctype' => 'multipart/form-data');
+
+    case 'insert':
+    case 'update':
+      upload_nodeapi($comment, 'validate', NULL);
+      upload_save($comment);
+      break;
+  }
+}
+
+?>
Index: database/database.mysql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.mysql,v
retrieving revision 1.199
diff -u -r1.199 database.mysql
--- database/database.mysql	18 Sep 2005 17:08:44 -0000	1.199
+++ database/database.mysql	23 Sep 2005 23:55:59 -0000
@@ -246,12 +246,14 @@
   fid int(10) unsigned NOT NULL default '0',
   nid int(10) unsigned NOT NULL default '0',
   vid int(10) unsigned NOT NULL default '0',
+  cid int(10) unsigned NOT NULL default '0',
   filename varchar(255) NOT NULL default '',
   filepath varchar(255) NOT NULL default '',
   filemime varchar(255) NOT NULL default '',
   filesize int(10) unsigned NOT NULL default '0',
   list tinyint(1) unsigned NOT NULL default '0',
   KEY vid (vid),
+  KEY cid (cid),
   KEY fid (fid)
 ) TYPE=MyISAM;
 
Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.138
diff -u -r1.138 database.pgsql
--- database/database.pgsql	18 Sep 2005 17:08:44 -0000	1.138
+++ database/database.pgsql	23 Sep 2005 23:55:59 -0000
@@ -242,6 +242,7 @@
   fid SERIAL,
   nid integer NOT NULL default '0',
   vid integer NOT NULL default '0',
+  cid integer NOT NULL default '0',
   filename varchar(255) NOT NULL default '',
   filepath varchar(255) NOT NULL default '',
   filemime varchar(255) NOT NULL default '',
@@ -250,6 +251,7 @@
 );
 CREATE INDEX files_fid_idx ON files(fid);
 CREATE INDEX files_vid_idx ON files(vid);
+CREATE INDEX files_cid_idx ON files(cid);
 
 --
 -- Table structure for table 'filter_formats'
Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.137
diff -u -r1.137 updates.inc
--- database/updates.inc	23 Sep 2005 13:13:12 -0000	1.137
+++ database/updates.inc	23 Sep 2005 23:55:59 -0000
@@ -65,7 +65,8 @@
   "2005-08-15" => "update_145",
   "2005-08-25" => "update_146",
   "2005-09-07" => "update_147",
-  "2005-09-18" => "update_148"
+  "2005-09-18" => "update_148",
+  "2005-09-23" => "update_149"
 );
 
 function update_110() {
@@ -829,6 +830,23 @@
   return $ret;
 }
 
+function update_149() {
+  $ret = array();
+
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {files} ADD cid int(10) unsigned NOT NULL default '0' AFTER vid, ADD KEY cid (cid)");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {files} ADD cid integer NOT NULL default '0'");
+      $ret[] = update_sql("CREATE INDEX files_cid_idx ON files(cid)");
+      break;
+  }
+
+  return $ret;
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
