4 use lib '.'; # For use in nonstandard directory, munged by Makefile.
6 use IkiWiki::Plugin::comments;
9 die gettext("usage: ikiwiki-comment pagefile"), "\n";
12 my $pagefile=shift || usage ();
14 my $dir=IkiWiki::dirname($pagefile);
15 $dir="." unless length $dir;
16 my $page=IkiWiki::basename($pagefile);
19 IkiWiki::Plugin::comments::checkconfig();
20 my $comment_num=1 + IkiWiki::Plugin::comments::num_comments($page, $dir);
22 my $username = getpwuid($<);
23 if (! defined $username) { $username="" }
25 my $comment="[[!comment format=mdwn\n";
26 $comment.=" username=\"$username\"\n";
27 $comment.=" subject=\"\"\"comment $comment_num\"\"\"\n";
28 $comment.=" " . IkiWiki::Plugin::comments::commentdate() . "\n";
29 $comment.=" content=\"\"\"\n\n\"\"\"]]\n";
31 # This will yield a hash of the comment before it's edited,
32 # but that's ok; the date provides sufficient entropy to avoid collisions,
33 # and the hash of a comment does not need to match its actual content.
34 # Doing it this way avoids needing to move the file to a final
35 # location after it's edited.
36 my $location=IkiWiki::Plugin::comments::unique_comment_location($page, $comment, $dir)."._comment";
38 IkiWiki::writefile($location, $dir, $comment);
41 if (-x "/usr/bin/editor") {
42 @editor="/usr/bin/editor";
44 if (exists $ENV{EDITOR}) {
45 @editor=split(' ', $ENV{EDITOR});
47 if (exists $ENV{VISUAL}) {
48 @editor=split(' ', $ENV{VISUAL});
50 exec(@editor, "$dir/$location");