2 # Copyright © 2006-2008 Joey Hess <joey@ikiwiki.info>
3 # Copyright © 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
4 # Licensed under the GNU GPL, version 2, or any later version published by the
5 # Free Software Foundation
6 package IkiWiki::Plugin::comments;
13 use constant PREVIEW => "Preview";
14 use constant POST_COMMENT => "Post comment";
15 use constant CANCEL => "Cancel";
21 hook(type => "checkconfig", id => 'comments', call => \&checkconfig);
22 hook(type => "getsetup", id => 'comments', call => \&getsetup);
23 hook(type => "preprocess", id => 'comment', call => \&preprocess,
25 hook(type => "preprocess", id => 'commentmoderation', call => \&preprocess_moderation);
26 # here for backwards compatability with old comments
27 hook(type => "preprocess", id => '_comment', call => \&preprocess);
28 hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi);
29 hook(type => "htmlize", id => "_comment", call => \&htmlize);
30 hook(type => "htmlize", id => "_comment_pending",
31 call => \&htmlize_pending);
32 hook(type => "pagetemplate", id => "comments", call => \&pagetemplate);
33 hook(type => "formbuilder_setup", id => "comments",
34 call => \&formbuilder_setup);
35 # Load goto to fix up user page links for logged-in commenters
36 IkiWiki::loadplugin("goto");
37 IkiWiki::loadplugin("inline");
47 comments_pagespec => {
49 example => 'blog/* and !*/Discussion',
50 description => 'PageSpec of pages where comments are allowed',
51 link => 'ikiwiki/PageSpec',
55 comments_closed_pagespec => {
57 example => 'blog/controversial or blog/flamewar',
58 description => 'PageSpec of pages where posting new comments is not allowed',
59 link => 'ikiwiki/PageSpec',
63 comments_pagename => {
65 default => 'comment_',
66 description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"',
67 safe => 0, # manual page moving required
70 comments_allowdirectives => {
73 description => 'Interpret directives in comments?',
77 comments_allowauthor => {
80 description => 'Allow anonymous commenters to set an author name?',
87 description => 'commit comments to the VCS',
88 # old uncommitted comments are likely to cause
89 # confusion if this is changed
96 $config{comments_commit} = 1
97 unless defined $config{comments_commit};
98 $config{comments_pagespec} = ''
99 unless defined $config{comments_pagespec};
100 $config{comments_closed_pagespec} = ''
101 unless defined $config{comments_closed_pagespec};
102 $config{comments_pagename} = 'comment_'
103 unless defined $config{comments_pagename};
108 return $params{content};
111 sub htmlize_pending {
113 return sprintf(gettext("this comment needs %s"),
115 IkiWiki::cgiurl(do => "commentmoderation").'">'.
116 gettext("moderation").'</a>');
119 # FIXME: copied verbatim from meta
122 if (exists $IkiWiki::Plugin::htmlscrubber::{safe_url_regexp} &&
123 defined $IkiWiki::Plugin::htmlscrubber::safe_url_regexp) {
124 return $url=~/$IkiWiki::Plugin::htmlscrubber::safe_url_regexp/;
133 my $page = $params{page};
135 my $format = $params{format};
136 if (defined $format && ! exists $IkiWiki::hooks{htmlize}{$format}) {
137 error(sprintf(gettext("unsupported page format %s"), $format));
140 my $content = $params{content};
141 if (! defined $content) {
142 error(gettext("comment must have content"));
144 $content =~ s/\\"/"/g;
146 if (defined wantarray) {
147 if ($config{comments_allowdirectives}) {
148 $content = IkiWiki::preprocess($page, $params{destpage},
152 # no need to bother with htmlize if it's just HTML
153 $content = IkiWiki::htmlize($page, $params{destpage}, $format, $content)
156 IkiWiki::run_hooks(sanitize => sub {
159 destpage => $params{destpage},
165 IkiWiki::preprocess($page, $params{destpage}, $content, 1);
168 # set metadata, possibly overriding [[!meta]] directives from the
174 my $commentauthorurl;
176 if (defined $params{username}) {
177 $commentuser = $params{username};
179 my $oiduser = eval { IkiWiki::openiduser($commentuser) };
181 if (defined $oiduser) {
182 # looks like an OpenID
183 $commentauthorurl = $commentuser;
184 $commentauthor = (defined $params{nickname} && length $params{nickname}) ? $params{nickname} : $oiduser;
185 $commentopenid = $commentuser;
188 $commentauthorurl = IkiWiki::cgiurl(
190 page => IkiWiki::userpage($commentuser)
193 $commentauthor = $commentuser;
197 if (defined $params{ip}) {
198 $commentip = $params{ip};
200 $commentauthor = gettext("Anonymous");
203 $commentstate{$page}{commentuser} = $commentuser;
204 $commentstate{$page}{commentopenid} = $commentopenid;
205 $commentstate{$page}{commentip} = $commentip;
206 $commentstate{$page}{commentauthor} = $commentauthor;
207 $commentstate{$page}{commentauthorurl} = $commentauthorurl;
208 $commentstate{$page}{commentauthoravatar} = $params{avatar};
209 if (! defined $pagestate{$page}{meta}{author}) {
210 $pagestate{$page}{meta}{author} = $commentauthor;
212 if (! defined $pagestate{$page}{meta}{authorurl}) {
213 $pagestate{$page}{meta}{authorurl} = $commentauthorurl;
216 if ($config{comments_allowauthor}) {
217 if (defined $params{claimedauthor}) {
218 $pagestate{$page}{meta}{author} = $params{claimedauthor};
221 if (defined $params{url}) {
222 my $url=$params{url};
224 eval q{use URI::Heuristic};
226 $url=URI::Heuristic::uf_uristr($url);
230 $pagestate{$page}{meta}{authorurl} = $url;
235 $pagestate{$page}{meta}{author} = $commentauthor;
236 $pagestate{$page}{meta}{authorurl} = $commentauthorurl;
239 if (defined $params{subject}) {
240 # decode title the same way meta does
241 eval q{use HTML::Entities};
242 $pagestate{$page}{meta}{title} = decode_entities($params{subject});
245 if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
246 $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page})).
247 "#".page_to_id($params{page});
250 eval q{use Date::Parse};
252 my $time = str2time($params{date});
253 $IkiWiki::pagectime{$page} = $time if defined $time;
259 sub preprocess_moderation {
262 $params{desc}=gettext("Comment Moderation")
263 unless defined $params{desc};
265 if (length $config{cgiurl}) {
267 IkiWiki::cgiurl(do => 'commentmoderation').
268 '">'.$params{desc}.'</a>';
271 return $params{desc};
275 sub sessioncgi ($$) {
279 my $do = $cgi->param('do');
280 if ($do eq 'comment') {
281 editcomment($cgi, $session);
283 elsif ($do eq 'commentmoderation') {
284 commentmoderation($cgi, $session);
286 elsif ($do eq 'commentsignin') {
287 IkiWiki::cgi_signin($cgi, $session);
292 # Mostly cargo-culted from IkiWiki::plugin::editpage
293 sub editcomment ($$) {
297 IkiWiki::decode_cgi_utf8($cgi);
299 eval q{use CGI::FormBuilder};
302 my @buttons = (POST_COMMENT, PREVIEW, CANCEL);
303 my $form = CGI::FormBuilder->new(
304 fields => [qw{do sid page subject editcontent type author url}],
307 required => [qw{editcontent}],
310 action => IkiWiki::cgiurl(),
313 template => { template('editcomment.tmpl') },
316 IkiWiki::decode_form_utf8($form);
317 IkiWiki::run_hooks(formbuilder_setup => sub {
318 shift->(title => "comment", form => $form, cgi => $cgi,
319 session => $session, buttons => \@buttons);
321 IkiWiki::decode_form_utf8($form);
323 my $type = $form->param('type');
324 if (defined $type && length $type && $IkiWiki::hooks{htmlize}{$type}) {
325 $type = IkiWiki::possibly_foolish_untaint($type);
328 $type = $config{default_pageext};
333 if (exists $IkiWiki::hooks{htmlize}) {
334 foreach my $key (grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}) {
335 push @page_types, [$key, $IkiWiki::hooks{htmlize}{$key}{longname} || $key];
338 @page_types=sort @page_types;
340 $form->field(name => 'do', type => 'hidden');
341 $form->field(name => 'sid', type => 'hidden', value => $session->id,
343 $form->field(name => 'page', type => 'hidden');
344 $form->field(name => 'subject', type => 'text', size => 72);
345 $form->field(name => 'editcontent', type => 'textarea', rows => 10);
346 $form->field(name => "type", value => $type, force => 1,
347 type => 'select', options => \@page_types);
349 $form->tmpl_param(username => $session->param('name'));
351 if ($config{comments_allowauthor} and
352 ! defined $session->param('name')) {
353 $form->tmpl_param(allowauthor => 1);
354 $form->field(name => 'author', type => 'text', size => '40');
355 $form->field(name => 'url', type => 'text', size => '40');
358 $form->tmpl_param(allowauthor => 0);
359 $form->field(name => 'author', type => 'hidden', value => '',
361 $form->field(name => 'url', type => 'hidden', value => '',
365 if (! defined $session->param('name')) {
366 # Make signinurl work and return here.
367 $form->tmpl_param(signinurl => IkiWiki::cgiurl(do => 'commentsignin'));
368 $session->param(postsignin => $ENV{QUERY_STRING});
369 IkiWiki::cgi_savesession($session);
372 # The untaint is OK (as in editpage) because we're about to pass
373 # it to file_pruned and wiki_file_regexp anyway.
374 my ($page) = $form->field('page')=~/$config{wiki_file_regexp}/;
375 $page = IkiWiki::possibly_foolish_untaint($page);
376 if (! defined $page || ! length $page ||
377 IkiWiki::file_pruned($page)) {
378 error(gettext("bad page name"));
381 $form->title(sprintf(gettext("commenting on %s"),
382 IkiWiki::pagetitle(IkiWiki::basename($page))));
384 $form->tmpl_param('helponformattinglink',
385 htmllink($page, $page, 'ikiwiki/formatting',
387 linktext => 'FormattingHelp'),
388 allowdirectives => $config{allow_directives});
390 if ($form->submitted eq CANCEL) {
391 # bounce back to the page they wanted to comment on, and exit.
392 IkiWiki::redirect($cgi, urlto($page));
396 if (not exists $pagesources{$page}) {
397 error(sprintf(gettext(
398 "page '%s' doesn't exist, so you can't comment"),
402 if (pagespec_match($page, $config{comments_closed_pagespec},
403 location => $page)) {
404 error(sprintf(gettext(
405 "comments on page '%s' are closed"),
409 # Set a flag to indicate that we're posting a comment,
410 # so that postcomment() can tell it should match.
412 IkiWiki::check_canedit($page, $cgi, $session);
415 my $content = "[[!comment format=$type\n";
417 if (defined $session->param('name')) {
418 my $username = $session->param('name');
419 $username =~ s/"/"/g;
420 $content .= " username=\"$username\"\n";
422 if (defined $session->param('nickname')) {
423 my $nickname = $session->param('nickname');
424 $nickname =~ s/"/"/g;
425 $content .= " nickname=\"$nickname\"\n";
427 elsif (defined $session->remote_addr()) {
428 my $ip = $session->remote_addr();
429 if ($ip =~ m/^([.0-9]+)$/) {
430 $content .= " ip=\"$1\"\n";
434 if ($config{comments_allowauthor}) {
435 my $author = $form->field('author');
436 if (defined $author && length $author) {
437 $author =~ s/"/"/g;
438 $content .= " claimedauthor=\"$author\"\n";
440 my $url = $form->field('url');
441 if (defined $url && length $url) {
442 $url =~ s/"/"/g;
443 $content .= " url=\"$url\"\n";
447 my $avatar=getavatar($session->param('name'));
448 if (defined $avatar && length $avatar) {
449 $avatar =~ s/"/"/g;
450 $content .= " avatar=\"$avatar\"\n";
453 my $subject = $form->field('subject');
454 if (defined $subject && length $subject) {
455 $subject =~ s/"/"/g;
458 $subject = "comment ".(num_comments($page, $config{srcdir}) + 1);
460 $content .= " subject=\"$subject\"\n";
462 $content .= " date=\"" . strftime_utf8('%Y-%m-%dT%H:%M:%SZ', gmtime) . "\"\n";
464 my $editcontent = $form->field('editcontent');
465 $editcontent="" if ! defined $editcontent;
466 $editcontent =~ s/\r\n/\n/g;
467 $editcontent =~ s/\r/\n/g;
468 $editcontent =~ s/"/\\"/g;
469 $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n";
471 my $location=unique_comment_location($page, $content, $config{srcdir});
473 # This is essentially a simplified version of editpage:
474 # - the user does not control the page that's created, only the parent
475 # - it's always a create operation, never an edit
476 # - this means that conflicts should never happen
477 # - this means that if they do, rocks fall and everyone dies
479 if ($form->submitted eq PREVIEW) {
480 my $preview=previewcomment($content, $location, $page, time);
481 IkiWiki::run_hooks(format => sub {
482 $preview = shift->(page => $page,
483 content => $preview);
485 $form->tmpl_param(page_preview => $preview);
488 $form->tmpl_param(page_preview => "");
491 if ($form->submitted eq POST_COMMENT && $form->validate) {
492 IkiWiki::checksessionexpiry($cgi, $session);
495 my $ok=IkiWiki::check_content(content => $form->field('editcontent'),
496 subject => $form->field('subject'),
497 $config{comments_allowauthor} ? (
498 author => $form->field('author'),
499 url => $form->field('url'),
509 $location=unique_comment_location($page, $content, $config{srcdir}, "._comment_pending");
510 writefile("$location._comment_pending", $config{srcdir}, $content);
512 # Refresh so anything that deals with pending
513 # comments can be updated.
514 require IkiWiki::Render;
516 IkiWiki::saveindex();
518 IkiWiki::printheader($session);
519 print IkiWiki::cgitemplate($cgi, gettext(gettext("comment stored for moderation")),
521 gettext("Your comment will be posted after moderator review").
526 # FIXME: could probably do some sort of graceful retry
527 # on error? Would require significant unwinding though
528 my $file = "$location._comment";
529 writefile($file, $config{srcdir}, $content);
533 if ($config{rcs} and $config{comments_commit}) {
534 my $message = gettext("Added a comment");
535 if (defined $form->field('subject') &&
536 length $form->field('subject')) {
538 gettext("Added a comment: %s"),
539 $form->field('subject'));
542 IkiWiki::rcs_add($file);
543 IkiWiki::disable_commit_hook();
544 $conflict = IkiWiki::rcs_commit_staged(
548 IkiWiki::enable_commit_hook();
549 IkiWiki::rcs_update();
552 # Now we need a refresh
553 require IkiWiki::Render;
555 IkiWiki::saveindex();
557 # this should never happen, unless a committer deliberately
558 # breaks it or something
559 error($conflict) if defined $conflict;
561 # Jump to the new comment on the page.
562 # The trailing question mark tries to avoid broken
563 # caches and get the most recent version of the page.
564 IkiWiki::redirect($cgi, urlto($page).
565 "?updated#".page_to_id($location));
569 IkiWiki::showform($form, \@buttons, $session, $cgi,
580 eval q{use Libravatar::URL};
582 my $oiduser = eval { IkiWiki::openiduser($user) };
583 my $https=defined $config{url} && $config{url}=~/^https:/;
585 if (defined $oiduser) {
587 $avatar = libravatar_url(openid => $user, https => $https);
590 if (! defined $avatar &&
591 (my $email = IkiWiki::userinfo_get($user, 'email'))) {
593 $avatar = libravatar_url(email => $email, https => $https);
601 sub commentmoderation ($$) {
605 IkiWiki::needsignin($cgi, $session);
606 if (! IkiWiki::is_admin($session->param("name"))) {
607 error(gettext("you are not logged in as an admin"));
610 IkiWiki::decode_cgi_utf8($cgi);
612 if (defined $cgi->param('sid')) {
613 IkiWiki::checksessionexpiry($cgi, $session);
615 my $rejectalldefer=$cgi->param('rejectalldefer');
619 foreach my $id (keys %vars) {
620 if ($id =~ /(.*)\._comment(?:_pending)?$/) {
621 $id=decode_utf8($id);
622 my $action=$cgi->param($id);
623 next if $action eq 'Defer' && ! $rejectalldefer;
625 # Make sure that the id is of a legal
627 my ($f) = $id =~ /$config{wiki_file_regexp}/;
628 if (! defined $f || ! length $f ||
629 IkiWiki::file_pruned($f)) {
630 error("illegal file");
633 my $page=IkiWiki::dirname($f);
634 my $file="$config{srcdir}/$f";
637 $file="$config{wikistatedir}/comments_pending/".$f;
640 if ($action eq 'Accept') {
641 my $content=eval { readfile($file) };
642 next if $@; # file vanished since form was displayed
643 my $dest=unique_comment_location($page, $content, $config{srcdir})."._comment";
644 writefile($dest, $config{srcdir}, $content);
645 if ($config{rcs} and $config{comments_commit}) {
646 IkiWiki::rcs_add($dest);
651 require IkiWiki::Render;
652 IkiWiki::prune($file);
658 if ($config{rcs} and $config{comments_commit}) {
659 my $message = gettext("Comment moderation");
660 IkiWiki::disable_commit_hook();
661 $conflict=IkiWiki::rcs_commit_staged(
665 IkiWiki::enable_commit_hook();
666 IkiWiki::rcs_update();
669 # Now we need a refresh
670 require IkiWiki::Render;
672 IkiWiki::saveindex();
674 error($conflict) if defined $conflict;
679 my ($id, $dir, $ctime)=@{$_};
680 my $content=readfile("$dir/$id");
681 my $preview=previewcomment($content, $id,
687 } sort { $b->[2] <=> $a->[2] } comments_pending();
689 my $template=template("commentmoderation.tmpl");
692 comments => \@comments,
693 cgiurl => IkiWiki::cgiurl(),
695 IkiWiki::printheader($session);
696 my $out=$template->output;
697 IkiWiki::run_hooks(format => sub {
698 $out = shift->(page => "", content => $out);
700 print IkiWiki::cgitemplate($cgi, gettext("comment moderation"), $out);
704 sub formbuilder_setup (@) {
707 my $form=$params{form};
708 if ($form->title eq "preferences" &&
709 IkiWiki::is_admin($params{session}->param("name"))) {
710 push @{$params{buttons}}, "Comment Moderation";
711 if ($form->submitted && $form->submitted eq "Comment Moderation") {
712 commentmoderation($params{cgi}, $params{session});
717 sub comments_pending () {
720 eval q{use File::Find};
724 my $origdir=getcwd();
726 my $find_comments=sub {
729 return unless -d $dir;
731 chdir($dir) || die "chdir $dir: $!";
736 my $file=decode_utf8($_);
738 return if ! length $file || IkiWiki::file_pruned($file)
739 || -l $_ || -d _ || $file !~ /\Q$extension\E$/;
740 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
742 my $ctime=(stat($_))[10];
743 push @ret, [$f, $dir, $ctime];
748 chdir($origdir) || die "chdir $origdir: $!";
751 $find_comments->($config{srcdir}, "._comment_pending");
753 $find_comments->("$config{wikistatedir}/comments_pending/",
759 sub previewcomment ($$$) {
765 # Previewing a comment should implicitly enable comment posting mode.
766 my $oldpostcomment=$postcomment;
769 my $preview = IkiWiki::htmlize($location, $page, '_comment',
770 IkiWiki::linkify($location, $page,
771 IkiWiki::preprocess($location, $page,
772 IkiWiki::filter($location, $page, $content), 0, 1)));
774 my $template = template("comment.tmpl");
775 $template->param(content => $preview);
776 $template->param(ctime => displaytime($time, undef, 1));
777 $template->param(html5 => $config{html5});
779 IkiWiki::run_hooks(pagetemplate => sub {
780 shift->(page => $location,
782 template => $template);
785 $template->param(have_actions => 0);
787 $postcomment=$oldpostcomment;
789 return $template->output;
792 sub commentsshown ($) {
795 return pagespec_match($page, $config{comments_pagespec},
799 sub commentsopen ($) {
802 return length $config{cgiurl} > 0 &&
803 (! length $config{comments_closed_pagespec} ||
804 ! pagespec_match($page, $config{comments_closed_pagespec},
808 sub pagetemplate (@) {
811 my $page = $params{page};
812 my $template = $params{template};
813 my $shown = ($template->query(name => 'commentslink') ||
814 $template->query(name => 'commentsurl') ||
815 $template->query(name => 'atomcommentsurl') ||
816 $template->query(name => 'comments')) &&
817 commentsshown($page);
819 if ($template->query(name => 'comments')) {
820 my $comments = undef;
822 $comments = IkiWiki::preprocess_inline(
823 pages => "comment($page) and !comment($page/*)",
824 template => 'comment',
828 destpage => $params{destpage},
829 feedfile => 'comments',
834 if (defined $comments && length $comments) {
835 $template->param(comments => $comments);
838 if ($shown && commentsopen($page)) {
839 $template->param(addcommenturl => addcommenturl($page));
844 if ($template->query(name => 'commentsurl')) {
845 $template->param(commentsurl =>
846 urlto($page).'#comments');
849 if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) {
850 # This will 404 until there are some comments, but I
851 # think that's probably OK...
852 $template->param(atomcommentsurl =>
853 urlto($page).'comments.atom');
856 if ($template->query(name => 'commentslink')) {
857 my $num=num_comments($page, $config{srcdir});
860 $link = htmllink($page, $params{destpage}, $page,
861 linktext => sprintf(ngettext("%i comment", "%i comments", $num), $num),
862 anchor => "comments",
866 elsif (commentsopen($page)) {
867 $link = "<a href=\"".addcommenturl($page)."\">".
868 #translators: Here "Comment" is a verb;
869 #translators: the user clicks on it to
870 #translators: post a comment.
874 $template->param(commentslink => $link)
879 # everything below this point is only relevant to the comments
881 if (!exists $commentstate{$page}) {
885 if ($template->query(name => 'commentid')) {
886 $template->param(commentid => page_to_id($page));
889 if ($template->query(name => 'commentuser')) {
890 $template->param(commentuser =>
891 $commentstate{$page}{commentuser});
894 if ($template->query(name => 'commentopenid')) {
895 $template->param(commentopenid =>
896 $commentstate{$page}{commentopenid});
899 if ($template->query(name => 'commentip')) {
900 $template->param(commentip =>
901 $commentstate{$page}{commentip});
904 if ($template->query(name => 'commentauthor')) {
905 $template->param(commentauthor =>
906 $commentstate{$page}{commentauthor});
909 if ($template->query(name => 'commentauthorurl')) {
910 $template->param(commentauthorurl =>
911 $commentstate{$page}{commentauthorurl});
914 if ($template->query(name => 'commentauthoravatar')) {
915 $template->param(commentauthoravatar =>
916 $commentstate{$page}{commentauthoravatar});
919 if ($template->query(name => 'removeurl') &&
920 IkiWiki::Plugin::remove->can("check_canremove") &&
921 length $config{cgiurl}) {
922 $template->param(removeurl => IkiWiki::cgiurl(do => 'remove',
924 $template->param(have_actions => 1);
928 sub addcommenturl ($) {
931 return IkiWiki::cgiurl(do => 'comment', page => $page);
934 sub num_comments ($$) {
938 my @comments=glob("$dir/$page/$config{comments_pagename}*._comment");
939 return int @comments;
942 sub unique_comment_location ($$$$) {
944 eval q{use Digest::MD5 'md5_hex'};
946 my $content_md5=md5_hex(Encode::encode_utf8(shift));
948 my $ext=shift || "._comment";
951 my $i = num_comments($page, $dir);
954 $location = "$page/$config{comments_pagename}${i}_${content_md5}";
955 } while (-e "$dir/$location$ext");
961 # Converts a comment page name into a unique, legal html id
962 # attribute value, that can be used as an anchor to link to the
966 eval q{use Digest::MD5 'md5_hex'};
969 return "comment-".md5_hex(Encode::encode_utf8(($page)));
972 package IkiWiki::PageSpec;
974 sub match_postcomment ($$;@) {
978 if (! $postcomment) {
979 return IkiWiki::FailReason->new("not posting a comment");
981 return match_glob($page, $glob, @_);
984 sub match_comment ($$;@) {
988 if (! $postcomment) {
989 # To see if it's a comment, check the source file type.
990 # Deal with comments that were just deleted.
991 my $source=exists $IkiWiki::pagesources{$page} ?
992 $IkiWiki::pagesources{$page} :
993 $IkiWiki::delpagesources{$page};
994 my $type=defined $source ? IkiWiki::pagetype($source) : undef;
995 if (! defined $type || $type ne "_comment") {
996 return IkiWiki::FailReason->new("$page is not a comment");
1000 return match_glob($page, "$glob/*", internal => 1, @_);
1003 sub match_comment_pending ($$;@) {
1007 my $source=exists $IkiWiki::pagesources{$page} ?
1008 $IkiWiki::pagesources{$page} :
1009 $IkiWiki::delpagesources{$page};
1010 my $type=defined $source ? IkiWiki::pagetype($source) : undef;
1011 if (! defined $type || $type ne "_comment_pending") {
1012 return IkiWiki::FailReason->new("$page is not a pending comment");
1015 return match_glob($page, "$glob/*", internal => 1, @_);