From 71009ea46f835813a3ba76ceef6af41d116d7a6d Mon Sep 17 00:00:00 2001
From: Garvin Hicking <mail@garv.in>
Date: Mon, 23 Oct 2006 07:32:37 +0000
Subject: [PATCH] Fix gazillion comment count bug

---
 docs/NEWS                          | 7 +++++++
 include/admin/comments.inc.php     | 3 ++-
 include/functions_comments.inc.php | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/docs/NEWS b/docs/NEWS
index e6c5d367..c65fb6c9 100644
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -1,5 +1,12 @@
 # $Id$
 
+Version 1.1 ()
+------------------------------------------------------------------------
+
+    * Fix possible integer wraparound in comment count leading to
+      a gazillion counter state. Also now show links to the entries
+      within the administration comment panel. Thanks to Julian Finn!
+
 Version 1.1-beta5 (October 18th, 2006)
 ------------------------------------------------------------------------
 
diff --git a/include/admin/comments.inc.php b/include/admin/comments.inc.php
index 324a35fb..ef0e43d4 100644
--- a/include/admin/comments.inc.php
+++ b/include/admin/comments.inc.php
@@ -311,6 +311,7 @@ foreach ($sql as $rs) {
         'referer'   => $rs['referer'],
         'url'       => $rs['url'],
         'ip'        => $rs['ip'],
+        'entry_url' => serendipity_archiveURL($rs['entry_id'], $rs['title']),
         'email'     => $rs['email'],
         'author'    => (empty($rs['author']) ? ANONYMOUS : $rs['author']),
         'entry_id'  => $rs['entry_id']
@@ -336,7 +337,7 @@ foreach ($sql as $rs) {
 ?>
 <tr>
     <td class="<?php echo $header_class; ?>"><a name="c<?php echo $comment['id'] ?>"></a>
-        <?php echo ($comment['type'] == 'NORMAL' ? COMMENT : TRACKBACK) . ' #'. $comment['id'] .', '. IN_REPLY_TO .' <strong>'. $comment['title'] .'</strong>, '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $comment['timestamp']))?>
+        <?php echo ($comment['type'] == 'NORMAL' ? COMMENT : TRACKBACK) . ' #'. $comment['id'] .', '. IN_REPLY_TO .' <strong><a href="' . $comment['entry_url'] . '">'. $comment['title'] .'</a></strong>, '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $comment['timestamp']))?>
     </td>
 </tr>
 <tr>
diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php
index bc7a29fe..ffab9c85 100644
--- a/include/functions_comments.inc.php
+++ b/include/functions_comments.inc.php
@@ -430,7 +430,7 @@ function serendipity_deleteComment($id, $entry_id, $type='comments') {
                 } else {
                     $type = 'comments';
                 }
-                serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = ". $entry_id ." $admin");
+                serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = ". $entry_id ." AND $type > 0 $admin");
             }
 
             serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = " . $id);