Index: tracdiscussion/api.py
===================================================================
--- tracdiscussion/api.py	(Revision 6010)
+++ tracdiscussion/api.py	(Arbeitskopie)
@@ -7,7 +7,7 @@
 from trac.core import *
 from trac.mimeview import Context
 from trac.perm import PermissionError
-from trac.web.chrome import add_stylesheet, add_script, add_ctxtnav
+from trac.web.chrome import add_link, add_stylesheet, add_script, add_ctxtnav
 from trac.web.href import Href
 from trac.wiki.formatter import format_to_html, format_to_oneliner
 from trac.util.datefmt import to_timestamp, to_datetime, utc, \
@@ -19,6 +19,7 @@
 from genshi.input import HTML
 from genshi.core import Markup
 from genshi.filters import Transformer
+from trac.util.presentation import Paginator
 
 class IDiscussionFilter(Interface):
     """Extension point interface for components that want to filter discussion
@@ -551,14 +552,19 @@
                   datetime.now(utc))
 
                 # Get form values
-                order = context.req.args.get('order') or 'id'
-                desc = context.req.args.get('desc')
+                if not context.req.args.get('order'):
+                  order = 'lastreply'
+                  desc = 1
+                else:
+                  order = context.req.args.get('order') or 'lastreply'
+                  desc = context.req.args.get('desc')
+                page = context.req.args.get('page') or 1
 
                 # Display topics.
                 context.data['order'] = order
                 context.data['desc'] = desc
                 context.data['topics'] = self.get_topics(context,
-                  context.forum['id'], order, desc)
+                  context.forum['id'], order, desc, int(page))
 
             elif action == 'topic-add':
                 context.req.perm.assert_permission('DISCUSSION_APPEND')
@@ -956,11 +962,13 @@
 
         return forums
 
-    def get_topics(self, context, forum_id, order_by = 'time', desc = False):
+    def get_topics(self, context, forum_id, order_by = 'time', desc = False, cur_page = 1):
 
         def _get_new_replies_count(context, topic_id):
             time = int(context.visited_topics.has_key(topic_id) and
               (context.visited_topics[topic_id] or 0))
+            if time == 0:
+              return 0
             sql = "SELECT COUNT(id) FROM message m WHERE m.topic = %s AND m.time > %s"
 
             self.env.log.debug(sql % (topic_id, time))
@@ -969,12 +977,15 @@
                return int(row[0])
             return 0
 
+        req = context.req 
         if not order_by in ('replies', 'lastreply',):
             order_by = 't.' + order_by
-        columns = ('id', 'forum', 'time', 'subject', 'body', 'author',
+        elif order_by in ( 'lastreply',):
+            order_by = 'lastreply'
+        columns = ('id', 'forum', 'time', 'subject', 'author',
           'replies', 'lastreply')
-        sql = "SELECT t.id, t.forum, t.time, t.subject, t.body, t.author," \
-          " m.replies, m.lastreply FROM topic t LEFT JOIN (SELECT COUNT(id)" \
+        sql = "SELECT t.id, t.forum, t.time, t.subject, t.author," \
+          " m.replies, m.lastreply, CASE WHEN m.lastreply IS NULL THEN t.time ELSE m.lastreply END lastreply FROM topic t LEFT JOIN (SELECT COUNT(id)" \
           " AS replies, MAX(time) AS lastreply, topic FROM message GROUP BY" \
           " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \
           + order_by + (" ASC", " DESC")[bool(desc)]
@@ -987,11 +998,36 @@
             row = dict(zip(columns, row))
             topics.append(row)
 
+        self.RESULTS_PER_PAGE = 30
+        my_href = context.req.href.discussion('forum', forum_id)
+
+        results = Paginator(topics, cur_page - 1, self.RESULTS_PER_PAGE)
+        for page in results.get_shown_pages():
+          self.env.log.debug('Pages: %i' % (page))
+        results.current_page = {'href': None, 'class': 'current', 'string': str(results.page + 1), 'title':None}
+
+        pagedata = []
+        shown_pages = results.get_shown_pages(21)
+        for shown_page in shown_pages:
+          page_href = my_href + ('?page=%i' % (shown_page))
+          pagedata.append([page_href, None, str(shown_page), 'page ' + str(shown_page)])
+        fields = ['href', 'class', 'string', 'title']
+        results.shown_pages = [dict(zip(fields, p)) for p in pagedata]
+
+        self.env.log.debug('Pages: %i' % (results.num_items))
+        if results.has_next_page:
+          page_href = my_href + ('?page=%i' % (results.page+2))
+          add_link(req, 'next', page_href, 'Next Page')
+
+        if results.has_previous_page:
+          page_href = my_href + ('?page=%i' % (results.page))
+          add_link(req, 'prev', page_href, 'Prev Page')
+
         # Compute count of new replies.
-        for topic in topics:
+        for topic in results.items:
             topic['new_replies'] = _get_new_replies_count(context, topic['id'])
 
-        return topics
+        return results
 
     def get_messages(self, context, topic_id, order_by = 'time', desc = False):
         order_by = 'm.' + order_by
Index: tracdiscussion/htdocs/css/discussion.css
===================================================================
--- tracdiscussion/htdocs/css/discussion.css	(Revision 6010)
+++ tracdiscussion/htdocs/css/discussion.css	(Arbeitskopie)
@@ -52,12 +52,18 @@
 }
 
 /* Topic list */
-.topic-list td.id, .topic-list td.author, .topic-list td.lastreply,
+.topic-list td.id, .topic-list td.author, 
 .topic-list td.founded, .topic-list td.time, .topic-list td.replies,
 .topic-list td.new_replies
 {
   text-align: center;
 }
+.topic-list div.subject {
+  font-weight: bold;
+}
+.topic-list div.lastreply {
+  width: 130px;
+}
 
 .topic-list td.id
 {
Index: tracdiscussion/templates/topic-list.html
===================================================================
--- tracdiscussion/templates/topic-list.html	(Revision 6010)
+++ tracdiscussion/templates/topic-list.html	(Arbeitskopie)
@@ -26,70 +26,51 @@
           <table py:when="len(discussion.topics)" class="listing">
             <thead>
               <tr>
-                ${sortable_th(discussion.order, discussion.desc, 'id', 'ID', href.discussion('forum', discussion.forum.id))}
                 ${sortable_th(discussion.order, discussion.desc, 'subject', 'Subject', href.discussion('forum', discussion.forum.id))}
-                ${sortable_th(discussion.order, discussion.desc, 'author', 'Author', href.discussion('forum', discussion.forum.id))}
-                ${sortable_th(discussion.order, discussion.desc, 'lastreply', 'Last Reply', href.discussion('forum', discussion.forum.id))}
-                ${sortable_th(discussion.order, discussion.desc, 'time', 'Founded', href.discussion('forum', discussion.forum.id))}
                 ${sortable_th(discussion.order, discussion.desc, 'replies', 'Replies', href.discussion('forum', discussion.forum.id))}
-                <th class="new_replies">New Replies</th>
+                ${sortable_th(discussion.order, discussion.desc, 'lastreply', 'Last Reply', href.discussion('forum', discussion.forum.id))}
+                <th class="new_replies">New</th>
               </tr>
+              <tr>
+                ${sortable_th(discussion.order, discussion.desc, 'id', 'ID', href.discussion('forum', discussion.forum.id))}
+                ${sortable_th(discussion.order, discussion.desc, 'author', 'Author', href.discussion('forum', discussion.forum.id))}
+                <th class="not_used">&nbsp;</th>
+                <th class="not_used">&nbsp;</th>
+              </tr>
+
             </thead>
             <tbody>
-              <tr py:for="line, topic in enumerate(discussion.topics)" class="${line % 2 and 'even' or 'odd'}">
-                <td class="id">
-                  <div class="id">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>${topic.id}</span>
-                    </a>
-                  </div>
-                </td>
+              <tr py:for="line, topic in enumerate(discussion.topics.items)" class="${line % 2 and 'even' or 'odd'}">
                 <td class="subject">
                   <div class="subject">
                     <a href="${href.discussion('topic', topic.id)}">
                       <span>${format_to_oneliner_no_links(discussion.env, context, topic.subject) or '&nbsp;'}</span>
-                    </a>
+                    </a> (<span>${topic.id}</span>)
+                  </div> 
+                  <div class="author">
+                    <span>by; ${format_to_oneliner_no_links(discussion.env, context, topic.author) or '&nbsp;'}</span>
+                    &raquo;
+                    <span>
+                      ${format_datetime(topic.time)} (${pretty_timedelta(topic.time) + ' ago'})
+                    </span>
                   </div>
                 </td>
-                <td class="author">
-                  <div class="author">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>${format_to_oneliner_no_links(discussion.env, context, topic.author) or '&nbsp;'}</span>
-                    </a>
+                <td class="replies">
+                  <div class="replies">
+                    <span>${topic.replies or '0'}</span>
                   </div>
                 </td>
                 <td class="lastreply">
                   <div class="lastreply">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>
-                        ${topic.lastreply and format_datetime(topic.lastreply) or 'no replies'}<br/>
-                        ${topic.lastreply and pretty_timedelta(topic.lastreply) + ' ago' or ''}
-                      </span>
-                    </a>
+                    <span>
+                      ${topic.lastreply and format_datetime(topic.lastreply) or 'no replies'}<br/>
+                      ${topic.lastreply and pretty_timedelta(topic.lastreply) + ' ago' or ''}
+                    </span>
                   </div>
                 </td>
-                <td class="founded">
-                  <div class="founded">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>
-                        ${format_datetime(topic.time)}<br/>
-                        ${pretty_timedelta(topic.time) + ' ago'}
-                      </span>
-                    </a>
-                  </div>
-                </td>
-                <td class="replies">
-                  <div class="replies">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>${topic.replies or '0'}</span>
-                    </a>
-                  </div>
-                </td>
                 <td class="new_replies">
                   <div class="new_replies">
-                    <a href="${href.discussion('topic', topic.id)}">
-                      <span>${topic.new_replies or '0'}</span>
-                    </a>
+                    <span>${topic.new_replies or '0'}</span>
                   </div>
                 </td>
               </tr>
@@ -97,6 +78,7 @@
           </table>
           <p py:otherwise="" class="help">There are no topics created in this forum.</p>
         </py:choose>
+        <xi:include py:with="paginator = discussion.topics" href="page_index.html" />
 
         <div class="buttons">
           <form py:if="'DISCUSSION_APPEND' in perm" method="post" action="${href.discussion('forum', discussion.forum.id)}">
