]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
comments: if the remove plugin is enabled, append a "Remove comment" link
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
index c9c7b2ed4c8f4eaa09b110426f2619617376f927..1c4ab4895f0e16f90d33b4dbb347ecc7fbc9192c 100644 (file)
@@ -198,8 +198,17 @@ sub preprocess {
                        $pagestate{$page}{meta}{author} = $params{claimedauthor};
                }
 
-               if (defined $params{url} and safeurl($params{url})) {
-                       $pagestate{$page}{meta}{authorurl} = $params{url};
+               if (defined $params{url}) {
+                       my $url=$params{url};
+
+                       eval q{use URI::Heuristic}; 
+                       if (! $@) {
+                               $url=URI::Heuristic::uf_uristr($url);
+                       }
+
+                       if (safeurl($url)) {
+                               $pagestate{$page}{meta}{authorurl} = $url;
+                       }
                }
        }
        else {
@@ -497,7 +506,10 @@ sub sessioncgi ($$) {
                error($conflict) if defined $conflict;
 
                # Jump to the new comment on the page.
-               IkiWiki::redirect($cgi, urlto($page, undef, 1)."#$location");
+               # The trailing question mark tries to avoid broken
+               # caches and get the most recent version of the page.
+               IkiWiki::redirect($cgi, urlto($page, undef, 1)."?updated#$location");
+
        }
        else {
                IkiWiki::showform ($form, \@buttons, $session, $cgi,
@@ -592,6 +604,12 @@ sub pagetemplate (@) {
                }
        }
 
+       # everything below this point is only relevant to the comments
+       # themselves
+       if (!exists $commentstate{$page}) {
+               return;
+       }
+
        if ($template->query(name => 'commentuser')) {
                $template->param(commentuser =>
                        $commentstate{$page}{commentuser});
@@ -616,6 +634,14 @@ sub pagetemplate (@) {
                $template->param(commentauthorurl =>
                        $commentstate{$page}{commentauthorurl});
        }
+
+       if ($template->query(name => 'removeurl') &&
+           IkiWiki::Plugin::remove->can("check_canremove") &&
+           length $config{cgiurl}) {
+               $template->param(removeurl => IkiWiki::cgiurl(do => 'remove',
+                       page => $page));
+               $template->param(have_actions => 1);
+       }
 }
 
 package IkiWiki::PageSpec;