add Comments link when displaying a page inline
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 18 Dec 2008 00:38:02 +0000 (19:38 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 18 Dec 2008 00:38:02 +0000 (19:38 -0500)
This link will supplant the usual Discussion link for pages
that have comments enabled.

IkiWiki/Plugin/comments.pm
templates/inlinepage.tmpl
templates/page.tmpl

index 0b3007097f77effca18e427b2171051f979c1048..cb5a517a107ea94007f00ae77436d76f69ddbdae 100644 (file)
@@ -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});
index 984d33ceff6298ca81c33eda7075c46bf4b9bb47..3c0b933159b168fe94119a51258b0d0f49baec06 100644 (file)
@@ -58,9 +58,13 @@ License: <TMPL_VAR LICENSE>
 <TMPL_IF NAME="EDITURL">
 <li><a href="<TMPL_VAR EDITURL>" rel="nofollow">Edit</a></li>
 </TMPL_IF>
+<TMPL_IF NAME="COMMENTSLINK">
+<li><TMPL_VAR COMMENTSLINK></li>
+<TMPL_ELSE>
 <TMPL_IF NAME="DISCUSSIONLINK">
 <li><TMPL_VAR DISCUSSIONLINK></li>
 </TMPL_IF>
+</TMPL_IF>
 </ul>
 </div><!--.actions-->
 </TMPL_IF>
index ea50fb722570c9a7fff7855a48ba7ba476802ef8..79c2b8b6ee774fdfafb446869adf5fb9c88fed8b 100644 (file)
 <TMPL_IF COMMENTS>
 <div id="comments">
 <TMPL_VAR COMMENTS>
-</div>
-
 <TMPL_UNLESS COMMENTURL>
 <div class="addcomment">Comments on this page are closed.</div>
 </TMPL_UNLESS>
-</TMPL_IF>
-
 <TMPL_IF COMMENTURL>
 <div class="addcomment">
 <a href="<TMPL_VAR COMMENTURL>">Add a comment</a>
 </div>
 </TMPL_IF>
+</div>
+</TMPL_IF>
 
 <div id="footer" class="pagefooter">
 <div id="pageinfo">