diff -urp --strip-trailing-cr ../drupal-6.x-dev/modules/comment/comment.module ./modules/comment/comment.module --- ../drupal-6.x-dev/modules/comment/comment.module 2007-10-12 12:41:47.000000000 +0200 +++ ./modules/comment/comment.module 2007-10-13 00:51:11.000000000 +0200 @@ -376,7 +376,7 @@ function comment_new_page_count($num_com function theme_comment_block() { $items = array(); foreach (comment_get_recent() as $comment) { - $items[] = l($comment->subject, 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))); + $items[] = l($comment->subject, 'node/'. $comment->nid, array('query' => 'cid='. $comment->cid, 'fragment' => 'comment-'. $comment->cid)) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))); } if ($items) { return theme('item_list', $items); @@ -774,7 +774,7 @@ function comment_save($edit) { comment_invoke_comment($edit, 'update'); // Add an entry to the watchdog log. - watchdog('content', 'Comment: updated %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid']))); + watchdog('content', 'Comment: updated %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('query' => 'cid='. $edit['cid'], 'fragment' => 'comment-'. $edit['cid']))); } else { // Add the comment to database. @@ -835,7 +835,7 @@ function comment_save($edit) { comment_invoke_comment($edit, 'insert'); // Add an entry to the watchdog log. - watchdog('content', 'Comment: added %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid']))); + watchdog('content', 'Comment: added %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('query' => 'cid='. $edit['cid'], 'fragment' => 'comment-'. $edit['cid']))); } _comment_update_node_statistics($edit['nid']); @@ -873,7 +873,8 @@ function comment_links($comment, $return $links['comment_parent'] = array( 'title' => t('parent'), 'href' => comment_node_url(), - 'fragment' => "comment-$comment->cid" + 'fragment' => "comment-$comment->cid", + 'query' => 'cid='. $comment->cid, ); } @@ -1050,14 +1051,42 @@ function comment_render($node, $cid = 0) $query_count = db_rewrite_sql($query_count, 'c', 'cid'); // Start a form, for use with comment control. - $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args); + + // The argument 'cid' means a page on which the comment #cid is. If set, + // fetch pages until the comment is found, otherwise just get one page. + $cid = (isset($_GET['cid']) && is_numeric($_GET['cid'])) ? $_GET['cid'] : FALSE; + $cids = array(); + $page = 0; + while ((!$cid && empty($cids)) || ($cid && !isset($cids[$cid]))) { + if ($page) { + // Inject fake pager if searching beyond first page. Only happens if 'cid' specified. + $_GET['page'] = $page; + } + $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args); + $results = array(); + $stop = FALSE; + while ($comment = db_fetch_object($result)) { + $results[] = $comment; + if (isset($cids[$comment->cid])) { + // The same repeats - means wrong 'cid' specified (doesn't exist), pager returns + // last page again after the end. So finish page fetching, then exit. + $stop = TRUE; + } + $cids[$comment->cid] = TRUE; + } + $page++; + if ($stop || empty($results)) { + // Requested comment not found, or no comments at all + break; + } + } $divs = 0; $last_depth = 0; $num_rows = FALSE; $comments = ''; drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css'); - while ($comment = db_fetch_object($result)) { + foreach ($results as $comment) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->depth = count(explode('.', $comment->thread)) - 1; @@ -1102,7 +1131,9 @@ function comment_render($node, $cid = 0) for ($i = 0; $i < $divs; $i++) { $output .= ''; } - $output .= theme('pager', NULL, $comments_per_page, 0); + $pager = theme('pager', NULL, $comments_per_page, 0); + // Bit of a hack, to work around impossibility to remove query arguments from pager links + $output .= ($cid) ? str_replace("&cid=$cid", '', $pager) : $pager; if ($num_rows && ($comment_controls == COMMENT_CONTROLS_BELOW || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) { $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page); @@ -1240,7 +1271,7 @@ function comment_admin_overview($type = while ($comment = db_fetch_object($result)) { $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), 'fragment' => 'comment-'. $comment->cid))); + $form['subject'][$comment->cid] = array('#value' => l($comment->subject, 'node/'. $comment->nid, array('title' => truncate_utf8($comment->comment, 128), 'query' => 'cid='. $comment->cid, 'fragment' => '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('query' => $destination))); @@ -1279,7 +1310,7 @@ function comment_admin_overview_submit($ // Allow modules to respond to the updating of a comment. comment_invoke_comment($comment, $form_state['values']['operation']); // Add an entry to the watchdog log. - watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid))); + watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/'. $comment->nid, array('query' => 'cid='. $comment->cid, 'fragment' => 'comment-'. $comment->cid))); } } cache_clear_all(); @@ -1755,7 +1786,7 @@ function _comment_form_submit(&$comment_ function comment_form_submit($form, &$form_state) { _comment_form_submit($form_state['values']); if ($cid = comment_save($form_state['values'])) { - $form_state['redirect'] = array('node/'. $form_state['values']['nid'], NULL, "comment-$cid"); + $form_state['redirect'] = array('node/'. $form_state['values']['nid'], "cid=$cid", "comment-$cid"); return; } } @@ -1866,7 +1897,7 @@ function template_preprocess_comment(&$v $variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : ''; $variables['signature'] = $comment->signature; $variables['submitted'] = theme('comment_submitted', $comment); - $variables['title'] = l($comment->subject, $_GET['q'], array('fragment' => "comment-$comment->cid")); + $variables['title'] = l($comment->subject, $_GET['q'], array('query' => 'cid='. $comment->cid, 'fragment' => "comment-$comment->cid")); $variables['template_files'][] = 'comment-'. $node->type; }