summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2008-12-17 19:38:02 -0500
committerJoey Hess <joey@gnu.kitenet.net>2008-12-17 19:38:02 -0500
commitcd7ac8f72a43a53aeca3b5e8daf906e990420016 (patch)
tree2a2a0ed6550323fd9b422fccec36f81d907be9ea /IkiWiki/Plugin
parent5feffc8b0b953856052c09dd431984e2e835b439 (diff)
add Comments link when displaying a page inline
This link will supplant the usual Discussion link for pages that have comments enabled.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/comments.pm58
1 files changed, 35 insertions, 23 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 0b3007097..cb5a517a1 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -511,6 +511,24 @@ sub sessioncgi ($$) {
exit;
}
+sub commentsshown ($) {
+ my $page=shift;
+
+ return ! pagespec_match($page, "*/$config{comments_pagename}*",
+ location => $page) &&
+ pagespec_match($page, $config{comments_pagespec},
+ location => $page);
+}
+
+sub commentsopen ($) {
+ my $page = shift;
+
+ return length $config{cgiurl} > 0 &&
+ (! length $config{comments_closed_pagespec} ||
+ ! pagespec_match($page, $config{comments_closed_pagespec},
+ location => $page));
+}
+
sub pagetemplate (@) {
my %params = @_;
@@ -518,29 +536,9 @@ sub pagetemplate (@) {
my $template = $params{template};
if ($template->query(name => 'comments')) {
- my $comments = undef;
-
- my $open = 0;
- my $shown = 0;
- if (pagespec_match($page,
- $config{comments_pagespec},
- location => $page)) {
- $shown = 1;
- $open = length $config{cgiurl} > 0;
- }
-
- if (pagespec_match($page, "*/$config{comments_pagename}*",
- location => $page)) {
- $shown = 0;
- $open = 0;
- }
- if (length $config{comments_closed_pagespec} &&
- pagespec_match($page, $config{comments_closed_pagespec},
- location => $page)) {
- $shown = 0;
- $open = 0;
- }
+ my $shown = commentsshown($page);
+ my $comments = undef;
if ($shown) {
$comments = IkiWiki::preprocess_inline(
pages => "internal($page/$config{comments_pagename}*)",
@@ -558,13 +556,27 @@ sub pagetemplate (@) {
$template->param(comments => $comments);
}
- if ($open) {
+ if ($shown && commentsopen($page)) {
my $commenturl = IkiWiki::cgiurl(do => 'comment',
page => $page);
$template->param(commenturl => $commenturl);
}
}
+ if ($template->query(name => 'commentslink')) {
+ # XXX Would be nice to say how many comments there are in
+ # the link. But, to update the number, blog pages
+ # would have to update whenever comments of any inlines
+ # page are added, which is not currently done.
+ if (commentsshown($page)) {
+ $template->param(commentslink =>
+ htmllink($page, $params{destpage}, $page,
+ linktext => gettext("Comments"),
+ anchor => "comments",
+ noimageinline => 1));
+ }
+ }
+
if ($template->query(name => 'commentuser')) {
$template->param(commentuser =>
$pagestate{$page}{comments}{commentuser});