From 46911eb14eb99a7caa355659c53786d25305e3b9 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Sat, 17 Mar 2018 18:53:51 +0100 Subject: [PATCH] Anonymize IPs that we do show using a color code. --- css/wiki.css | 44 ++++++++++++++++++++++++++++++++++++++++++++ wiki.pl | 17 ++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/css/wiki.css b/css/wiki.css index 128d5331c..e408ca33d 100644 --- a/css/wiki.css +++ b/css/wiki.css @@ -172,6 +172,50 @@ span.bar a { padding: 1ex 0; } +.red { + background: red; + color: red; +} + +.orange { + background: orange; + color: orange; +} + +.yellow { + background: yellow; + color: yellow; +} + +.green { + background: green; + color: green; +} + +.blue { + background: blue; + color: blue; +} + +.indigo { + background: indigo; + color: indigo; +} + +.violet { + background: violet; + color: violet; +} + +.white { + background: white; + color: white; +} + +.ip-code { + border: 1px solid #666; +} + hr { border: none; color: black; diff --git a/wiki.pl b/wiki.pl index 5f273d8c7..b114c4fa2 100644 --- a/wiki.pl +++ b/wiki.pl @@ -35,6 +35,7 @@ package OddMuse; no warnings 'numeric'; no warnings 'uninitialized'; use utf8; # in case anybody ever adds UTF8 characters to the source +use B; use CGI qw/-utf8/; use CGI::Carp qw(fatalsToBrowser); use File::Glob ':glob'; @@ -2195,6 +2196,17 @@ sub ScriptLinkDiff { return ScriptLink($action, $text, 'diff'); } +sub ColorCode { + 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 + 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[$_]}, $_) } + @indexes)); +} + sub GetAuthor { my ($username) = @_; return $username if $username; @@ -2209,12 +2221,11 @@ sub GetAuthorLink { $username = ''; # Just pretend it isn't there. } if ($username and $RecentLink) { - return ScriptLink(UrlEncode($username), $name, 'author', undef, $host); + return ScriptLink(UrlEncode($username), $name, 'author'); } elsif ($username) { return $q->span({-class=>'author'}, $name); } - # FIXME add funny little image to visuall group by $host - return T('Anonymous'); + return ColorCode($host); } sub GetHistoryLink {