Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.347.2.6
diff -u -r1.347.2.6 comment.module
--- modules/comment.module	25 Jul 2005 09:41:20 -0000	1.347.2.6
+++ modules/comment.module	23 Sep 2005 23:55:04 -0000
@@ -383,7 +383,7 @@
     print theme('page', comment_post($edit));
     return;
   }
-  else if ($_POST['op'] == t('Preview comment')) {
+  else if ($_POST['op'] == t('Preview comment') || $_POST['fileop'] == t('Attach')) {
     $edit = $_POST['edit'];
     $edit = comment_validate_form($edit);
     drupal_set_title(t('Preview comment'));
@@ -683,7 +683,8 @@
   if (node_comment_mode($comment->nid) == 2) {
     if (user_access('administer comments') && user_access('access administration pages')) {
       $links[] = l(t('delete'), "admin/comment/delete/$comment->cid");
-      $links[] = l(t('edit'), "admin/comment/edit/$comment->cid");
+      $links[] = l(t('edit'),
+        (comment_access('edit', $comment) ? '' : 'admin/') . "comment/edit/$comment->cid");
       $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
     }
     else if (user_access('post comments')) {
@@ -750,6 +751,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)));
       }
 
@@ -868,6 +872,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);
@@ -922,11 +929,15 @@
     drupal_goto('admin/comment');
   }
 
-  // If we're not saving our changes above, we're editing it.
-  $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid);
-  $comment = db_fetch_object($result);
-  $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
-  $comment = drupal_unpack($comment);
+  if ($_POST['fileop'] == t('Attach')) {
+    $comment = array2object($_POST['edit']);
+  } else {
+    // If we're not saving our changes above, we're editing it.
+    $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d', $cid);
+    $comment = db_fetch_object($result);
+    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
+    $comment = drupal_unpack($comment);
+  }
 
   if ($comment) {
     if (!$comment->uid) {
@@ -938,15 +949,22 @@
     else {
       // Otherwise, just display the author's name.
       $form .= form_item(t('Author'), format_name($comment));
+      $form .= form_hidden('uid', $comment->uid);
+      $form .= form_hidden('name', $comment->name);
+      $form .= form_hidden('mail', $comment->mail);
+      $form .= form_hidden('homepage', $comment->homepage);
     }
     $form .= form_textfield(t('Subject'), 'subject', $comment->subject, 70, 128);
     $form .= form_textarea(t('Comment'), 'comment', $comment->comment, 70, 15, '');
+    $form .= implode('', module_invoke_all('comment', 'form post', object2array($comment)));
     $form .= filter_form('format', $comment->format);
     $form .= form_radios(t('Status'), 'status', $comment->status, array(t('Published'), t('Not published')));
     $form .= form_hidden('nid', $comment->nid);
     $form .= form_hidden('cid', $comment->cid);
     $form .= form_submit(t('Submit'));
-    print theme('page', form($form));
+
+    $param = module_invoke_all('comment', 'form param', NULL);
+    print theme('page', form($form, 'post', NULL, $param));
   }
 }
 
@@ -1408,6 +1426,8 @@
   // comment field:
   $form .= form_textarea(t('Comment'), 'comment', $edit['comment'] ? $edit['comment'] : $user->signature, 70, 10, '', NULL, TRUE);
 
+  $form .= implode('', module_invoke_all('comment', 'form post', $edit));
+
   // format selector
   $form .= filter_form('format', $edit['format']);
 
@@ -1425,7 +1445,8 @@
     $form .= form_submit(t('Post comment'));
   }
 
-  return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid'])));
+  $param = module_invoke_all('comment', 'form param', NULL);
+  return theme('box', $title, form($form, 'post', url('comment/reply/'. $edit['nid']), $param));
 }
 
 function theme_comment_preview($comment, $links = '', $visible = 1) {
@@ -1545,6 +1566,7 @@
   $output .= '<div class="moderation">'. $comment->moderation ."</div>\n";
   $output .= '<div class="credit">'. t('by %a on %b', array('%a' => format_name($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.31.2.5
diff -u -r1.31.2.5 upload.module
--- modules/upload.module	25 May 2005 04:28:59 -0000	1.31.2.5
+++ modules/upload.module	23 Sep 2005 23:55:04 -0000
@@ -85,6 +85,7 @@
 
   $group .= form_textfield(t('Maximum total file size'), 'upload_maxsize_total', variable_get('upload_maxsize_total', 0), 10, 10, t('The maximum size of a file a user can upload in megabytes. Enter 0 for unlimited.'));
   $group .= form_textfield(t('Maximum resolution for uploaded images'), 'upload_max_resolution', variable_get('upload_max_resolution', 0), 10, 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);
 
@@ -138,7 +139,7 @@
       break;
 
     case 'validate':
-      $node->files = upload_load($node);
+      list ($node->files) = upload_load($node);
 
       // Double check existing files:
       if (is_array($node->list)) {
@@ -233,7 +234,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;
 
@@ -334,8 +338,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, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
-                 $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
+        db_query("INSERT INTO {files} (fid, nid, cid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)",
+                 $fid, $node->nid, isset($node->cid) ? $node->cid : 0, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
       }
     }
     else {
@@ -353,11 +357,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) {
@@ -387,16 +398,25 @@
 }
 
 function upload_load($node) {
-  $files = array();
+  $files = $comment_files = array();
 
-  if ($node->nid) {
+  if ($node->nid && !$node->is_comment) {
     $result = db_query("SELECT * FROM {files} WHERE nid = %d", $node->nid);
     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);
 }
 
 /**
@@ -420,4 +440,38 @@
   return $file;
 }
 
+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.174.2.2
diff -u -r1.174.2.2 database.mysql
--- database/database.mysql	3 May 2005 05:20:07 -0000	1.174.2.2
+++ database/database.mysql	23 Sep 2005 23:55:04 -0000
@@ -232,12 +232,15 @@
 CREATE TABLE files (
   fid int(10) unsigned NOT NULL default '0',
   nid 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',
-  PRIMARY KEY (fid)
+  PRIMARY KEY (fid),
+  KEY nid (nid),
+  KEY cid (cid)
 ) TYPE=MyISAM;
 
 --
Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.110.2.4
diff -u -r1.110.2.4 database.pgsql
--- database/database.pgsql	27 Jun 2005 04:45:50 -0000	1.110.2.4
+++ database/database.pgsql	23 Sep 2005 23:55:04 -0000
@@ -228,6 +228,7 @@
 CREATE TABLE files (
   fid SERIAL,
   nid 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 '',
@@ -235,6 +236,8 @@
   list smallint NOT NULL default '0',
   PRIMARY KEY  (fid)
 );
+CREATE INDEX files_nid_idx ON files(nid);
+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.100.2.5
diff -u -r1.100.2.5 updates.inc
--- database/updates.inc	7 May 2005 08:36:24 -0000	1.100.2.5
+++ database/updates.inc	23 Sep 2005 23:55:04 -0000
@@ -107,7 +107,8 @@
   "2005-03-21" => "update_128",
   "2005-04-14" => "update_129",
   "2005-05-06" => "update_130",
-  "2005-05-07" => "update_131"
+  "2005-05-07" => "update_131",
+  "2005-09-23: first update since Drupal 4.6.0 release" => "update_132"
 );
 
 function update_32() {
@@ -2393,6 +2394,20 @@
   return $ret;
 }
 
+function update_132() {
+  $ret = array();
+
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {files} ADD cid int(10) unsigned NOT NULL default '0' AFTER nid, ADD KEY nid (nid), ADD KEY cid (cid)");
+  elseif ($GLOBALS['db_type'] == 'pgsql') {
+    $ret[] = update_sql("ALTER TABLE {files} ADD cid integer NOT NULL default '0'");
+    $ret[] = update_sql("CREATE INDEX files_nid_idx ON files(nid)");
+    $ret[] = update_sql("CREATE INDEX files_cid_idx ON files(cid)");
+  }
+
+  return $ret;
+}
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
