]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki-comment.in
Make the layout adjust to narrow viewports better
[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 if (! -d $pagefile) {
18         $page=~s/\.[^.]+$//;
19 }
20
21 IkiWiki::Plugin::comments::checkconfig();
22 my $comment_num=1 + IkiWiki::Plugin::comments::num_comments($page, $dir);
23
24 my $username = getpwuid($<);
25 if (! defined $username) { $username="" }
26
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";
32
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";
39
40 IkiWiki::writefile($location, $dir, $comment);
41
42 my @editor="vi";
43 if (-x "/usr/bin/editor") {
44         @editor="/usr/bin/editor";
45 }
46 if (exists $ENV{EDITOR}) {
47         @editor=split(' ', $ENV{EDITOR});
48 }
49 if (exists $ENV{VISUAL}) {
50 @editor=split(' ', $ENV{VISUAL});
51 }
52 exec(@editor, "$dir/$location");