--- comment.module.orig 2009-01-21 23:20:48.461601217 +0200 +++ comment.module 2009-01-21 23:55:33.881392069 +0200 @@ -1159,6 +1159,57 @@ function comment_admin($type = 'new') { } } +/** + * Returns display ordinal of a comment, starting from 0. + */ +function comment_get_display_ordinal($cid) { + // Count how may comments (c) are before $cid (d) in display order. This is the 0-based display ordinal. + $query= + "SELECT count(*) FROM {comments} d INNER JOIN {comments} c ON d.nid=c.nid". + " WHERE d.cid=%d"; + $query_args=array($cid); + + if (!user_access('administer comments')) { + $query .= ' AND c.status = %d'; + $query_args[] = COMMENT_PUBLISHED; + } + + // take mode and sort orders + $mode = _comment_get_display_setting('mode'); + $order = _comment_get_display_setting('sort'); + + if ($mode == COMMENT_MODE_FLAT_EXPANDED || $mode==COMMENT_MODE_FLAT_COLLAPSED) { + // flat list + if ($order == COMMENT_ORDER_NEWEST_FIRST) { + $query.=' AND c.cid > d.cid'; + } else { + $query.=' AND c.cid < d.cid'; + } + } else { + // threaded + if ($order == COMMENT_ORDER_NEWEST_FIRST) { + $query.=' AND c.thread > d.thread'; + } else { + $query.= + ' AND SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1)) < SUBSTRING(d.thread, 1, (LENGTH(d.thread) - 1))'; + } + } + + $ord= + db_result(db_query($query, + $query_args)); + return $ord; +} + +/** + * Returns page number for comment, starting from 0. + */ +function comment_get_display_page($cid) { + $ord=comment_get_display_ordinal($cid); + $comments_per_page = _comment_get_display_setting('comments_per_page'); + return floor($ord/$comments_per_page); +} + function comment_admin_overview($type = 'new', $arg) { // build an 'Update options' form $form['options'] = array( @@ -1186,9 +1237,12 @@ function comment_admin_overview($type = // build a table listing the appropriate comments $destination = drupal_get_destination(); while ($comment = db_fetch_object($result)) { + $comment_page_num=comment_get_display_page($comment->cid); + $comment_page=$comment_page_num? 'page='.$comment_page_num : NULL; + $comments[$comment->cid] = ''; $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $form['subject'][$comment->cid] = array('#value' => l($comment->subject, 'node/'. $comment->nid, array('title' => truncate_utf8($comment->comment, 128)), NULL, 'comment-'. $comment->cid)); + $form['subject'][$comment->cid] = array('#value' => l($comment->subject, 'node/'. $comment->nid, array('title' => truncate_utf8($comment->comment, 128)), $comment_page, 'comment-'. $comment->cid)); $form['username'][$comment->cid] = array('#value' => theme('username', $comment)); $form['timestamp'][$comment->cid] = array('#value' => format_date($comment->timestamp, 'small')); $form['operations'][$comment->cid] = array('#value' => l(t('edit'), 'comment/edit/'. $comment->cid, array(), $destination));