]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
comments: serve avatars over https in https wikis
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
old mode 100644 (file)
new mode 100755 (executable)
index 63e9ab4..2f2a515
@@ -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, https => $ENV{HTTPS});
+                    }
+                }
        }
        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;
        }
@@ -364,16 +376,14 @@ sub editcomment ($$) {
        }
 
        # The untaint is OK (as in editpage) because we're about to pass
-       # it to file_pruned anyway
-       my $page = $form->field('page');
+       # it to file_pruned and wiki_file_regexp anyway.
+       my ($page) = $form->field('page')=~/$config{wiki_file_regexp}/;
        $page = IkiWiki::possibly_foolish_untaint($page);
        if (! defined $page || ! length $page ||
                IkiWiki::file_pruned($page)) {
                error(gettext("bad page name"));
        }
 
-       my $baseurl = urlto($page);
-
        $form->title(sprintf(gettext("commenting on %s"),
                        IkiWiki::pagetitle(IkiWiki::basename($page))));
 
@@ -385,7 +395,7 @@ sub editcomment ($$) {
 
        if ($form->submitted eq CANCEL) {
                # bounce back to the page they wanted to comment on, and exit.
-               IkiWiki::redirect($cgi, $baseurl);
+               IkiWiki::redirect($cgi, urlto($page));
                exit;
        }
 
@@ -506,7 +516,7 @@ sub editcomment ($$) {
                        IkiWiki::saveindex();
 
                        IkiWiki::printheader($session);
-                       print IkiWiki::misctemplate(gettext(gettext("comment stored for moderation")),
+                       print IkiWiki::cgitemplate($cgi, gettext(gettext("comment stored for moderation")),
                                "<p>".
                                gettext("Your comment will be posted after moderator review").
                                "</p>");
@@ -556,8 +566,8 @@ sub editcomment ($$) {
 
        }
        else {
-               IkiWiki::showform ($form, \@buttons, $session, $cgi,
-                       forcebaseurl => $baseurl, page => $page);
+               IkiWiki::showform($form, \@buttons, $session, $cgi,
+                       page => $page);
        }
 
        exit;
@@ -662,7 +672,7 @@ sub commentmoderation ($$) {
        IkiWiki::run_hooks(format => sub {
                $out = shift->(page => "", content => $out);
        });
-       print IkiWiki::misctemplate(gettext("comment moderation"), $out);
+       print IkiWiki::cgitemplate($cgi, gettext("comment moderation"), $out);
        exit;
 }
 
@@ -757,10 +767,8 @@ sub previewcomment ($$$) {
 sub commentsshown ($) {
        my $page=shift;
 
-       return ! pagespec_match($page, "comment(*)",
-                               location => $page) &&
-              pagespec_match($page, $config{comments_pagespec},
-                             location => $page);
+       return pagespec_match($page, $config{comments_pagespec},
+               location => $page);
 }
 
 sub commentsopen ($) {
@@ -787,7 +795,7 @@ sub pagetemplate (@) {
                my $comments = undef;
                if ($shown) {
                        $comments = IkiWiki::preprocess_inline(
-                               pages => "comment($page)",
+                               pages => "comment($page) and !comment($page/*)",
                                template => 'comment',
                                show => 0,
                                reverse => 'yes',
@@ -878,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}) {