From 9a32451986c710d1f1ce71217c1f7ab3b84f72bf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 23 Jun 2010 20:12:26 -0400 Subject: [PATCH] finializing openid nickname support Renamed usershort => nickname. Note that this means existing user login sessions will not have the nickname recorded, and so it won't be used for those. --- IkiWiki/Plugin/comments.pm | 8 ++++++-- IkiWiki/Plugin/git.pm | 14 +++++++++----- IkiWiki/Plugin/openid.pm | 14 +++++++------- IkiWiki/Plugin/recentchanges.pm | 2 +- debian/changelog | 10 +++++++--- doc/ikiwiki/directive/comment.mdwn | 2 ++ doc/plugins/write.mdwn | 2 +- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 41c6948e8..d34951570 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -177,7 +177,7 @@ sub preprocess { if (defined $oiduser) { # looks like an OpenID $commentauthorurl = $commentuser; - $commentauthor = $oiduser; + $commentauthor = (defined $params{nickname} && length $params{nickname}) ? $params{nickname} : $oiduser; $commentopenid = $commentuser; } else { @@ -396,12 +396,16 @@ sub editcomment ($$) { my $content = "[[!comment format=$type\n"; - # FIXME: handling of double quotes probably wrong? if (defined $session->param('name')) { my $username = $session->param('name'); $username =~ s/"/"/g; $content .= " username=\"$username\"\n"; } + if (defined $session->param('nickname')) { + my $nickname = $session->param('nickname'); + $nickname =~ s/"/"/g; + $content .= " nickname=\"$nickname\"\n"; + } elsif (defined $session->remote_addr()) { my $ip = $session->remote_addr(); if ($ip =~ m/^([.0-9]+)$/) { diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 3e289e0c3..8d210cb5d 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -606,12 +606,16 @@ sub rcs_recentchanges ($) { push @messages, { line => $line }; } - my $user=$ci->{'author_name'}; - my $usershort=$ci->{'author_username'}; + my $user=$ci->{'author_username'}; my $web_commit = ($ci->{'author'} =~ /\@web>/); + my $nickname; - if ($usershort =~ /:\/\//) { - $usershort=undef; # url; not really short + # Set nickname only if a non-url author_username is available, + # and author_name is an url. + if ($user !~ /:\/\// && defined $ci->{'author_name'} && + $ci->{'author_name'} =~ /:\/\//) { + $nickname=$user; + $user=$ci->{'author_name'}; } # compatability code for old web commit messages @@ -626,7 +630,7 @@ sub rcs_recentchanges ($) { push @rets, { rev => $sha1, user => $user, - usershort => $usershort, + nickname => $nickname, committype => $web_commit ? "web" : "git", when => $when, message => [@messages], diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index f19a559a9..d393afd23 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -187,16 +187,16 @@ sub auth ($$) { $vident->signed_extension_fields('http://openid.net/srv/ax/1.0'), ); } - my $username; + my $nickname; foreach my $ext (@extensions) { foreach my $field (qw{value.email email}) { if (exists $ext->{$field} && defined $ext->{$field} && length $ext->{$field}) { $session->param(email => $ext->{$field}); - if (! defined $username && + if (! defined $nickname && $ext->{$field}=~/(.+)@.+/) { - $username = $1; + $nickname = $1; } last; } @@ -205,14 +205,14 @@ sub auth ($$) { if (exists $ext->{$field} && defined $ext->{$field} && length $ext->{$field}) { - $username=$ext->{$field}; + $nickname=$ext->{$field}; last; } } } - if (defined $username) { - $username=~s/\s+/_/g; - $session->param(username => $username); + if (defined $nickname) { + $nickname=~s/\s+/_/g; + $session->param(nickname => $nickname); } } else { diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 9f188cbff..758b98348 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -118,7 +118,7 @@ sub store ($$$) { my $oiduser=eval { IkiWiki::openiduser($change->{user}) }; if (defined $oiduser) { $change->{authorurl}=$change->{user}; - $change->{user}=defined $change->{usershort} ? $change->{usershort} : $oiduser; + $change->{user}=defined $change->{nickname} ? $change->{nickname} : $oiduser; } elsif (length $config{cgiurl}) { $change->{authorurl} = IkiWiki::cgiurl( diff --git a/debian/changelog b/debian/changelog index dfa862e5b..e41de638f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,16 @@ ikiwiki (3.20100624) UNRELEASED; urgency=low - * API: Add new optional field usershort to rcs_recentchanges. + * Changes to avoid display of ugly google openids, by displaying + a username taken from openid. + * API: Add new optional field nickname to rcs_recentchanges. * API: rcs_commit and rcs_commit_staged are now passed named parameters. + * openid: Store nickname based on username or email provided from + openid provider. + * git: Record the nickname from openid in the git author email. + * comment: Record the username from openid in the comment page. * Fixed some confusion and bugginess about whether rcs_getctime/rcs_getmtime were passed absolute or relative filenames. - * git: Record the username from openid in the git author email. - (This avoids display of ugly google openids.) -- Joey Hess Wed, 23 Jun 2010 15:30:04 -0400 diff --git a/doc/ikiwiki/directive/comment.mdwn b/doc/ikiwiki/directive/comment.mdwn index 693a92770..398130e2e 100644 --- a/doc/ikiwiki/directive/comment.mdwn +++ b/doc/ikiwiki/directive/comment.mdwn @@ -29,6 +29,8 @@ metadata of the comment. nearly any format, since it's parsed by [[!cpan TimeDate]] * `username` - Used to record the username (or OpenID) of a logged in commenter. +* `nickname` - Name to display for a logged in commenter. + (Optional; used for OpenIDs.) * `ip` - Can be used to record the IP address of a commenter, if they posted anonymously. * `claimedauthor` - Records the name that the user entered, diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index a2b954bd4..a921b9a02 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -1108,7 +1108,7 @@ The data structure returned for each change is: { rev => # the RCSs id for this commit user => # user who made the change (may be an openid), - usershort => # short name of user (optional; not an openid), + nickname => # short name for user (optional; not an openid), committype => # either "web" or the name of the rcs, when => # time when the change was made,