5 use FindBin; use lib $FindBin::Bin; # For use in nonstandard directory, munged by Makefile.
7 use IkiWiki::Plugin::comments;
11 die gettext("usage: ikiwiki-comment pagefile [options]") . "\n";
15 my $pagefile=shift || usage();
16 my $interactive = -t STDIN;
18 my ($format, $username, $subject, $date, $url, $email, $ip);
20 'format:s' => \$format,
21 'username:s' => \$username,
22 'subject:s' => \$subject,
29 my $dir=get_dir($pagefile);
30 my $page=get_page($pagefile);
32 IkiWiki::Plugin::comments::checkconfig();
36 $username ||= get_username();
37 $subject ||= get_subject($page, $dir);
38 $date ||= IkiWiki::Plugin::comments::commentdate();
44 die "must supply username" unless defined $username;
45 $subject ||= get_subject($page, $dir);
46 die "must supply date" unless defined $date;
50 chomp($content = join('', <STDIN>));
53 my $comment=get_comment($format, $username, $subject, $date, $url, $email, $ip, $content);
55 # For interactive use, this will yield a hash of the comment before
56 # it's edited, but that's ok; the date provides sufficient entropy
57 # to avoid collisions, and the hash of a comment does not need to
58 # match its actual content.
59 # Doing it this way avoids needing to move the file to a final
60 # location after it's edited.
61 my $location=IkiWiki::Plugin::comments::unique_comment_location($page, $comment, $dir)."._comment";
63 IkiWiki::writefile($location, $dir, $comment);
64 exec_editor("$dir/$location") if $interactive;
69 my $dir=IkiWiki::dirname($file);
70 $dir="." unless length $dir;
76 my $page=IkiWiki::basename($file);
77 $page=~s/\.[^.]+$// unless -d $file;
82 my $username = getpwuid($<);
83 $username="" unless defined $username;
88 my ($page, $dir) = @_;
89 my $comment_num=1+IkiWiki::Plugin::comments::num_comments($page, $dir);
90 return "comment $comment_num";
94 my ($format, $username, $subject, $date, $url, $email, $ip, $content) = @_;
95 $format = defined $format ? $format = " format=$format" : q{};
96 $content = '' unless defined $content;
97 my $comment="[[!comment$format\n";
98 $comment.=" username=\"$username\"\n";
99 $comment.=" subject=\"\"\"$subject\"\"\"\n";
100 $comment.=" date=\"$date\"\n";
101 $comment.=" url=\"$url\"\n" if defined $url;
102 $comment.=" email=\"$email\"\n" if defined $email;
103 $comment.=" ip=\"$ip\"\n" if defined $ip;
104 $comment.=" content=\"\"\"\n$content\n\"\"\"]]\n";
112 if (-x "/usr/bin/editor") {
113 @editor="/usr/bin/editor";
115 if (exists $ENV{EDITOR}) {
116 @editor=split(' ', $ENV{EDITOR});
118 if (exists $ENV{VISUAL}) {
119 @editor=split(' ', $ENV{VISUAL});
121 exec(@editor, $file);