Preserving comment hierarchy after a deletion

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Preserving comment hierarchy after a deletion

Post by Jabrwock »

On some other blogs, an admin deleting a comment results in every reply under that thread being deleted as well.

I'm trying to set up a blog similar to LiveJournal's style, where deleted comments get replaced by a (Comment deleted) entry, so the hierarchy of conversations is preserved, but the comment itself is "gone".

so if I have the following set of comments on a post:
1 "comment"
1.1 "re: comment 1"
2 "comment"
2.1 "re: comment 2"
2.1.1 "re: comment 2.1"
2.2 "re: comment 2"

And I "delete" comment 2.1, it would look like this
1 "comment"
1.1 "re: comment 1"
2 "comment"
2.1 (Comment deleted)
2.1.1 "re: comment 2.1"
2.2 "re: comment 2"

Otherwise, when comment 2.1 is deleted, 2.1.1 is moved up, and it appears as if 2.1.1 was replying to 2, not 2.1.

Does that make sense?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Preserving comment hierarchy after a deletion

Post by garvinhicking »

You could quite easily do that by patching up the serendipity_deleteComment function, if you wish.

What I've experienced so far is that people do like that a comment is properly getting deleted.

Deleting a comment that has already been commented on is IMHO considered bad moderation style and should be circumvented by either deleting the whole comment tree, or by appending an admin comment that tells the visitor that the previous comment has errors/is bad.

Adding an option on how to delete a comment would hardly fit into the interface, which is meant for one-click deleting, and not with having deletion options :-?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Re: Preserving comment hierarchy after a deletion

Post by Jabrwock »

garvinhicking wrote:What I've experienced so far is that people do like that a comment is properly getting deleted.
Same here, but it's an issue that seems to crop up when dealing with a troll who interrupts a conversation. Sometimes people reply to the troll post, but keep the conversation going rather than responding to him. I'd like to be able to just wipe the troll post itself, and keep the rest of the conversation. So I'll try messing around with deleteComment()
Deleting a comment that has already been commented on is IMHO considered bad moderation style and should be circumvented by either deleting the whole comment tree, or by appending an admin comment that tells the visitor that the previous comment has errors/is bad.
True. Currently though, the tree itself doesn't get deleted, just the offending post, and so the replies are "moved up" in the hierarchy, which can lead to confusion as to who was replying to what.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Preserving comment hierarchy after a deletion

Post by garvinhicking »

What maybe could be done and is a reasonable way through is that if a reply has child-comments, a comment will not get deleted, but the text will get replaced with "(COMMENT DELETED)".

It would be as easy as fetching "SELECT * from serendipity_comments where parent_id = XX" before deleting acomment; if there are no rows, delete the full comment, if there are rows, replace it.

Would you like to try patching it? I could then patch it into our core distribution. If you don't get along, I think I could patch it for you, but I might not be able to do so before the end of this week.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Re: Preserving comment hierarchy after a deletion

Post by Jabrwock »

garvinhicking wrote:Would you like to try patching it? I could then patch it into our core distribution. If you don't get along, I think I could patch it for you, but I might not be able to do so before the end of this week.
I'll give it a shot, and see what I can come up with.

Can I restrict it to admins/moderators? That way a user wouldn't be able to delete their own comment if a reply has been made, but an admin who tried to delete a troll comment with children would be able to (replacing it with "COMMENT DELETED").

[edit] nevermind, I just realised that users can't edit their own comments anyway unless they are a moderator...
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

diff

Post by Jabrwock »

This seems to work for me. Deleting a reply-less comment deletes it. Deleting a comment with replies replaces it with (COMMENT DELETED), so you need to delete all the children first.

Comment count decrements when comments are deleted, but not if the comment is already marked "(COMMENT DELETED)".

Note: Right now, you can still reply to a comment that has been deleted. serendipity_displayCommentForm still needs to be modified so that it doesn't put a "reply" link on deleted comments.

Example:
(comment count: 5)
1
1.1
1.1.1
1.2
1.2.1

Deleting 1.1
(comment count: 4)
1
(COMMENT DELETED) - formerly 1.1
1.1.1
1.2
1.2.1

Deleting 1.1.1
(comment count: 3)
1
(COMMENT DELETED) - formerly 1.1
1.2
1.2.1

Deleting 1.1
(comment count: 3)
1
1.2
1.2.1

diff:

Code: Select all

<         $sql = serendipity_db_query("SELECT status, parent_id FROM {$serendipity['dbPrefix']}comments
<                                             WHERE entry_id = '". (int)$entry_id ."'
<                                                     AND id = '". (int)$id ."'
<                                                     $admin", true);
<
<         serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}comments
<                                     WHERE entry_id = '". (int)$entry_id ."'
<                                             AND id = '". (int)$id ."'
<                                             $admin");
---
>         $sql = serendipity_db_query("SELECT status, parent_id, body FROM {$serendipity['dbPrefix']}comments
>                                              WHERE entry_id = '". (int)$entry_id ."'
>                                                      AND id = '". (int)$id ."'
>                                                      $admin", true);
>         /* Check to see if the comment has children
>            if it does, don't delete, but replace with "*(COMMENT DELETED)*"
>            to delete a tree, delete children first */
>         $has_parent = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}comments
>                                                     WHERE parent_id = '". (int)$id ."'", true);
>
>         if (is_array($has_parent))
>         {
>             /* keep the entry, but replace it's contents with "*(COMMENT DELETED)*" */
>             serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET body = '*(COMMENT DELETED)*'
>                                          WHERE id = '". (int)$id ."'");
>         }
>         else
>         {
>             /* it's has no children, delete it completely */
>             serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}comments
>                                      WHERE entry_id = '". (int)$entry_id ."'
>                                              AND id = '". (int)$id ."'
>                                              $admin");
>         }
240c255,258
<         if ($sql['status'] !== 'pending') {
---
>         /* If it's pending, don't bother updating the comment count
>            it's ok that it reduces the count even though the post remains, because it's now an empty post anyway, so it shouldn't count */
>         /* BUT if it's already "deleted", don't decrement the count any further */
>         if (($sql['status'] !== 'pending') && ($sql['body'] !== '*(COMMENT DELETED)*')) {
244,245d261
<         serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = '" . (int)$id . "'");
<
Manuel
Regular
Posts: 36
Joined: Sun Feb 19, 2006 11:36 pm
Location: Lion's den :3
Contact:

Post by Manuel »

Wouldn't it be easier to just edit the offending comment than to make developers hardcode a "COMMENT DELETED" into the s9y core?

Apart from that, there might be users who actually do want specific comments to disappear completely (which includes a decreasing number in the comment counter beneath each entry), and it would be no hassle for the blog admin either. On the contrary, he/she could even replace an offending comment with situation-specific explanations concerning the reason for his/her intervention.
Image
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Jabrwock »

Manuel wrote:Wouldn't it be easier to just edit the offending comment than to make developers hardcode a "COMMENT DELETED" into the s9y core?

Apart from that, there might be users who actually do want specific comments to disappear completely (which includes a decreasing number in the comment counter beneath each entry), and it would be no hassle for the blog admin either. On the contrary, he/she could even replace an offending comment with situation-specific explanations concerning the reason for his/her intervention.
Deleting a comment that has been replied to has the potential to screw with a conversation's hierarchy. That's why I wanted something like this. It only truly deletes comments with no replies.

Then again, it would be great if this could be turned on/off in the settings, so people who wanted this feature could turn it on & maybe customize the message, but others could skip it and delete as normal.

I can't seem to edit on the entry screen. I have to go to the admin screen, search for the comment, and edit it there, so it's a bit of a pain. Besides, it's apparently bad form to edit someone else's comment rather than delete it outright... or so I'm told, so I wanted a "standard" deletion message, kept it editor neutral. This allows comment removal, but keeps the "placeholder" comment intact while there are still replies present. To delete the whole tree, you delete the children first.

Essentially I was looking for functionality like in LiveJournal. Example: http://gamepolitics.livejournal.com/214 ... #t15400880
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Jabrwock »

For the moment, I've made a temporary "comments.tpl" that checks for "<strong>(COMMENT DELETED)</strong>", If it's present, it skips printing the "reply" link. (no point in allowing replies to a "non-existent" comment).

This is just a temporary fix. Maybe we can add a field in the table that will indicate that a comment has been (mostly) wiped, so it checks that instead of the comment contents.

Code: Select all

20c20
<             {if $entry.allow_comments}
---
>             {if $entry.allow_comments && $comment.body != "<strong>(COMMENT DELETED)</strong>"}
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Jabrwock,

many thanks for your work! I committed the patch you made to the PHP file and the bundled templates of our Serendipity 1.1 trunk.

I added a nifty modification: The first deletion of a comment with a subtree will replace it with "COMMENT_REMOVED" (it is replaced in the template with the right localized version so that if you change languages, you always see the localized version). If you delete such a comment AGAIN, it will be deleted the hard way.

So all people should be satisfied with this? :-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Jabrwock »

garvinhicking wrote:I added a nifty modification: The first deletion of a comment with a subtree will replace it with "COMMENT_REMOVED" (it is replaced in the template with the right localized version so that if you change languages, you always see the localized version).
I thought about that, but wasn't sure how to edit the localized version to accomplish a "generic" message. I'm learning as I go. ;)

I think a mod to the default comments.tpl would also be an idea, so that if the comment has the COMMENT_REMOVED as it's body, it doesn't display the "reply" link. So this would prevent the deleted comment from being replied to after it has been marked.

I would check something like {if $comment.body != $CONST.COMMENT_REMOVED} right? (assuming COMMENT_REMOVED has been defined in /lang)
If you delete such a comment AGAIN, it will be deleted the hard way.
That's an excellent idea. Then if they REALLY want it gone, it's gone. But for quick moderation, it works too.
Manuel
Regular
Posts: 36
Joined: Sun Feb 19, 2006 11:36 pm
Location: Lion's den :3
Contact:

Post by Manuel »

Sounds good, Garvin, but this needs to be documented somewhere. Alternatively, on deleting a comment, the user could be prompted with appropriate information.
Image
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Jabrwock »

Manuel wrote:Or, on deleting a comment the user is prompted with appropriate information.
I think a warning in that deletion prompt, something like (are you sure you want to delete this: warning, this comment has children, and will be moderated instead of deleted. use delete again to completely delete it) would suffice.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

The problem is that for this amount of verbosity I currently have no time to really implement it; it would also require javascript, which I try to avoid.

I'll need to think where to best document this :-/

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Jabrwock
Regular
Posts: 34
Joined: Fri Feb 24, 2006 5:42 pm
Location: Saskatoon, Saskatchewan, Canada
Contact:

Post by Jabrwock »

Yeah, it would be kind of hard to make it context sensitive, in comments.inc.php there's no way to know if $comment has been replied to.

Maybe just add to COMMENT_DELETE_CONFIRM to add in (Note: if this comment has already been replied to, deleting it will replace it with {COMMENT DELETED}. If this comment already contains {COMMENT DELETED}, clicking delete will permanently remove this comment.)
Post Reply