- $pagestate{$page}{comments}{comments} = defined $params{closed}
- ? (not IkiWiki::yesno($params{closed}))
- : 1;
- $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives});
- $pagestate{$page}{comments}{commit} = defined $params{commit}
- ? IkiWiki::yesno($params{commit})
- : 1;
-
- my $formtemplate = IkiWiki::template("comments_embed.tmpl",
- blind_cache => 1);
- $formtemplate->param(cgiurl => $config{cgiurl});
- $formtemplate->param(page => $params{page});
-
- if (not $pagestate{$page}{comments}{comments}) {
- $formtemplate->param("disabled" =>
- gettext('comments are closed'));
- }
- elsif ($params{preview}) {
- $formtemplate->param("disabled" =>
- gettext('not available during Preview'));
- }
-
- debug("page $params{page} => destpage $params{destpage}");
-
- unless (defined $params{inline} && !IkiWiki::yesno($params{inline})) {
- my $posts = '';
- eval q{use IkiWiki::Plugin::inline};
- error($@) if ($@);
- my @args = (
- pages => "internal($params{page}/_comment_*)",
- template => "comments_display",
- show => 0,
- reverse => "yes",
- # special stuff passed through
- page => $params{page},
- destpage => $params{destpage},
- preview => $params{preview},
- );
- push @args, atom => $params{atom} if defined $params{atom};
- push @args, rss => $params{rss} if defined $params{rss};
- push @args, feeds => $params{feeds} if defined $params{feeds};
- push @args, feedshow => $params{feedshow} if defined $params{feedshow};
- push @args, timeformat => $params{timeformat} if defined $params{timeformat};
- push @args, feedonly => $params{feedonly} if defined $params{feedonly};
- $posts = IkiWiki::preprocess_inline(@args);
- $formtemplate->param("comments" => $posts);
- }
-
- return $formtemplate->output;
-} # }}}
-
-# FIXME: logic taken from editpage, should be common code?
-sub getcgiuser ($) { # {{{
- my $session = shift;
- my $user = $session->param('name');
- $user = $ENV{REMOTE_ADDR} unless defined $user;
- debug("getcgiuser() -> $user");
- return $user;
-} # }}}
-
-# FIXME: logic adapted from recentchanges, should be common code?
-# returns (author URL, pretty-printed version)
-sub linkuser ($) { # {{{
- my $user = shift;
- my $oiduser = eval { IkiWiki::openiduser($user) };
-
- if (defined $oiduser) {
- return ($user, $oiduser);
+
+ my $format = $params{format};
+ if (defined $format && (! exists $IkiWiki::hooks{htmlize}{$format} ||
+ ! isallowed($format))) {
+ error(sprintf(gettext("unsupported page format %s"), $format));
+ }
+
+ my $content = $params{content};
+ if (! defined $content) {
+ error(gettext("comment must have content"));
+ }
+ $content =~ s/\\"/"/g;
+
+ if (defined wantarray) {
+ if ($config{comments_allowdirectives}) {
+ $content = IkiWiki::preprocess($page, $params{destpage},
+ $content);
+ }
+
+ # no need to bother with htmlize if it's just HTML
+ $content = IkiWiki::htmlize($page, $params{destpage}, $format, $content)
+ if defined $format;
+
+ IkiWiki::run_hooks(sanitize => sub {
+ $content = shift->(
+ page => $page,
+ destpage => $params{destpage},
+ content => $content,
+ );
+ });