Commit daceef50 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Make deleted comments visible to Trusted Users



This allows Trusted Users to check whether a user posted a politically
incorrect comment, even if he already deleted it.

Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent 16e4708f
...@@ -68,3 +68,7 @@ ...@@ -68,3 +68,7 @@
padding: 0; padding: 0;
border: none; border: none;
} }
.comment-deleted {
color: #999;
}
...@@ -7,6 +7,7 @@ define("CRED_ACCOUNT_EDIT_DEV", 3); ...@@ -7,6 +7,7 @@ define("CRED_ACCOUNT_EDIT_DEV", 3);
define("CRED_ACCOUNT_LAST_LOGIN", 4); define("CRED_ACCOUNT_LAST_LOGIN", 4);
define("CRED_ACCOUNT_SEARCH", 5); define("CRED_ACCOUNT_SEARCH", 5);
define("CRED_COMMENT_DELETE", 6); define("CRED_COMMENT_DELETE", 6);
define("CRED_COMMENT_VIEW_DELETED", 22);
define("CRED_PKGBASE_ADOPT", 7); define("CRED_PKGBASE_ADOPT", 7);
define("CRED_PKGBASE_CHANGE_CATEGORY", 8); define("CRED_PKGBASE_CHANGE_CATEGORY", 8);
define("CRED_PKGBASE_DELETE", 9); define("CRED_PKGBASE_DELETE", 9);
...@@ -55,6 +56,7 @@ function has_credential($credential, $approved_users=array()) { ...@@ -55,6 +56,7 @@ function has_credential($credential, $approved_users=array()) {
case CRED_ACCOUNT_LAST_LOGIN: case CRED_ACCOUNT_LAST_LOGIN:
case CRED_ACCOUNT_SEARCH: case CRED_ACCOUNT_SEARCH:
case CRED_COMMENT_DELETE: case CRED_COMMENT_DELETE:
case CRED_COMMENT_VIEW_DELETED:
case CRED_PKGBASE_ADOPT: case CRED_PKGBASE_ADOPT:
case CRED_PKGBASE_CHANGE_CATEGORY: case CRED_PKGBASE_CHANGE_CATEGORY:
case CRED_PKGBASE_DELETE: case CRED_PKGBASE_DELETE:
......
...@@ -25,10 +25,11 @@ function pkgbase_categories() { ...@@ -25,10 +25,11 @@ function pkgbase_categories() {
* Get the number of non-deleted comments for a specific package base * Get the number of non-deleted comments for a specific package base
* *
* @param string $base_id The package base ID to get comment count for * @param string $base_id The package base ID to get comment count for
* @param bool $include_deleted True if deleted comments should be included
* *
* @return string The number of comments left for a specific package * @return string The number of comments left for a specific package
*/ */
function pkgbase_comments_count($base_id) { function pkgbase_comments_count($base_id, $include_deleted) {
$base_id = intval($base_id); $base_id = intval($base_id);
if (!$base_id) { if (!$base_id) {
return null; return null;
...@@ -37,7 +38,9 @@ function pkgbase_comments_count($base_id) { ...@@ -37,7 +38,9 @@ function pkgbase_comments_count($base_id) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT COUNT(*) FROM PackageComments "; $q = "SELECT COUNT(*) FROM PackageComments ";
$q.= "WHERE PackageBaseID = " . $base_id . " "; $q.= "WHERE PackageBaseID = " . $base_id . " ";
$q.= "AND DelUsersID IS NULL"; if (!$include_deleted) {
$q.= "AND DelUsersID IS NULL";
}
$result = $dbh->query($q); $result = $dbh->query($q);
if (!$result) { if (!$result) {
return null; return null;
...@@ -51,10 +54,11 @@ function pkgbase_comments_count($base_id) { ...@@ -51,10 +54,11 @@ function pkgbase_comments_count($base_id) {
* *
* @param int $base_id The package base ID to get comments for * @param int $base_id The package base ID to get comments for
* @param int $limit Maximum number of comments to return (0 means unlimited) * @param int $limit Maximum number of comments to return (0 means unlimited)
* @param bool $include_deleted True if deleted comments should be included
* *
* @return array All package comment information for a specific package base * @return array All package comment information for a specific package base
*/ */
function pkgbase_comments($base_id, $limit) { function pkgbase_comments($base_id, $limit, $include_deleted) {
$base_id = intval($base_id); $base_id = intval($base_id);
$limit = intval($limit); $limit = intval($limit);
if (!$base_id) { if (!$base_id) {
...@@ -63,10 +67,13 @@ function pkgbase_comments($base_id, $limit) { ...@@ -63,10 +67,13 @@ function pkgbase_comments($base_id, $limit) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT PackageComments.ID, UserName, UsersID, Comments, "; $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, ";
$q.= "CommentTS FROM PackageComments LEFT JOIN Users "; $q.= "CommentTS, DelUsersID FROM PackageComments LEFT JOIN Users ";
$q.= "ON PackageComments.UsersID = Users.ID "; $q.= "ON PackageComments.UsersID = Users.ID ";
$q.= "WHERE PackageBaseID = " . $base_id . " "; $q.= "WHERE PackageBaseID = " . $base_id . " ";
$q.= "AND DelUsersID IS NULL ORDER BY CommentTS DESC"; if (!$include_deleted) {
$q.= "AND DelUsersID IS NULL ";
}
$q.= "ORDER BY CommentTS DESC";
if ($limit > 0) { if ($limit > 0) {
$q.=" LIMIT " . $limit; $q.=" LIMIT " . $limit;
} }
...@@ -242,7 +249,8 @@ function pkgbase_display_details($base_id, $row, $SID="") { ...@@ -242,7 +249,8 @@ function pkgbase_display_details($base_id, $row, $SID="") {
} }
$limit = isset($_GET['comments']) ? 0 : 10; $limit = isset($_GET['comments']) ? 0 : 10;
$comments = pkgbase_comments($base_id, $limit); $include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
$comments = pkgbase_comments($base_id, $limit, $include_deleted);
if (!empty($comments)) { if (!empty($comments)) {
include('pkg_comments.php'); include('pkg_comments.php');
} }
......
...@@ -436,7 +436,8 @@ function pkg_display_details($id=0, $row, $SID="") { ...@@ -436,7 +436,8 @@ function pkg_display_details($id=0, $row, $SID="") {
} }
$limit = isset($_GET['comments']) ? 0 : 10; $limit = isset($_GET['comments']) ? 0 : 10;
$comments = pkgbase_comments($base_id, $limit); $include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
$comments = pkgbase_comments($base_id, $limit, $include_deleted);
if (!empty($comments)) { if (!empty($comments)) {
include('pkg_comments.php'); include('pkg_comments.php');
} }
......
...@@ -6,7 +6,8 @@ if (isset($row['BaseID'])) { ...@@ -6,7 +6,8 @@ if (isset($row['BaseID'])) {
/* On a package base details page. */ /* On a package base details page. */
$base_id = $row['ID']; $base_id = $row['ID'];
} }
$count = pkgbase_comments_count($base_id); $include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
$count = pkgbase_comments_count($base_id, $include_deleted);
?> ?>
<div id="news"> <div id="news">
<h3> <h3>
...@@ -18,8 +19,8 @@ $count = pkgbase_comments_count($base_id); ...@@ -18,8 +19,8 @@ $count = pkgbase_comments_count($base_id);
<?php if ($row['UserName'] && $SID): <?php if ($row['UserName'] && $SID):
$row['UserName'] = "<a href=\"" . get_user_uri($row['UserName']) . "\">{$row['UserName']}</a>"; $row['UserName'] = "<a href=\"" . get_user_uri($row['UserName']) . "\">{$row['UserName']}</a>";
endif; ?> endif; ?>
<h4> <h4<?php if ($row['DelUsersID']): ?> class="comment-deleted"<?php endif; ?>>
<?php if (can_delete_comment_array($row)): ?> <?php if (!$row['DelUsersID'] && can_delete_comment_array($row)): ?>
<form method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>"> <form method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
<fieldset style="display:inline;"> <fieldset style="display:inline;">
<input type="hidden" name="action" value="do_DeleteComment" /> <input type="hidden" name="action" value="do_DeleteComment" />
...@@ -39,10 +40,13 @@ $count = pkgbase_comments_count($base_id); ...@@ -39,10 +40,13 @@ $count = pkgbase_comments_count($base_id);
<?php else: ?> <?php else: ?>
<?= __('Anonymous comment') ?> <?= __('Anonymous comment') ?>
<?php endif; ?> <?php endif; ?>
<?php if ($row['DelUsersID']): ?>
(<?= __('deleted') ?>)
<?php endif; ?>
<?php endif; ?> <?php endif; ?>
</h4> </h4>
<p class="timestamp"><?= gmdate('Y-m-d H:i', $row['CommentTS']) ?></p> <p class="timestamp"><?= gmdate('Y-m-d H:i', $row['CommentTS']) ?></p>
<div class="article-content"> <div class="article-content<?php if ($row['DelUsersID']): ?> comment-deleted<?php endif; ?>">
<p> <p>
<?= parse_comment($row['Comments']) ?> <?= parse_comment($row['Comments']) ?>
</p> </p>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment