Permalink
Browse files

Getting ready for #DSGVO

Removing IP number ("host") from page files and keep files. The IP
numbers remain in the RC file. GetAuthor and GetAuthorLink now take
username as a first argument and host as an optional second argument.
Sorry for the incompatible change.
  • Loading branch information...
kensanata committed Mar 17, 2018
1 parent 429fb76 commit 4729171a6650b3ea6362efe3a93b4f398673a349
Showing with 24 additions and 29 deletions.
  1. +4 −4 stuff/gopher-server.pl
  2. +1 −1 t/gopher-server.t
  3. +1 −1 t/rc.t
  4. +18 −23 wiki.pl
@@ -447,8 +447,8 @@ sub serve_text_page_menu {
} elsif ($title =~ s!^image[/a-z]* external:!pics/!) {
$self->print_menu("I" . $text||$title, $title);
} elsif ($title) {
$title =~ s!^image[/[a-z]]*:!!;
$self->print_menu("1" . $text||$title, $title . "/menu");
$title =~ s!^image[/a-z]*:!!i;
$self->print_menu("1" . ($text||$title), $title . "/menu");
}
}

@@ -480,7 +480,7 @@ sub serve_page_history {

$self->print_menu("1" . NormalToFree($id) . " (current)", "$id/menu");
$self->print_info(CalcTime($Page{ts})
. " by " . GetAuthor($Page{host}, $Page{username})
. " by " . GetAuthor($Page{username})
. ($Page{summary} ? ": $Page{summary}" : "")
. ($Page{minor} ? " (minor)" : ""));

@@ -489,7 +489,7 @@ sub serve_page_history {
$self->print_menu("1" . NormalToFree($id) . " ($keep->{revision})",
"$id/$keep->{revision}/menu");
$self->print_info(CalcTime($keep->{ts})
. " by " . GetAuthor($keep->{host}, $keep->{username})
. " by " . GetAuthor($keep->{username})
. ($keep->{summary} ? ": $keep->{summary}" : "")
. ($keep->{minor} ? " (minor)" : ""));
}
@@ -226,7 +226,7 @@ like($page, qr/^$haiku_re/, "Haiku updated");

$page = query_gopher("Haiku/history");
like($page, qr/^1Haiku \(current\)\tHaiku\/menu\t/m, "Haiku (current)");
like($page, qr/^i\d\d:\d\d UTC by Alex from \S+: typos \(minor\)/m,
like($page, qr/^i\d\d:\d\d UTC by Alex: typos \(minor\)/m,
"Metadata recorded");
like($page, qr/^1Haiku \(1\)\tHaiku\/1\/menu\t/m, "Haiku (1)");

2 t/rc.t
@@ -51,7 +51,7 @@ test_page(get_page('action=rc raw=1'), 'title: Wiki');
WriteStringToFile($RcFile, "1${FS}test${FS}${FS}test${FS}127.0.0.1${FS}${FS}1${FS}${FS}\n");
test_page_negative(get_page('action=rc raw=1'), 'title: test');
test_page(get_page('action=rc raw=1 from=1'), 'title: Wiki', 'title: test',
'description: test', 'generator: 127.0.0.1',
'description: test', 'generator: Anonymous',
'link: http://localhost/wiki.pl/test',
'last-modified: 1970-01-01T00:00Z', 'revision: 1');

41 wiki.pl
@@ -1757,7 +1757,7 @@ sub RcHtml {
$languages, $cluster, $last) = @_;
my $all_revision = $last ? undef : $revision; # no revision for the last one
$host = QuoteHtml($host);
my $author = GetAuthorLink($host, $username);
my $author = GetAuthorLink($username, $host);
my $sum = $summary ? $q->span({class=>'dash'}, ' – ')
. $q->strong(QuoteHtml($summary)) : '';
my $edit = $minor ? $q->em({class=>'type'}, T('(minor)')) : '';
@@ -1840,7 +1840,7 @@ sub RcTextRevision {
: ($UsePathInfo ? '/' : '?') . UrlEncode($id));
print "\n", RcTextItem('title', NormalToFree($id)),
RcTextItem('description', $summary),
RcTextItem('generator', GetAuthor($host, $username)),
RcTextItem('generator', GetAuthor($username)),
RcTextItem('language', join(', ', @{$languages})), RcTextItem('link', $link),
RcTextItem('last-modified', TimeToW3($ts)),
RcTextItem('revision', $revision),
@@ -1925,7 +1925,6 @@ sub RssItem {
}
my $date = TimeToRFC822($ts);
$username = QuoteHtml($username);
$username ||= $host;
my $rss = "<item>\n";
$rss .= "<title>$name</title>\n";
my $link = ScriptUrl(GetParam('all', $cluster)
@@ -2034,8 +2033,7 @@ sub GetHistoryLine {
$html .= ' ' . GetOldPageLink('browse', $id, $revision,
Ts('Revision %s', $revision));
}
my $host = $data{host} || $data{ip};
$html .= T(' . . . .') . ' ' . GetAuthorLink($host, $data{username});
$html .= T(' . . . .') . ' ' . GetAuthorLink($data{username});
$html .= $q->span({class=>'dash'}, ' &#8211; ')
. $q->strong(QuoteHtml($data{summary})) if $data{summary};
$html .= ' ' . $q->em({class=>'type'}, T('(minor)')) . ' ' if $data{minor};
@@ -2198,14 +2196,13 @@ sub ScriptLinkDiff {
}

sub GetAuthor {
my ($host, $username) = @_;
return $username . ' ' . Ts('from %s', $host) if $username and $host;
my ($username) = @_;
return $username if $username;
return T($host); # could be 'Anonymous'
return T('Anonymous');
}

sub GetAuthorLink {
my ($host, $username) = @_;
my ($username, $host) = @_;
$username = FreeToNormal($username);
my $name = NormalToFree($username);
if (ValidId($username) ne '') { # ValidId() returns error string
@@ -2216,7 +2213,8 @@ sub GetAuthorLink {
} elsif ($username) {
return $q->span({-class=>'author'}, $name);
}
return T($host); # could be 'Anonymous'
# FIXME add funny little image to visuall group by $host
return T('Anonymous');
}

sub GetHistoryLink {
@@ -2437,7 +2435,7 @@ sub GetFooterTimestamp {
$page //= \%Page;
if ($id and $rev ne 'history' and $rev ne 'edit' and $page->{revision}) {
my @elements = (($rev eq '' ? T('Last edited') : T('Edited')), TimeToText($page->{ts}),
Ts('by %s', GetAuthorLink($page->{host}, $page->{username})));
Ts('by %s', GetAuthorLink($page->{username})));
push(@elements, ScriptLinkDiff(2, $id, T('(diff)'), $rev)) if $UseDiff and $page->{revision} > 1;
return $q->div({-class=>'time'}, @elements);
}
@@ -3526,20 +3524,19 @@ sub PrintSearchResult {
$entry{size} = int((length($text) / 1024) + 1) . 'K';
$entry{'last-modified'} = TimeToText($Page{ts});
$entry{username} = $Page{username};
$entry{host} = $Page{host};
PrintSearchResultEntry(\%entry);
}

sub PrintSearchResultEntry {
my %entry = %{(shift)}; # get value from reference
if (GetParam('raw', 0)) {
$entry{generator} = GetAuthor($entry{host}, $entry{username});
foreach my $key (qw(title description size last-modified generator username host)) {
$entry{generator} = GetAuthor($entry{username});
foreach my $key (qw(title description size last-modified generator username)) {
print RcTextItem($key, $entry{$key});
}
print RcTextItem('link', "$ScriptName?$entry{title}"), "\n";
} else {
my $author = GetAuthorLink($entry{host}, $entry{username});
my $author = GetAuthorLink($entry{username});
$author ||= $entry{generator};
my $id = $entry{title};
my ($class, $resolved, $title, $exists) = ResolveId($id);
@@ -3593,8 +3590,8 @@ sub ReplaceAndSave {
RequestLockOrError(); # fatal
my @result = Replace($from, $to, 1, sub {
my ($id, $new) = @_;
Save($id, $new, $from . '' . $to, 1, ($Page{host} ne $q->remote_addr()));
});
Save($id, $new, $from . '' . $to, 1);
});
ReleaseLock();
return @result;
}
@@ -3713,9 +3710,7 @@ sub DoPost {
}
my $newAuthor = 0;
if ($oldrev) { # the first author (no old revision) is not considered to be "new"
# prefer usernames for potential new author detection
$newAuthor = 1 if not $Page{username} or $Page{username} ne GetParam('username', '');
$newAuthor = 1 if not $q->remote_addr() or not $Page{host} or $q->remote_addr() ne $Page{host};
}
my $oldtime = $Page{ts};
my $myoldtime = GetParam('oldtime', ''); # maybe empty!
@@ -3789,7 +3784,6 @@ sub AddComment {
sub Save { # call within lock, with opened page
my ($id, $new, $summary, $minor, $upload) = @_;
my $user = GetParam('username', '');
my $host = $q->remote_addr();
my $revision = $Page{revision} + 1;
my $old = $Page{text};
my $olddiff = $Page{'diff-major'} == '1' ? $Page{'diff-minor'} : $Page{'diff-major'};
@@ -3805,8 +3799,8 @@ sub Save { # call within lock, with opened page
ExpireKeepFiles();
$Page{lastmajor} = $revision unless $minor;
$Page{lastmajorsummary} = $summary unless $minor;
@Page{qw(ts revision summary username host minor text)} =
($Now, $revision, $summary, $user, $host, $minor, $new);
@Page{qw(ts revision summary username minor text)} =
($Now, $revision, $summary, $user, $minor, $new);
if ($UseDiff and $UseCache > 1 and $revision > 1 and not $upload and not TextIsFile($old)) {
UpdateDiffs($old, $new, $olddiff); # sets diff-major and diff-minor
}
@@ -3817,6 +3811,7 @@ sub Save { # call within lock, with opened page
if ($revision == 1 and $LockOnCreation{$id}) {
WriteStringToFile(GetLockedPageFile($id), 'LockOnCreation');
}
my $host = $q->remote_addr();
WriteRcLog($id, $summary, $minor, $revision, $user, $host, $languages, GetCluster($new));
AddToIndex($id) if ($revision == 1);
}
@@ -3908,7 +3903,7 @@ sub DoMaintain {
for my $line (@rc) {
my ($ts, $id, $minor, $summary, $host, @rest) = split(/$FS/, $line);
last if $ts >= $starttime;
push(@tmp, join($FS, $ts, $id, $minor, $summary, 'Anonymous', @rest));
push(@tmp, join($FS, $ts, $id, $minor, $summary, T('Anonymous'), @rest));
}
print $q->p(Ts('Moving %s log entries.', scalar(@tmp)));
if (@tmp) {

0 comments on commit 4729171

Please sign in to comment.