Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.569
diff -u -r1.569 comment.module
--- modules/comment/comment.module	25 Jul 2007 14:57:58 -0000	1.569
+++ modules/comment/comment.module	30 Jul 2007 17:42:10 -0000
@@ -317,6 +317,50 @@
 }
 
 /**
+ * Calculate page number for first new comment.
+ */
+
+function comment_new_page_count($num_comments, $new_replies, $nid) {
+  $comments_per_page = _comment_get_display_setting('comments_per_page');
+  $mode = _comment_get_display_setting('mode');
+  $order = _comment_get_display_setting('sort');
+  $pagenum = NULL;
+  if ($num_comments <= $comments_per_page || ($mode<3 && $order == 1)) {
+    //Only one page of comments or flat forum and newest first.
+    //First new comment will always be on first page.
+    $pageno = 0;
+    } 
+    else {
+      if ($mode < 3){ 
+        //Flat comments and oldest first
+        $count = $num_comments - $new_replies;
+      } 
+      else {
+        //Threaded comments. See the documentation for comment_render().
+        if ($order == 1) { 
+          //Newest first: find the last thread with new comment
+          $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY thread DESC LIMIT 1', $nid, $new_replies);
+          $thread = db_result($result);
+          $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND thread > '" . $thread . "'", $nid);
+        } 
+        else { 
+          //Oldest first: find the first thread with new comment
+          $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d  AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) LIMIT 1', $nid, $new_replies);  
+          $thread = substr(db_result($result), 0, -1);
+          $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '" . $thread . "'", $nid);
+        }
+        $count = db_result($result_count);
+      }
+      $pageno =  $count / $comments_per_page;
+    }
+    if ($pageno >= 1) {
+      $pagenum = "page=" . intval($pageno);
+    }
+  return $pagenum;
+}
+
+
+/**
  * Returns a formatted list of recent comments to be displayed in the comment
  * block.
  *
@@ -360,6 +404,7 @@
             $links['comment_new_comments'] = array(
               'title' => format_plural($new, '1 new comment', '@count new comments'),
               'href' => "node/$node->nid",
+              'query' => comment_new_page_count($all, $new, $node->nid),
               'attributes' => array('title' => t('Jump to the first new comment of this posting.')),
               'fragment' => 'new'
             );
Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.411
diff -u -r1.411 forum.module
--- modules/forum/forum.module	26 Jul 2007 06:48:03 -0000	1.411
+++ modules/forum/forum.module	30 Jul 2007 17:49:12 -0000
@@ -763,7 +763,7 @@
         $variables['topics'][$id]->title = l($topic->title, "node/$topic->nid");
         if ($topic->new_replies) {
           $variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new', '@count new');
-          $variables['topics'][$id]->new_url = url("node/$topic->nid", array('fragment' => 'new'));
+          $variables['topics'][$id]->new_url = url(node/$topic->nid", NULL, comment_new_page_count($topic->num_comments, $topic->new_replies, $topic->nid), array('fragment' => 'new'));
         }
         $variables['topics'][$id]->created = theme('forum_submitted', $topic);
         $variables['topics'][$id]->last_reply = theme('forum_submitted', $topic->last_reply);
Index: modules/tracker/tracker.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker/tracker.module,v
retrieving revision 1.150
diff -u -r1.150 tracker.module
--- modules/tracker/tracker.module	4 Jul 2007 10:54:26 -0000	1.150
+++ modules/tracker/tracker.module	30 Jul 2007 17:43:48 -0000
@@ -106,7 +106,7 @@
 
       if ($new = comment_num_new($node->nid)) {
         $comments .= '<br />';
-        $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", array('fragment' => 'new'));
+        $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, comment_new_page_count($node->comment_count, $new, $node->nid), 'new');
       }
     }
 
