+sub pagetemplate (@) { #{{{
+ my %params = @_;
+
+ my $page = $params{page};
+ my $template = $params{template};
+
+ if ($template->query(name => 'comments')) {
+ my $comments = undef;
+
+ my $open = 0;
+ my $shown = pagespec_match($page,
+ $config{comments_shown_pagespec},
+ location => $page);
+
+ if (pagespec_match($page, "*/$config{comments_pagename}*",
+ location => $page)) {
+ $shown = 0;
+ $open = 0;
+ }
+
+ if (length $config{cgiurl}) {
+ $open = pagespec_match($page,
+ $config{comments_open_pagespec},
+ location => $page);
+ }
+
+ if ($shown) {
+ $comments = IkiWiki::preprocess_inline(
+ pages => "internal($page/$config{comments_pagename}*)",
+ template => 'comments_display',
+ show => 0,
+ reverse => 'yes',
+ page => $page,
+ destpage => $params{destpage},
+ feedfile => 'comments',
+ emptyfeeds => 'no',
+ );
+ }
+
+ if (defined $comments && length $comments) {
+ $template->param(comments => $comments);
+ }
+
+ if ($open) {
+ my $commenturl = IkiWiki::cgiurl(do => 'comment',
+ page => $page);
+ $template->param(commenturl => $commenturl);
+ }
+ }
+
+ if ($template->query(name => 'commentuser')) {
+ $template->param(commentuser =>
+ $pagestate{$page}{comments}{commentuser});
+ }
+
+ if ($template->query(name => 'commentip')) {
+ $template->param(commentip =>
+ $pagestate{$page}{comments}{commentip});
+ }
+
+ if ($template->query(name => 'commentauthor')) {
+ $template->param(commentauthor =>
+ $pagestate{$page}{comments}{commentauthor});
+ }
+
+ if ($template->query(name => 'commentauthorurl')) {
+ $template->param(commentauthorurl =>
+ $pagestate{$page}{comments}{commentauthorurl});
+ }
+} # }}}
+