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.
This commit is contained in:
Alex Schroeder
2020-07-23 11:49:42 +02:00
parent 987c262425
commit eaf97602ff

16
wiki.pl
View File

@@ -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 {