From 7723e94218a8c526fc8d869086c05dd382268649 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Sat, 5 Mar 2011 20:33:07 +1300 Subject: [PATCH 1/3] comments: add avatar picture of comment author Use Libravatar::URL to pull the avatar picture for the comment author if we have an email address for him/her. --- IkiWiki/Plugin/comments.pm | 17 +++++++++++++++++ doc/style.css | 3 +++ templates/comment.tmpl | 5 +++++ 3 files changed, 25 insertions(+) mode change 100644 => 100755 IkiWiki/Plugin/comments.pm diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm old mode 100644 new mode 100755 index 8d46ed579..00ab1c8bd --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -167,6 +167,7 @@ sub preprocess { my $commentip; my $commentauthor; my $commentauthorurl; + my $commentauthoravatar; my $commentopenid; if (defined $params{username}) { $commentuser = $params{username}; @@ -187,6 +188,16 @@ sub preprocess { $commentauthor = $commentuser; } + + eval 'use Libravatar::URL'; + + if (! $@) { + my $email = IkiWiki::userinfo_get($commentuser, 'email'); + + if (defined $email) { + $commentauthoravatar = libravatar_url(email => $email); + } + } } else { if (defined $params{ip}) { @@ -200,6 +211,7 @@ sub preprocess { $commentstate{$page}{commentip} = $commentip; $commentstate{$page}{commentauthor} = $commentauthor; $commentstate{$page}{commentauthorurl} = $commentauthorurl; + $commentstate{$page}{commentauthoravatar} = $commentauthoravatar; if (! defined $pagestate{$page}{meta}{author}) { $pagestate{$page}{meta}{author} = $commentauthor; } @@ -874,6 +886,11 @@ sub pagetemplate (@) { $commentstate{$page}{commentauthorurl}); } + if ($template->query(name => 'commentauthoravatar')) { + $template->param(commentauthoravatar => + $commentstate{$page}{commentauthoravatar}); + } + if ($template->query(name => 'removeurl') && IkiWiki::Plugin::remove->can("check_canremove") && length $config{cgiurl}) { diff --git a/doc/style.css b/doc/style.css index fa413cf24..fcf39be6a 100644 --- a/doc/style.css +++ b/doc/style.css @@ -247,6 +247,9 @@ span.color { .comment-subject { font-weight: bold; } +.comment-avatar { + float: right; +} .comment { border: 1px solid #aaa; padding: 3px; diff --git a/templates/comment.tmpl b/templates/comment.tmpl index c2ee5a371..c16ca7c81 100644 --- a/templates/comment.tmpl +++ b/templates/comment.tmpl @@ -1,6 +1,10 @@
+
+ +
+
@@ -58,4 +62,5 @@ Comment by
+
From 83056abb8788e55041f2ea535236afd20736a659 Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Thu, 24 Mar 2011 21:08:51 +1300 Subject: [PATCH 2/3] comments: serve avatars over https in https wikis --- IkiWiki/Plugin/comments.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 00ab1c8bd..2f2a515b9 100755 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -195,7 +195,7 @@ sub preprocess { my $email = IkiWiki::userinfo_get($commentuser, 'email'); if (defined $email) { - $commentauthoravatar = libravatar_url(email => $email); + $commentauthoravatar = libravatar_url(email => $email, https => $ENV{HTTPS}); } } } From e2e1b1cd20928e2b80871e5daffaea60738d054e Mon Sep 17 00:00:00 2001 From: Francois Marier Date: Sun, 27 Mar 2011 16:22:49 +1300 Subject: [PATCH 3/3] comments: add OpenID-based avatars (libravatar.org) This requires version 1.04 or later of Libravatar::URL. --- IkiWiki/Plugin/comments.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 2f2a515b9..bccb977e3 100755 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -192,9 +192,10 @@ sub preprocess { eval 'use Libravatar::URL'; if (! $@) { - my $email = IkiWiki::userinfo_get($commentuser, 'email'); - - if (defined $email) { + if (defined $commentopenid) { + $commentauthoravatar = libravatar_url(openid => $commentopenid, https => $ENV{HTTPS}); + } + elsif (my $email = IkiWiki::userinfo_get($commentuser, 'email')) { $commentauthoravatar = libravatar_url(email => $email, https => $ENV{HTTPS}); } }