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;
12 use POSIX qw(strftime);
14 use constant PREVIEW => "Preview";
15 use constant POST_COMMENT => "Post comment";
16 use constant CANCEL => "Cancel";
22 hook(type => "checkconfig", id => 'comments', call => \&checkconfig);
23 hook(type => "getsetup", id => 'comments', call => \&getsetup);
24 hook(type => "preprocess", id => 'comment', call => \&preprocess,
26 hook(type => "preprocess", id => 'commentmoderation', call => \&preprocess_moderation);
27 # here for backwards compatability with old comments
28 hook(type => "preprocess", id => '_comment', call => \&preprocess);
29 hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi);
30 hook(type => "htmlize", id => "_comment", call => \&htmlize);
31 hook(type => "htmlize", id => "_comment_pending",
32 call => \&htmlize_pending);
33 hook(type => "pagetemplate", id => "comments", call => \&pagetemplate);
34 hook(type => "formbuilder_setup", id => "comments",
35 call => \&formbuilder_setup);
36 # Load goto to fix up user page links for logged-in commenters
37 IkiWiki::loadplugin("goto");
38 IkiWiki::loadplugin("inline");
48 comments_pagespec => {
50 example => 'blog/* and !*/Discussion',
51 description => 'PageSpec of pages where comments are allowed',
52 link => 'ikiwiki/PageSpec',
56 comments_closed_pagespec => {
58 example => 'blog/controversial or blog/flamewar',
59 description => 'PageSpec of pages where posting new comments is not allowed',
60 link => 'ikiwiki/PageSpec',
64 comments_pagename => {
66 default => 'comment_',
67 description => 'Base name for comments, e.g. "comment_" for pages like "sandbox/comment_12"',
68 safe => 0, # manual page moving required
71 comments_allowdirectives => {
74 description => 'Interpret directives in comments?',
78 comments_allowauthor => {
81 description => 'Allow anonymous commenters to set an author name?',
88 description => 'commit comments to the VCS',
89 # old uncommitted comments are likely to cause
90 # confusion if this is changed
97 $config{comments_commit} = 1
98 unless defined $config{comments_commit};
99 $config{comments_pagespec} = ''
100 unless defined $config{comments_pagespec};
101 $config{comments_closed_pagespec} = ''
102 unless defined $config{comments_closed_pagespec};
103 $config{comments_pagename} = 'comment_'
104 unless defined $config{comments_pagename};
109 return $params{content};
112 sub htmlize_pending {
114 return sprintf(gettext("this comment needs %s"),
116 IkiWiki::cgiurl(do => "commentmoderation").'">'.
117 gettext("moderation").'</a>');
120 # FIXME: copied verbatim from meta
123 if (exists $IkiWiki::Plugin::htmlscrubber::{safe_url_regexp} &&
124 defined $IkiWiki::Plugin::htmlscrubber::safe_url_regexp) {
125 return $url=~/$IkiWiki::Plugin::htmlscrubber::safe_url_regexp/;
134 my $page = $params{page};
136 my $format = $params{format};
137 if (defined $format && ! exists $IkiWiki::hooks{htmlize}{$format}) {
138 error(sprintf(gettext("unsupported page format %s"), $format));
141 my $content = $params{content};
142 if (! defined $content) {
143 error(gettext("comment must have content"));
145 $content =~ s/\\"/"/g;
147 if (defined wantarray) {
148 if ($config{comments_allowdirectives}) {
149 $content = IkiWiki::preprocess($page, $params{destpage},
153 # no need to bother with htmlize if it's just HTML
154 $content = IkiWiki::htmlize($page, $params{destpage}, $format, $content)
157 IkiWiki::run_hooks(sanitize => sub {
160 destpage => $params{destpage},
166 IkiWiki::preprocess($page, $params{destpage}, $content, 1);
169 # set metadata, possibly overriding [[!meta]] directives from the
175 my $commentauthorurl;
177 if (defined $params{username}) {
178 $commentuser = $params{username};
180 my $oiduser = eval { IkiWiki::openiduser($commentuser) };
182 if (defined $oiduser) {
183 # looks like an OpenID
184 $commentauthorurl = $commentuser;
185 $commentauthor = (defined $params{nickname} && length $params{nickname}) ? $params{nickname} : $oiduser;
186 $commentopenid = $commentuser;
189 $commentauthorurl = IkiWiki::cgiurl(
191 page => IkiWiki::userpage($commentuser)
194 $commentauthor = $commentuser;
198 if (defined $params{ip}) {
199 $commentip = $params{ip};
201 $commentauthor = gettext("Anonymous");
204 $commentstate{$page}{commentuser} = $commentuser;
205 $commentstate{$page}{commentopenid} = $commentopenid;
206 $commentstate{$page}{commentip} = $commentip;
207 $commentstate{$page}{commentauthor} = $commentauthor;
208 $commentstate{$page}{commentauthorurl} = $commentauthorurl;
209 $commentstate{$page}{commentauthoravatar} = $params{avatar};
210 if (! defined $pagestate{$page}{meta}{author}) {
211 $pagestate{$page}{meta}{author} = $commentauthor;
213 if (! defined $pagestate{$page}{meta}{authorurl}) {
214 $pagestate{$page}{meta}{authorurl} = $commentauthorurl;
217 if ($config{comments_allowauthor}) {
218 if (defined $params{claimedauthor}) {
219 $pagestate{$page}{meta}{author} = $params{claimedauthor};
222 if (defined $params{url}) {
223 my $url=$params{url};
225 eval q{use URI::Heuristic};
227 $url=URI::Heuristic::uf_uristr($url);
231 $pagestate{$page}{meta}{authorurl} = $url;
236 $pagestate{$page}{meta}{author} = $commentauthor;
237 $pagestate{$page}{meta}{authorurl} = $commentauthorurl;
240 if (defined $params{subject}) {
241 # decode title the same way meta does
242 eval q{use HTML::Entities};
243 $pagestate{$page}{meta}{title} = decode_entities($params{subject});
246 if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
247 $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page})).
248 "#".page_to_id($params{page});
251 eval q{use Date::Parse};
253 my $time = str2time($params{date});
254 $IkiWiki::pagectime{$page} = $time if defined $time;
260 sub preprocess_moderation {
263 $params{desc}=gettext("Comment Moderation")
264 unless defined $params{desc};
266 if (length $config{cgiurl}) {
268 IkiWiki::cgiurl(do => 'commentmoderation').
269 '">'.$params{desc}.'</a>';
272 return $params{desc};
276 sub sessioncgi ($$) {
280 my $do = $cgi->param('do');
281 if ($do eq 'comment') {
282 editcomment($cgi, $session);
284 elsif ($do eq 'commentmoderation') {
285 commentmoderation($cgi, $session);
287 elsif ($do eq 'commentsignin') {
288 IkiWiki::cgi_signin($cgi, $session);
293 # Mostly cargo-culted from IkiWiki::plugin::editpage
294 sub editcomment ($$) {
298 IkiWiki::decode_cgi_utf8($cgi);
300 eval q{use CGI::FormBuilder};
303 my @buttons = (POST_COMMENT, PREVIEW, CANCEL);
304 my $form = CGI::FormBuilder->new(
305 fields => [qw{do sid page subject editcontent type author url}],
308 required => [qw{editcontent}],
311 action => IkiWiki::cgiurl(),
314 template => { template('editcomment.tmpl') },
317 IkiWiki::decode_form_utf8($form);
318 IkiWiki::run_hooks(formbuilder_setup => sub {
319 shift->(title => "comment", form => $form, cgi => $cgi,
320 session => $session, buttons => \@buttons);
322 IkiWiki::decode_form_utf8($form);
324 my $type = $form->param('type');
325 if (defined $type && length $type && $IkiWiki::hooks{htmlize}{$type}) {
326 $type = IkiWiki::possibly_foolish_untaint($type);
329 $type = $config{default_pageext};
334 if (exists $IkiWiki::hooks{htmlize}) {
335 foreach my $key (grep { !/^_/ } keys %{$IkiWiki::hooks{htmlize}}) {
336 push @page_types, [$key, $IkiWiki::hooks{htmlize}{$key}{longname} || $key];
339 @page_types=sort @page_types;
341 $form->field(name => 'do', type => 'hidden');
342 $form->field(name => 'sid', type => 'hidden', value => $session->id,
344 $form->field(name => 'page', type => 'hidden');
345 $form->field(name => 'subject', type => 'text', size => 72);
346 $form->field(name => 'editcontent', type => 'textarea', rows => 10);
347 $form->field(name => "type", value => $type, force => 1,
348 type => 'select', options => \@page_types);
350 $form->tmpl_param(username => $session->param('name'));
352 if ($config{comments_allowauthor} and
353 ! defined $session->param('name')) {
354 $form->tmpl_param(allowauthor => 1);
355 $form->field(name => 'author', type => 'text', size => '40');
356 $form->field(name => 'url', type => 'text', size => '40');
359 $form->tmpl_param(allowauthor => 0);
360 $form->field(name => 'author', type => 'hidden', value => '',
362 $form->field(name => 'url', type => 'hidden', value => '',
366 if (! defined $session->param('name')) {
367 # Make signinurl work and return here.
368 $form->tmpl_param(signinurl => IkiWiki::cgiurl(do => 'commentsignin'));
369 $session->param(postsignin => $ENV{QUERY_STRING});
370 IkiWiki::cgi_savesession($session);
373 # The untaint is OK (as in editpage) because we're about to pass
374 # it to file_pruned and wiki_file_regexp anyway.
375 my ($page) = $form->field('page')=~/$config{wiki_file_regexp}/;
376 $page = IkiWiki::possibly_foolish_untaint($page);
377 if (! defined $page || ! length $page ||
378 IkiWiki::file_pruned($page)) {
379 error(gettext("bad page name"));
382 $form->title(sprintf(gettext("commenting on %s"),
383 IkiWiki::pagetitle(IkiWiki::basename($page))));
385 $form->tmpl_param('helponformattinglink',
386 htmllink($page, $page, 'ikiwiki/formatting',
388 linktext => 'FormattingHelp'),
389 allowdirectives => $config{allow_directives});
391 if ($form->submitted eq CANCEL) {
392 # bounce back to the page they wanted to comment on, and exit.
393 IkiWiki::redirect($cgi, urlto($page));
397 if (not exists $pagesources{$page}) {
398 error(sprintf(gettext(
399 "page '%s' doesn't exist, so you can't comment"),
403 if (pagespec_match($page, $config{comments_closed_pagespec},
404 location => $page)) {
405 error(sprintf(gettext(
406 "comments on page '%s' are closed"),
410 # Set a flag to indicate that we're posting a comment,
411 # so that postcomment() can tell it should match.
413 IkiWiki::check_canedit($page, $cgi, $session);
416 my $content = "[[!comment format=$type\n";
418 if (defined $session->param('name')) {
419 my $username = $session->param('name');
420 $username =~ s/"/"/g;
421 $content .= " username=\"$username\"\n";
423 if (defined $session->param('nickname')) {
424 my $nickname = $session->param('nickname');
425 $nickname =~ s/"/"/g;
426 $content .= " nickname=\"$nickname\"\n";
428 elsif (defined $session->remote_addr()) {
429 my $ip = $session->remote_addr();
430 if ($ip =~ m/^([.0-9]+)$/) {
431 $content .= " ip=\"$1\"\n";
435 if ($config{comments_allowauthor}) {
436 my $author = $form->field('author');
437 if (defined $author && length $author) {
438 $author =~ s/"/"/g;
439 $content .= " claimedauthor=\"$author\"\n";
441 my $url = $form->field('url');
442 if (defined $url && length $url) {
443 $url =~ s/"/"/g;
444 $content .= " url=\"$url\"\n";
448 my $avatar=getavatar($session->param('name'));
449 if (defined $avatar && length $avatar) {
450 $avatar =~ s/"/"/g;
451 $content .= " avatar=\"$avatar\"\n";
454 my $subject = $form->field('subject');
455 if (defined $subject && length $subject) {
456 $subject =~ s/"/"/g;
459 $subject = "comment ".(num_comments($page, $config{srcdir}) + 1);
461 $content .= " subject=\"$subject\"\n";
463 $content .= " date=\"" . decode_utf8(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime)) . "\"\n";
465 my $editcontent = $form->field('editcontent');
466 $editcontent="" if ! defined $editcontent;
467 $editcontent =~ s/\r\n/\n/g;
468 $editcontent =~ s/\r/\n/g;
469 $editcontent =~ s/"/\\"/g;
470 $content .= " content=\"\"\"\n$editcontent\n\"\"\"]]\n";
472 my $location=unique_comment_location($page, $content, $config{srcdir});
474 # This is essentially a simplified version of editpage:
475 # - the user does not control the page that's created, only the parent
476 # - it's always a create operation, never an edit
477 # - this means that conflicts should never happen
478 # - this means that if they do, rocks fall and everyone dies
480 if ($form->submitted eq PREVIEW) {
481 my $preview=previewcomment($content, $location, $page, time);
482 IkiWiki::run_hooks(format => sub {
483 $preview = shift->(page => $page,
484 content => $preview);
486 $form->tmpl_param(page_preview => $preview);
489 $form->tmpl_param(page_preview => "");
492 if ($form->submitted eq POST_COMMENT && $form->validate) {
493 IkiWiki::checksessionexpiry($cgi, $session);
496 my $ok=IkiWiki::check_content(content => $form->field('editcontent'),
497 subject => $form->field('subject'),
498 $config{comments_allowauthor} ? (
499 author => $form->field('author'),
500 url => $form->field('url'),
510 $location=unique_comment_location($page, $content, $config{srcdir}, "._comment_pending");
511 writefile("$location._comment_pending", $config{srcdir}, $content);
513 # Refresh so anything that deals with pending
514 # comments can be updated.
515 require IkiWiki::Render;
517 IkiWiki::saveindex();
519 IkiWiki::printheader($session);
520 print IkiWiki::cgitemplate($cgi, gettext(gettext("comment stored for moderation")),
522 gettext("Your comment will be posted after moderator review").
527 # FIXME: could probably do some sort of graceful retry
528 # on error? Would require significant unwinding though
529 my $file = "$location._comment";
530 writefile($file, $config{srcdir}, $content);
534 if ($config{rcs} and $config{comments_commit}) {
535 my $message = gettext("Added a comment");
536 if (defined $form->field('subject') &&
537 length $form->field('subject')) {
539 gettext("Added a comment: %s"),
540 $form->field('subject'));
543 IkiWiki::rcs_add($file);
544 IkiWiki::disable_commit_hook();
545 $conflict = IkiWiki::rcs_commit_staged(
549 IkiWiki::enable_commit_hook();
550 IkiWiki::rcs_update();
553 # Now we need a refresh
554 require IkiWiki::Render;
556 IkiWiki::saveindex();
558 # this should never happen, unless a committer deliberately
559 # breaks it or something
560 error($conflict) if defined $conflict;
562 # Jump to the new comment on the page.
563 # The trailing question mark tries to avoid broken
564 # caches and get the most recent version of the page.
565 IkiWiki::redirect($cgi, urlto($page).
566 "?updated#".page_to_id($location));
570 IkiWiki::showform($form, \@buttons, $session, $cgi,
581 eval q{use Libravatar::URL};
583 my $oiduser = eval { IkiWiki::openiduser($user) };
584 my $https=defined $config{url} && $config{url}=~/^https:/;
586 if (defined $oiduser) {
588 $avatar = libravatar_url(openid => $user, https => $https);
591 if (! defined $avatar &&
592 (my $email = IkiWiki::userinfo_get($user, 'email'))) {
594 $avatar = libravatar_url(email => $email, https => $https);
602 sub commentmoderation ($$) {
606 IkiWiki::needsignin($cgi, $session);
607 if (! IkiWiki::is_admin($session->param("name"))) {
608 error(gettext("you are not logged in as an admin"));
611 IkiWiki::decode_cgi_utf8($cgi);
613 if (defined $cgi->param('sid')) {
614 IkiWiki::checksessionexpiry($cgi, $session);
616 my $rejectalldefer=$cgi->param('rejectalldefer');
620 foreach my $id (keys %vars) {
621 if ($id =~ /(.*)\._comment(?:_pending)?$/) {
622 $id=decode_utf8($id);
623 my $action=$cgi->param($id);
624 next if $action eq 'Defer' && ! $rejectalldefer;
626 # Make sure that the id is of a legal
628 my ($f) = $id =~ /$config{wiki_file_regexp}/;
629 if (! defined $f || ! length $f ||
630 IkiWiki::file_pruned($f)) {
631 error("illegal file");
634 my $page=IkiWiki::dirname($f);
635 my $file="$config{srcdir}/$f";
638 $file="$config{wikistatedir}/comments_pending/".$f;
641 if ($action eq 'Accept') {
642 my $content=eval { readfile($file) };
643 next if $@; # file vanished since form was displayed
644 my $dest=unique_comment_location($page, $content, $config{srcdir})."._comment";
645 writefile($dest, $config{srcdir}, $content);
646 if ($config{rcs} and $config{comments_commit}) {
647 IkiWiki::rcs_add($dest);
652 require IkiWiki::Render;
653 IkiWiki::prune($file);
659 if ($config{rcs} and $config{comments_commit}) {
660 my $message = gettext("Comment moderation");
661 IkiWiki::disable_commit_hook();
662 $conflict=IkiWiki::rcs_commit_staged(
666 IkiWiki::enable_commit_hook();
667 IkiWiki::rcs_update();
670 # Now we need a refresh
671 require IkiWiki::Render;
673 IkiWiki::saveindex();
675 error($conflict) if defined $conflict;
680 my ($id, $dir, $ctime)=@{$_};
681 my $content=readfile("$dir/$id");
682 my $preview=previewcomment($content, $id,
688 } sort { $b->[2] <=> $a->[2] } comments_pending();
690 my $template=template("commentmoderation.tmpl");
693 comments => \@comments,
694 cgiurl => IkiWiki::cgiurl(),
696 IkiWiki::printheader($session);
697 my $out=$template->output;
698 IkiWiki::run_hooks(format => sub {
699 $out = shift->(page => "", content => $out);
701 print IkiWiki::cgitemplate($cgi, gettext("comment moderation"), $out);
705 sub formbuilder_setup (@) {
708 my $form=$params{form};
709 if ($form->title eq "preferences" &&
710 IkiWiki::is_admin($params{session}->param("name"))) {
711 push @{$params{buttons}}, "Comment Moderation";
712 if ($form->submitted && $form->submitted eq "Comment Moderation") {
713 commentmoderation($params{cgi}, $params{session});
718 sub comments_pending () {
721 eval q{use File::Find};
725 my $origdir=getcwd();
727 my $find_comments=sub {
730 return unless -d $dir;
732 chdir($dir) || die "chdir $dir: $!";
737 my $file=decode_utf8($_);
739 return if ! length $file || IkiWiki::file_pruned($file)
740 || -l $_ || -d _ || $file !~ /\Q$extension\E$/;
741 my ($f) = $file =~ /$config{wiki_file_regexp}/; # untaint
743 my $ctime=(stat($_))[10];
744 push @ret, [$f, $dir, $ctime];
749 chdir($origdir) || die "chdir $origdir: $!";
752 $find_comments->($config{srcdir}, "._comment_pending");
754 $find_comments->("$config{wikistatedir}/comments_pending/",
760 sub previewcomment ($$$) {
766 # Previewing a comment should implicitly enable comment posting mode.
767 my $oldpostcomment=$postcomment;
770 my $preview = IkiWiki::htmlize($location, $page, '_comment',
771 IkiWiki::linkify($location, $page,
772 IkiWiki::preprocess($location, $page,
773 IkiWiki::filter($location, $page, $content), 0, 1)));
775 my $template = template("comment.tmpl");
776 $template->param(content => $preview);
777 $template->param(ctime => displaytime($time, undef, 1));
778 $template->param(html5 => $config{html5});
780 IkiWiki::run_hooks(pagetemplate => sub {
781 shift->(page => $location,
783 template => $template);
786 $template->param(have_actions => 0);
788 $postcomment=$oldpostcomment;
790 return $template->output;
793 sub commentsshown ($) {
796 return pagespec_match($page, $config{comments_pagespec},
800 sub commentsopen ($) {
803 return length $config{cgiurl} > 0 &&
804 (! length $config{comments_closed_pagespec} ||
805 ! pagespec_match($page, $config{comments_closed_pagespec},
809 sub pagetemplate (@) {
812 my $page = $params{page};
813 my $template = $params{template};
814 my $shown = ($template->query(name => 'commentslink') ||
815 $template->query(name => 'commentsurl') ||
816 $template->query(name => 'atomcommentsurl') ||
817 $template->query(name => 'comments')) &&
818 commentsshown($page);
820 if ($template->query(name => 'comments')) {
821 my $comments = undef;
823 $comments = IkiWiki::preprocess_inline(
824 pages => "comment($page) and !comment($page/*)",
825 template => 'comment',
829 destpage => $params{destpage},
830 feedfile => 'comments',
835 if (defined $comments && length $comments) {
836 $template->param(comments => $comments);
839 if ($shown && commentsopen($page)) {
840 $template->param(addcommenturl => addcommenturl($page));
845 if ($template->query(name => 'commentsurl')) {
846 $template->param(commentsurl =>
847 urlto($page).'#comments');
850 if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) {
851 # This will 404 until there are some comments, but I
852 # think that's probably OK...
853 $template->param(atomcommentsurl =>
854 urlto($page).'comments.atom');
857 if ($template->query(name => 'commentslink')) {
858 my $num=num_comments($page, $config{srcdir});
861 $link = htmllink($page, $params{destpage}, $page,
862 linktext => sprintf(ngettext("%i comment", "%i comments", $num), $num),
863 anchor => "comments",
867 elsif (commentsopen($page)) {
868 $link = "<a href=\"".addcommenturl($page)."\">".
869 #translators: Here "Comment" is a verb;
870 #translators: the user clicks on it to
871 #translators: post a comment.
875 $template->param(commentslink => $link)
880 # everything below this point is only relevant to the comments
882 if (!exists $commentstate{$page}) {
886 if ($template->query(name => 'commentid')) {
887 $template->param(commentid => page_to_id($page));
890 if ($template->query(name => 'commentuser')) {
891 $template->param(commentuser =>
892 $commentstate{$page}{commentuser});
895 if ($template->query(name => 'commentopenid')) {
896 $template->param(commentopenid =>
897 $commentstate{$page}{commentopenid});
900 if ($template->query(name => 'commentip')) {
901 $template->param(commentip =>
902 $commentstate{$page}{commentip});
905 if ($template->query(name => 'commentauthor')) {
906 $template->param(commentauthor =>
907 $commentstate{$page}{commentauthor});
910 if ($template->query(name => 'commentauthorurl')) {
911 $template->param(commentauthorurl =>
912 $commentstate{$page}{commentauthorurl});
915 if ($template->query(name => 'commentauthoravatar')) {
916 $template->param(commentauthoravatar =>
917 $commentstate{$page}{commentauthoravatar});
920 if ($template->query(name => 'removeurl') &&
921 IkiWiki::Plugin::remove->can("check_canremove") &&
922 length $config{cgiurl}) {
923 $template->param(removeurl => IkiWiki::cgiurl(do => 'remove',
925 $template->param(have_actions => 1);
929 sub addcommenturl ($) {
932 return IkiWiki::cgiurl(do => 'comment', page => $page);
935 sub num_comments ($$) {
939 my @comments=glob("$dir/$page/$config{comments_pagename}*._comment");
940 return int @comments;
943 sub unique_comment_location ($$$$) {
945 eval q{use Digest::MD5 'md5_hex'};
947 my $content_md5=md5_hex(Encode::encode_utf8(shift));
949 my $ext=shift || "._comment";
952 my $i = num_comments($page, $dir);
955 $location = "$page/$config{comments_pagename}${i}_${content_md5}";
956 } while (-e "$dir/$location$ext");
962 # Converts a comment page name into a unique, legal html id
963 # attribute value, that can be used as an anchor to link to the
967 eval q{use Digest::MD5 'md5_hex'};
970 return "comment-".md5_hex(Encode::encode_utf8(($page)));
973 package IkiWiki::PageSpec;
975 sub match_postcomment ($$;@) {
979 if (! $postcomment) {
980 return IkiWiki::FailReason->new("not posting a comment");
982 return match_glob($page, $glob, @_);
985 sub match_comment ($$;@) {
989 if (! $postcomment) {
990 # To see if it's a comment, check the source file type.
991 # Deal with comments that were just deleted.
992 my $source=exists $IkiWiki::pagesources{$page} ?
993 $IkiWiki::pagesources{$page} :
994 $IkiWiki::delpagesources{$page};
995 my $type=defined $source ? IkiWiki::pagetype($source) : undef;
996 if (! defined $type || $type ne "_comment") {
997 return IkiWiki::FailReason->new("$page is not a comment");
1001 return match_glob($page, "$glob/*", internal => 1, @_);
1004 sub match_comment_pending ($$;@) {
1008 my $source=exists $IkiWiki::pagesources{$page} ?
1009 $IkiWiki::pagesources{$page} :
1010 $IkiWiki::delpagesources{$page};
1011 my $type=defined $source ? IkiWiki::pagetype($source) : undef;
1012 if (! defined $type || $type ne "_comment_pending") {
1013 return IkiWiki::FailReason->new("$page is not a pending comment");
1016 return match_glob($page, "$glob/*", internal => 1, @_);