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);
21 IkiWiki::Plugin::comments::checkconfig();
22 my $comment_num=1 + IkiWiki::Plugin::comments::num_comments($page, $dir);
24 my $username = getpwuid($<);
25 if (! defined $username) { $username="" }
27 my $comment="[[!comment format=mdwn\n";
28 $comment.=" username=\"$username\"\n";
29 $comment.=" subject=\"\"\"comment $comment_num\"\"\"\n";
30 $comment.=" " . IkiWiki::Plugin::comments::commentdate() . "\n";
31 $comment.=" content=\"\"\"\n\n\"\"\"]]\n";
33 # This will yield a hash of the comment before it's edited,
34 # but that's ok; the date provides sufficient entropy to avoid collisions,
35 # and the hash of a comment does not need to match its actual content.
36 # Doing it this way avoids needing to move the file to a final
37 # location after it's edited.
38 my $location=IkiWiki::Plugin::comments::unique_comment_location($page, $comment, $dir)."._comment";
40 IkiWiki::writefile($location, $dir, $comment);
43 if (-x "/usr/bin/editor") {
44 @editor="/usr/bin/editor";
46 if (exists $ENV{EDITOR}) {
47 @editor=split(' ', $ENV{EDITOR});
49 if (exists $ENV{VISUAL}) {
50 @editor=split(' ', $ENV{VISUAL});
52 exec(@editor, "$dir/$location");