Index: forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum.module,v
retrieving revision 1.305
diff -u -p -r1.305 forum.module
--- forum.module	20 Jan 2006 09:04:34 -0000	1.305
+++ forum.module	24 Jan 2006 01:33:25 -0000
@@ -965,9 +965,47 @@ function theme_forum_topic_list($tid, $t
         );
       }
       else {
+        // find number of comments per page
+        $comments_per_page = $_GET['comments_per_page'];
+        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'));
+        }
+        // compute page_links
+        $page_links = ''; // clear html output
+        if ($topic->num_comments > $comments_per_page) {
+          $num_comment_pages = ceil( $topic->num_comments / $comments_per_page );
+          // five or more pages
+          if ($num_comment_pages > 4) {
+            // link to first page
+            $page_links .= l("1", "node/$topic->nid", null, 'page=0&comments_per_page='.$comments_per_page);
+            $page_links .= ' ... ';
+            $runOnce = false;
+            for ($page_number = $num_comment_pages - 2; $page_number <= $num_comment_pages; $page_number++) {
+              if ($runOnce) {
+                $page_links .= ', ';  // comma
+              }
+              $page_links .= l($page_number, "node/$topic->nid", null, 'page='.($page_number - 1).'&comments_per_page='.$comments_per_page);
+              $runOnce = true;
+            }      
+          }
+          // four or fewer pages
+          else {
+            $runOnce = false;
+            for ($page_number = 1; $page_number <= $num_comment_pages; $page_number++) {
+              if ($runOnce) {
+                $page_links .= ', ';  // comma
+              }              
+              $page_links .= l($page_number, "node/$topic->nid", null, 'page='.($page_number - 1).'&comments_per_page='.$comments_per_page);
+              $runOnce = true;
+            }           
+          }
+          $page_links = '<br /> [ Pages: '.$page_links.' ]';  // add brackets
+        }
+
+        // organize topic row
         $rows[] = array(
           array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
-          array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
+          array('data' => l($topic->title, "node/$topic->nid").$page_links, 'class' => 'topic'),
           array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(format_plural($topic->new_replies, '1 new', '%count new'), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
           array('data' => _forum_format($topic), 'class' => 'created'),
           array('data' => _forum_format($topic->last_reply), 'class' => 'last-reply')
