Wipe username when deleting comments + delete entriely if no replies are detected

This commit is contained in:
Starbeamrainbowlabs 2017-11-19 12:44:58 +00:00
parent d1cc747a75
commit 55d27a84b4
4 changed files with 14 additions and 4 deletions

View File

@ -11,6 +11,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- Added new "« Parent Page" to subpages so that you can easily visit their parent pages - Added new "« Parent Page" to subpages so that you can easily visit their parent pages
- Users can now delete their own comments, and users logged in as a moderator or better can delete anyone's comments. - Users can now delete their own comments, and users logged in as a moderator or better can delete anyone's comments.
- Added new `comment-delete` action - Added new `comment-delete` action
- Comments are deleted entirely if they have no replies - otherwise the username & message are wiped
- The `history` action now supports `format=json` and `format=csv` - The `history` action now supports `format=json` and `format=csv`
- Added tags next to the names of pages in the search results - Added tags next to the names of pages in the search results
- Added new `random_page_exclude` setting that allows you to exclude pages from the random action with a (PHP) regular expression - Added new `random_page_exclude` setting that allows you to exclude pages from the random action with a (PHP) regular expression

View File

@ -2853,6 +2853,7 @@ function delete_comment(&$comment_data, $target_id)
for($i = 0; $i < $comment_count; $i++) { for($i = 0; $i < $comment_count; $i++) {
if($comment_data[$i]->id == $target_id) { if($comment_data[$i]->id == $target_id) {
unset($comment_data[$i]->username);
$comment_data[$i]->message = "_[Deleted]_"; $comment_data[$i]->message = "_[Deleted]_";
return true; return true;
} }
@ -2923,7 +2924,7 @@ function render_comments($comments_data, $depth = 0)
$comment = $comments_data[$i]; $comment = $comments_data[$i];
$result .= "\t<div class='comment' id='comment-$comment->id' data-comment-id='$comment->id'>\n"; $result .= "\t<div class='comment' id='comment-$comment->id' data-comment-id='$comment->id'>\n";
$result .= "\t<p class='comment-header'><span class='name'>" . page_renderer::render_username($comment->username) . "</span> said:</p>"; $result .= "\t<p class='comment-header'><span class='name'>" . page_renderer::render_username($comment->username ?? "<em>Unknown</em>") . "</span> said:</p>";
$result .= "\t<div class='comment-body'>\n"; $result .= "\t<div class='comment-body'>\n";
$result .= "\t\t" . parse_page_source($comment->message); $result .= "\t\t" . parse_page_source($comment->message);
$result .= "\t</div>\n"; $result .= "\t</div>\n";

View File

@ -59,7 +59,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds threaded comments to the bottom of every page.", "description": "Adds threaded comments to the bottom of every page.",
"id": "feature-comments", "id": "feature-comments",
"lastupdate": 1511092311, "lastupdate": 1511092595,
"optional": false "optional": false
}, },
{ {

View File

@ -338,7 +338,15 @@ function delete_comment(&$comment_data, $target_id)
for($i = 0; $i < $comment_count; $i++) { for($i = 0; $i < $comment_count; $i++) {
if($comment_data[$i]->id == $target_id) { if($comment_data[$i]->id == $target_id) {
$comment_data[$i]->message = "_[Deleted]_"; if(count($comment_data[$i]->replies) == 0) {
unset($comment_data[$i]);
// Reindex the comment list before returning
$comment_data = array_values($comment_data);
}
else {
unset($comment_data[$i]->username);
$comment_data[$i]->message = "_[Deleted]_";
}
return true; return true;
} }
if(count($comment_data[$i]->replies) > 0 && if(count($comment_data[$i]->replies) > 0 &&
@ -408,7 +416,7 @@ function render_comments($comments_data, $depth = 0)
$comment = $comments_data[$i]; $comment = $comments_data[$i];
$result .= "\t<div class='comment' id='comment-$comment->id' data-comment-id='$comment->id'>\n"; $result .= "\t<div class='comment' id='comment-$comment->id' data-comment-id='$comment->id'>\n";
$result .= "\t<p class='comment-header'><span class='name'>" . page_renderer::render_username($comment->username) . "</span> said:</p>"; $result .= "\t<p class='comment-header'><span class='name'>" . page_renderer::render_username($comment->username ?? "<em>Unknown</em>") . "</span> said:</p>";
$result .= "\t<div class='comment-body'>\n"; $result .= "\t<div class='comment-body'>\n";
$result .= "\t\t" . parse_page_source($comment->message); $result .= "\t\t" . parse_page_source($comment->message);
$result .= "\t</div>\n"; $result .= "\t</div>\n";