Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.242
diff -u -r1.242 comment.module
--- modules/comment.module	20 May 2004 10:23:52 -0000	1.242
+++ modules/comment.module	23 May 2004 19:15:45 -0000
@@ -166,6 +166,7 @@
   }
 
 }
+
 function comment_node_url() {
   return arg(0) ."/". arg(1) ."/". arg(2);
 }
@@ -494,6 +495,8 @@
   if ($status == 1) {
     return array(t("Comment queued"), t("Your comment has been queued for moderation by site administrators and will be published after approval."));
   }
+
+  return $edit["cid"];
 }
 
 function comment_links($comment, $return = 1) {
@@ -706,6 +709,13 @@
       $output .= "<form method=\"post\" action=\"". url("comment") ."\"><div>\n";
       $output .= form_hidden("nid", $nid);
 
+      // determine the type of this node for comment redirects.
+      // unlike the "determine redirect" code in this file, we don't
+      // check for the "comment" node type, since that check is only 
+      // really important when nodes have no existing comments.
+      $type = $type ? $type : arg(0);
+      $output .= form_hidden("type", $type);
+
       while ($comment = db_fetch_object($result)) {
         $comment = drupal_unpack($comment);
         $comment->depth = count(explode(".", $comment->thread)) - 1;
@@ -861,7 +871,7 @@
     case t("Moderate comments"):
     case t("Moderate comment"):
       comment_moderate($edit);
-      drupal_goto(comment_node_url());
+      drupal_goto("$edit[type]/view/$edit[nid]");
       break;
     case "reply":
       print theme("page", comment_reply(check_query(arg(3)), check_query(arg(2))), t("Add new comment"));
@@ -870,12 +880,12 @@
       print theme("page", comment_preview($edit), t("Preview comment"));
       break;
     case t("Post comment"):
-      list($error_title, $error_body) = comment_post($edit);
-      if ($error_body) {
-        print theme("page", $error_body, $error_title);
+      $return = comment_post($edit);
+      if (is_array($return) && $return[1]) {
+        print theme("page", $return[1], $return[0]);
       }
       else {
-        drupal_goto(comment_node_url());
+        drupal_goto("$edit[type]/view/$edit[nid]", NULL, "comment-$return");
       }
       break;
     case t("Save settings"):
@@ -885,7 +895,7 @@
       $comments_per_page = $_POST["comments_per_page"];
 
       comment_save_settings(check_query($mode), check_query($order), check_query($threshold), check_query($comments_per_page));
-      drupal_goto(comment_node_url());
+      drupal_goto("$edit[type]/view/$edit[nid]");
       break;
   }
 }
@@ -1293,6 +1303,16 @@
   $form .= form_hidden("pid", $edit["pid"]);
   $form .= form_hidden("nid", $edit["nid"]);
 
+  // determine the type of this node for proper redirects.
+  // not a perfect solution, see issue #7444, comments #39+.
+  $edit['type'] = $edit['type'] ? $edit['type'] : arg(0);
+
+  if ($edit['type'] == "comment") {
+    $edit['type'] = "node";
+  }
+
+  $form .= form_hidden("type", $edit['type']);
+
   if (!$edit["comment"] && variable_get("comment_preview", 1)) {
     $form .= form_submit(t("Preview comment"));
   }
@@ -1384,6 +1404,16 @@
     $output .= theme("comment_per_page_form", $comments_per_page);
     $output .= theme("comment_threshold", $threshold);
 
+    // determine the type of this node for proper redirects.
+    // not a perfect solution, see issue #7444, comments #39+.
+    $edit['type'] = $edit['type'] ? $edit['type'] : arg(0);
+
+    if ($edit['type'] == "comment") {
+      $edit['type'] = "node";
+    }
+
+    $output .= form_hidden("type", $edit['type']);
+
     $output .= " ". form_submit(t("Save settings"));
 
     $output = form_item(NULL, $output, t("Select your preferred way to display the comments and click 'Save settings' to activate your changes."));
