diff mbox

[v2] pkg_comments.php: Make comment timestamps link to the comment

Message ID 20181017013138.7081-1-archlinux@thecybershadow.net
State Accepted, archived
Headers show

Commit Message

Vladimir Panteleev Oct. 17, 2018, 1:31 a.m. UTC
As of today, there is no easy way to obtain a link to a specific
comment on a package page.

Many implementations of forums and comment systems today seem to
follow a convention where a comment's timestamp is an unobtrusive link
to the comment itself. Some examples are:

- phpBB (e.g. bbs.archlinux.org)
- GitHub
- Disqus
- Discourse

This patch adopts this convention as well, by making the timestamp a
link to the comment.
---

Version 2: Removed the CSS rule making the link color same as the
text, thus making the link more discoverable.

 web/template/pkg_comments.php | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Eli Schwartz Oct. 17, 2018, 1:56 a.m. UTC | #1
On 10/16/18 9:31 PM, Vladimir Panteleev wrote:
> As of today, there is no easy way to obtain a link to a specific
> comment on a package page.
> 
> Many implementations of forums and comment systems today seem to
> follow a convention where a comment's timestamp is an unobtrusive link
> to the comment itself. Some examples are:
> 
> - phpBB (e.g. bbs.archlinux.org)
> - GitHub
> - Disqus
> - Discourse
> 
> This patch adopts this convention as well, by making the timestamp a
> link to the comment.
> ---
> 
> Version 2: Removed the CSS rule making the link color same as the
> text, thus making the link more discoverable.

Thanks, the change looks great! Tested locally and it performs as expected.

...

As discussed on IRC, there doesn't seem to be any specific motivation to
add the CSS rule other than "preserve the status quo" w.r.t. coloring,
but I think it's reasonable to make it stand out, and this matches what
I've seen on many other websites, so, merged to pu.
diff mbox

Patch

diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index 3001a34..3bcf1a3 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -53,17 +53,19 @@  if ($comment_section == "package") {
 			$pkgbase_name = $row["PackageBaseName"];
 		}
 
+		$anchor = (isset($pinned) ? "pinned-" : "comment-") . $row['ID'];
 		$date_fmtd = date('Y-m-d H:i', $row['CommentTS']);
+		$date_link = '<a href="#' . $anchor . '" class="date">' . $date_fmtd . '</a>';
 		if ($comment_section == "package") {
 			if ($row['UserName']) {
 				$user_fmtd = html_format_username($row['UserName']);
-				$heading = __('%s commented on %s', $user_fmtd, $date_fmtd);
+				$heading = __('%s commented on %s', $user_fmtd, $date_link);
 			} else {
-				$heading = __('Anonymous comment on %s', $date_fmtd);
+				$heading = __('Anonymous comment on %s', $date_link);
 			}
 		} elseif ($comment_section == "account") {
 			$pkg_uri = '<a href=' . htmlspecialchars(get_pkg_uri($row['PackageBaseName']), ENT_QUOTES) . '>' . htmlspecialchars($row['PackageBaseName']) . '</a></td>';
-			$heading = __('Commented on package %s on %s', $pkg_uri, $date_fmtd);
+			$heading = __('Commented on package %s on %s', $pkg_uri, $date_link);
 		}
 
 		$is_deleted = $row['DelTS'];
@@ -97,7 +99,7 @@  if ($comment_section == "package") {
 			$comment_classes .= " comment-deleted";
 		}
 		?>
-		<h4 id="<?= isset($pinned) ? "pinned-" : "comment-" ?><?= $row['ID'] ?>" class="<?= $comment_classes ?>">
+		<h4 id="<?= $anchor ?>" class="<?= $comment_classes ?>">
 			<?= $heading ?>
 			<?php if ($is_deleted && has_credential(CRED_COMMENT_UNDELETE)): ?>
 				<form class="undelete-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
@@ -152,7 +154,7 @@  if ($comment_section == "package") {
 				</form>
 			<?php endif; ?>
 		</h4>
-		<div id="<?= isset($pinned) ? "pinned-" : "comment-" ?><?= $row['ID'] ?>-content" class="article-content<?php if ($is_deleted): ?> comment-deleted<?php endif; ?>">
+		<div id="<?= $anchor ?>-content" class="article-content<?php if ($is_deleted): ?> comment-deleted<?php endif; ?>">
 			<div>
 				<?php if (!empty($row['RenderedComment'])): ?>
 				<?= $row['RenderedComment'] ?>