Index: modules/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment.module,v
retrieving revision 1.369
diff -u -r1.369 comment.module
--- modules/comment.module	7 Sep 2005 20:45:53 -0000	1.369
+++ modules/comment.module	29 Sep 2005 16:15:01 -0000
@@ -92,6 +92,7 @@
   $items = array();
 
   if ($may_cache) {
+    $items[] = array('path' => 'comment/control', 'title' => t('comment control'), 'callback' => 'comment_control', 'access' => user_access('access comments'), 'type' => MENU_CALLBACK);
     $access = user_access('administer comments');
     $items[] = array('path' => 'admin/comment', 'title' => t('comments'),
       'callback' => 'comment_admin_overview', 'access' => $access);
@@ -124,8 +125,6 @@
       'callback' => 'comment_vote_settings', 'access' => $access,'type' => MENU_LOCAL_TASK);
 
     $access = user_access('post comments');
-    $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
-      'callback' => 'comment_save_settings', 'access' => 1, 'type' => MENU_CALLBACK);
     $items[] = array('path' => 'comment/edit', 'title' => t('edit comment'),
       'callback' => 'comment_edit', 'access' => $access, 'type' => MENU_CALLBACK);
     $items[] = array('path' => 'comment/delete', 'title' => t('delete comment'),
@@ -144,6 +143,20 @@
         'callback' => 'node_page',
         'type' => MENU_CALLBACK);
     }
+    if (((arg(0) == 'node') || (arg(0) == 'comment')) && is_numeric(arg(1))) {
+      $node = node_load(array('nid' => arg(1)));
+      if (variable_get('comment_task_'. $node->type, FALSE)) {
+        $title = t('discuss');
+        $title .= " ($node->comment_count)";
+        $items[] = array('path' => ('node/'. arg(1) .'/discuss'), 'title' => $title, 'weight' => 2,
+          'callback' => 'comment_task', 'callback arguments' => array(arg(1), arg(3)), 'type' => MENU_LOCAL_TASK,
+          'access' => node_access('view', $node) );
+      }
+    }
+    if (arg(0) == 'comment' && is_numeric(arg(1))) {
+      $node = node_load(array('nid' => arg(1)));
+      $_GET['q'] = variable_get('comment_task_'. $node->type, FALSE) ? 'node/'. arg(1) .'/discuss': 'node/'. arg(1);
+    }
   }
 
   return $items;
@@ -242,7 +255,9 @@
 function comment_nodeapi(&$node, $op, $arg = 0) {
   switch ($op) {
     case 'settings':
-      return form_radios(t('Default comment setting'), 'comment_'. $node->type, variable_get('comment_'. $node->type, 2), array(t('Disabled'), t('Read only'), t('Read/Write')), t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
+      $output = form_radios(t('Default comment setting'), 'comment_'. $node->type, variable_get('comment_'. $node->type, 2), array(t('Disabled'), t('Read only'), t('Read/Write')), t('Users with the <em>administer comments</em> permission will be able to override this setting.'));
+      $output .= form_checkbox(t('Show comments on own tab'), 'comment_task_'. $node->type, 1, variable_get('comment_task_'. $node->type, FALSE), t('If unchecked, comments will be shown directly beneath the corresponding post, instead of in a tab called %discuss', array('%discuss' => theme('placeholder', t('discuss')))));
+      return $output;
 
     case 'fields':
       return array('comment');
@@ -388,7 +403,7 @@
       return comment_preview($edit);
     }
     else {
-      drupal_goto("node/$nid#comment-$cid");
+      drupal_goto("comment/$nid#comment-$cid");
     }
   }
   else if ($_POST['op'] == t('Preview comment')) {
@@ -751,39 +766,37 @@
   return $links;
 }
 
+function comment_task($nid, $cid = 0) {
+  $node = node_load(array('nid' => $nid));
+  $links[] = l(t('add new comment'), "comment/reply/$nid#comment-form");
+  $links[] = l(t('view post'), "node/$nid");
+  $output = theme('item_list', $links);
+  if ($node->comment_count) {
+    $output .= comment_render($node, $cid);
+  }
+  else {
+    drupal_set_message(t('there are no comments for this post.'));
+  }
+  drupal_set_title($node->title);
+  return $output;
+}
+
 function comment_render($node, $cid = 0) {
   global $user;
 
-  $mode = $_GET['mode'];
-  $order = $_GET['order'];
-  $threshold = $_GET['threshold'];
-  $comments_per_page = $_GET['comments_per_page'];
-  $comment_page = $_GET['comment_page'];
-
   $output = '';
-
+  $nid = $node->nid;
+  if (empty($nid)) {
+    $nid = 0;
+  }
   if (user_access('access comments')) {
-    // Pre-process variables.
-    $nid = $node->nid;
-    if (empty($nid)) {
-      $nid = 0;
-    }
 
-    if (empty($mode)) {
-      $mode = $user->mode ? $user->mode : ($_SESSION['comment_mode'] ? $_SESSION['comment_mode'] : variable_get('comment_default_mode', 4));
-    }
-
-    if (empty($order)) {
-      $order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', 1));
-    }
-    if (empty($threshold)) {
-      $threshold = $user->threshold ? $user->threshold : ($_SESSION['comment_threshold'] ? $_SESSION['comment_threshold'] : variable_get('comment_default_threshold', 0));
-    }
+    $comment_page = $_GET['comment_page'];
+    $mode = $user->mode ? $user->mode : ($_SESSION['comment_mode'] ? $_SESSION['comment_mode'] : variable_get('comment_default_mode', 4));
+    $order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', 1));
+    $threshold = $user->threshold ? $user->threshold : ($_SESSION['comment_threshold'] ? $_SESSION['comment_threshold'] : variable_get('comment_default_threshold', 0));
     $threshold_min = db_result(db_query('SELECT minimum FROM {moderation_filters} WHERE fid = %d', $threshold));
-
-    if (empty($comments_per_page)) {
-      $comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION['comment_comments_per_page'] ? $_SESSION['comment_comments_per_page'] : variable_get('comment_default_per_page', '50'));
-    }
+    $comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION['comment_comments_per_page'] ? $_SESSION['comment_comments_per_page'] : variable_get('comment_default_per_page', '50'));
 
     $output .= "<a id=\"comment\"></a>\n";
 
@@ -902,7 +915,7 @@
       // Start a form, for use with comment control and moderation.
       $result = pager_query($query, $comments_per_page, 0, "SELECT COUNT(*) FROM {comments} WHERE status = %d AND nid = %d", $nid, COMMENT_PUBLISHED);
       if (db_num_rows($result) && (variable_get('comment_controls', 3) == 0 || variable_get('comment_controls', 3) == 2)) {
-        $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
+        $output .= '<form method="post" action="'. url('comment/control', drupal_get_destination()) ."\"><div>\n";
         $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
         $output .= form_hidden('nid', $nid);
         $output .= '</div></form>';
@@ -943,17 +956,17 @@
       $output .= '</div></form>';
 
       if (db_num_rows($result) && (variable_get('comment_controls', 3) == 1 || variable_get('comment_controls', 3) == 2)) {
-        $output .= '<form method="post" action="'. url('comment') ."\"><div>\n";
+        $output .= '<form method="post" action="'. url('comment/control', drupal_get_destination()) ."\"><div>\n";
         $output .= theme('comment_controls', $threshold, $mode, $order, $comments_per_page);
         $output .= form_hidden('nid', $nid);
         $output .= '</div></form>';
       }
     }
 
-    // If enabled, show new comment form.
-    if (user_access('post comments') && node_comment_mode($nid) == 2 && variable_get('comment_form_location', 0)) {
-      $output .= theme('comment_form', array('nid' => $nid), t('Post new comment'));
-    }
+  }
+  // If enabled, show new comment form.
+  if (user_access('post comments') && node_comment_mode($nid) == 2 && variable_get('comment_form_location', 0)) {
+    $output .= theme('comment_form', array('nid' => $nid), t('Post new comment'));
   }
   return $output;
 }
@@ -1019,7 +1032,7 @@
   while ($comment = db_fetch_object($result)) {
     $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
     $rows[] = array(
-        l($comment->subject, "node/$comment->nid", array('title' => truncate_utf8($comment->comment, 128)), NULL, "comment-$comment->cid") ." ". theme('mark', node_mark($comment->nid, $comment->timestamp)),
+        l($comment->subject, "comment/$comment->nid", array('title' => truncate_utf8($comment->comment, 128)), NULL, "comment-$comment->cid") ." ". theme('mark', node_mark($comment->nid, $comment->timestamp)),
         theme('username', $comment),
         ($comment->status == COMMENT_PUBLISHED ? t('Published') : t('Not published')),
         format_date($comment->timestamp, 'small'),
@@ -1280,7 +1293,7 @@
   }
 }
 
-function comment_save_settings() {
+function comment_control() {
   global $user;
 
   $edit = $_POST['edit'];
@@ -1302,7 +1315,7 @@
     $_SESSION['comment_comments_per_page'] = $comments_per_page;
   }
 
-  drupal_goto('node/'. $edit['nid'] .'#comment');
+  drupal_goto('comment/'. $edit['nid']);
 }
 
 function comment_num_all($nid) {
@@ -1529,7 +1542,7 @@
 
 function theme_comment($comment, $links = 0) {
   $output  = "<div class=\"comment\">\n";
-  $output .= '<div class="subject">'. l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
+  $output .= '<div class="subject">'. l($comment->subject, "comment/$comment->nid", NULL, NULL, "comment-$comment->cid") . ' ' . theme('mark', $comment->new) ."</div>\n";
   $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";
Index: modules/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node.module,v
retrieving revision 1.527
diff -u -r1.527 node.module
--- modules/node.module	2 Sep 2005 02:11:41 -0000	1.527
+++ modules/node.module	29 Sep 2005 16:15:03 -0000
@@ -573,7 +573,7 @@
 function node_show($node, $cid) {
   $output = node_view($node, FALSE, TRUE);
 
-  if (function_exists('comment_render') && $node->comment) {
+  if (function_exists('comment_render') && $node->comment && !variable_get('comment_task_'. $node->type, FALSE)) {
     $output .= comment_render($node, $cid);
   }
 
