From eaf97602ff7d05d15a1d2aef2f563a67bcaaf505 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Thu, 23 Jul 2020 11:49:42 +0200 Subject: [PATCH] Make sure the bogus hash is served for raw changes When serving recent changes, we know the username and host of the person making the edit. We use GetAuthorLink to show either the name linked to the username, or "Anonymous", or a colour coded bogus hash of their host (that's the four octal digits, hopefully colourized by your CSS). When serving raw changes, we used to serve just the username or "Anonymous". In order to help use cases such as the Gemini wiki running on gemini://alexschroeder.ch:1965 which consumes raw changes to present a view that is compatible with Gemini Wiki, we'd like those bogus hashes as well. This comit does that by splitting ColorCode into Code and ColorCode such that we can use Code when serving raw changes. --- wiki.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/wiki.pl b/wiki.pl index 7b0c2428..df1c16ee 100755 --- a/wiki.pl +++ b/wiki.pl @@ -1860,7 +1860,7 @@ sub RcTextRevision { $summary = GetPageContent($id) if GetParam('full', 0); print "\n", RcTextItem('title', NormalToFree($id)), RcTextItem('description', $summary), - RcTextItem('generator', GetAuthor($username)), + RcTextItem('generator', GetAuthor($username, $host)), RcTextItem('language', join(', ', @{$languages})), RcTextItem('link', $link), RcTextItem('last-modified', TimeToW3($ts)), RcTextItem('revision', $revision), @@ -2216,11 +2216,16 @@ sub ScriptLinkDiff { return ScriptLink($action, $text, 'diff'); } -sub ColorCode { +sub Code { my ($str) = @_; my $num = unpack("L",B::hash($str)); # 32-bit integer my $code = sprintf("%o", $num); # octal is 0-7 - my @indexes = split(//, substr($code, 0, 4)); # four numbers + return substr($code, 0, 4); # four numbers +} + +sub ColorCode { + my $code = Code(@_); + my @indexes = split(//, $code); # four numbers my @colors = qw/red orange yellow green blue indigo violet white/; return $q->span({-class => 'ip-code', -title => T('Anonymous')}, join('', map { $q->span({-class => $colors[$_]}, $_) } @@ -2228,9 +2233,10 @@ sub ColorCode { } sub GetAuthor { - my ($username) = @_; + my ($username, $host) = @_; return $username if $username; - return T('Anonymous'); + return T('Anonymous') if $host eq 'Anonymous'; + return Code($host); } sub GetAuthorLink {