]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki-comment.in
(no commit message)
[ikiwiki.git] / ikiwiki-comment.in
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use lib '.'; # For use in nonstandard directory, munged by Makefile.
5 use IkiWiki;
6 use IkiWiki::Plugin::comments;
7
8 sub usage () {
9         die gettext("usage: ikiwiki-comment pagefile"), "\n";
10 }
11
12 my $pagefile=shift || usage ();
13
14 my $dir=IkiWiki::dirname($pagefile);
15 $dir="." unless length $dir;
16 my $page=IkiWiki::basename($pagefile);
17 $page=~s/\.[^.]+$//;
18
19 IkiWiki::Plugin::comments::checkconfig();
20 my $comment_num=1 + IkiWiki::Plugin::comments::num_comments($page, $dir);
21
22 my $username = getpwuid($<);
23 if (! defined $username) { $username="" }
24
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";
30
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";
37
38 IkiWiki::writefile($location, $dir, $comment);
39
40 my @editor="vi";
41 if (-x "/usr/bin/editor") {
42         @editor="/usr/bin/editor";
43 }
44 if (exists $ENV{EDITOR}) {
45         @editor=split(' ', $ENV{EDITOR});
46 }
47 if (exists $ENV{VISUAL}) {
48 @editor=split(' ', $ENV{VISUAL});
49 }
50 exec(@editor, "$dir/$location");