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

Add support for anonymous comments



This allows for removing users without also removing the corresponding
comments. Instead, all comments from deleted users will be displayed as
"Anonymous comment".

Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent 6ee13212
Upgrading Upgrading
========= =========
From 2.3.1 to 3.0.0
-------------------
1. Drop the user ID foreign key from the "PackageComments" table:
`ALTER TABLE PackageComments DROP FOREIGN KEY PackageComments_ibfk_1;` should
work in most cases. Otherwise, check the output of `SHOW CREATE TABLE
PackageComments;` and use the foreign key name shown there.
2. Add support for anonymous comments:
----
ALTER TABLE PackageComments
MODIFY UsersID INTEGER UNSIGNED NULL DEFAULT NULL,
ADD FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE SET NULL;
----
From 2.2.0 to 2.3.0 From 2.2.0 to 2.3.0
------------------- -------------------
......
...@@ -161,14 +161,14 @@ CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageID); ...@@ -161,14 +161,14 @@ CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageID);
CREATE TABLE PackageComments ( CREATE TABLE PackageComments (
ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
PackageID INTEGER UNSIGNED NOT NULL, PackageID INTEGER UNSIGNED NOT NULL,
UsersID INTEGER UNSIGNED NOT NULL, UsersID INTEGER UNSIGNED NULL DEFAULT NULL,
Comments TEXT NOT NULL DEFAULT '', Comments TEXT NOT NULL DEFAULT '',
CommentTS BIGINT UNSIGNED NOT NULL DEFAULT 0, CommentTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL, DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX (UsersID), INDEX (UsersID),
INDEX (PackageID), INDEX (PackageID),
FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE, FOREIGN KEY (UsersID) REFERENCES Users(ID) ON SET NULL,
FOREIGN KEY (DelUsersID) REFERENCES Users(ID) ON DELETE CASCADE, FOREIGN KEY (DelUsersID) REFERENCES Users(ID) ON DELETE CASCADE,
FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE
) ENGINE = InnoDB; ) ENGINE = InnoDB;
......
...@@ -208,11 +208,11 @@ function package_comments($pkgid) { ...@@ -208,11 +208,11 @@ function package_comments($pkgid) {
if ($pkgid > 0) { if ($pkgid > 0) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS "; $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS ";
$q.= "FROM PackageComments, Users "; $q.= "FROM PackageComments LEFT JOIN Users ";
$q.= "WHERE PackageComments.UsersID = Users.ID"; $q.= "ON PackageComments.UsersID = Users.ID ";
$q.= " AND PackageID = " . $pkgid; $q.= "WHERE PackageID = " . $pkgid . " ";
$q.= " AND DelUsersID IS NULL"; # only display non-deleted comments $q.= "AND DelUsersID IS NULL "; # only display non-deleted comments
$q.= " ORDER BY CommentTS DESC"; $q.= "ORDER BY CommentTS DESC";
if (!isset($_GET['comments'])) { if (!isset($_GET['comments'])) {
$q.= " LIMIT 10"; $q.= " LIMIT 10";
......
...@@ -10,7 +10,7 @@ $pkgname = $row['Name']; ...@@ -10,7 +10,7 @@ $pkgname = $row['Name'];
</h3> </h3>
<?php while (list($indx, $row) = each($comments)): ?> <?php while (list($indx, $row) = each($comments)): ?>
<?php if ($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>
...@@ -22,10 +22,18 @@ $pkgname = $row['Name']; ...@@ -22,10 +22,18 @@ $pkgname = $row['Name'];
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" /> <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="image" src="/images/x.png" alt="<?= __('Delete comment') ?>" name="submit" value="1" /> <input type="image" src="/images/x.png" alt="<?= __('Delete comment') ?>" name="submit" value="1" />
</fieldset> </fieldset>
<?php if ($row['UserName']): ?>
<?= __('Comment by %s', $row['UserName']) ?> <?= __('Comment by %s', $row['UserName']) ?>
<?php else: ?>
<?= __('Anonymous comment') ?>
<?php endif; ?>
</form> </form>
<?php else: ?> <?php else: ?>
<?php if ($row['UserName']): ?>
<?= __('Comment by %s', $row['UserName']) ?> <?= __('Comment by %s', $row['UserName']) ?>
<?php else: ?>
<?= __('Anonymous comment') ?>
<?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>
......
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