comments: render comments/commenturl in page.tmpl
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Sun, 23 Nov 2008 17:11:14 +0000 (17:11 +0000)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Thu, 11 Dec 2008 21:14:04 +0000 (21:14 +0000)
IkiWiki/Plugin/comments.pm

index 01ee481f596ae517ad06ddb1978a99501e8c4eca..33d8ca8e212aaf4b907c922b6e75cc6897b6b86a 100644 (file)
@@ -399,8 +399,48 @@ sub pagetemplate (@) { #{{{
        if ($template->query(name => 'comments')) {
                my $comments = undef;
 
+               my $comments_pagename = $config{comments_pagename};
+
+               my $open = 0;
+               my $shown = pagespec_match($page,
+                       $config{comments_shown_pagespec},
+                       location => $page);
+
+               if (pagespec_match($page, "*/${comments_pagename}*",
+                               location => $page)) {
+                       $shown = 0;
+                       $open = 0;
+               }
+
+               if (length $config{cgiurl}) {
+                       $open = pagespec_match($page,
+                               $config{comments_open_pagespec},
+                               location => $page);
+               }
+
+               if ($shown) {
+                       eval q{use IkiWiki::Plugin::inline};
+                       error($@) if $@;
+
+                       my @args = (
+                               pages => "internal($page/${comments_pagename}*)",
+                               template => 'comments_display',
+                               show => 0,
+                               reverse => 'yes',
+                               page => $page,
+                               destpage => $params{destpage},
+                       );
+                       $comments = IkiWiki::preprocess_inline(@args);
+               }
+
                if (defined $comments && length $comments) {
-                       $template->param(name => $comments);
+                       $template->param(comments => $comments);
+               }
+
+               if ($open) {
+                       my $commenturl = IkiWiki::cgiurl(do => 'comment',
+                               page => $page);
+                       $template->param(commenturl => $commenturl);
                }
        }
 } # }}}