add ikiwiki-comment program

master
Joey Hess 2014-10-20 12:08:07 -04:00
parent 13331e8243
commit 82a4fb49ae
6 changed files with 97 additions and 4 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ html/*
ikiwiki.out ikiwiki.out
ikiwiki-transition.out ikiwiki-transition.out
ikiwiki-calendar.out ikiwiki-calendar.out
ikiwiki-comment.out
pm_to_blib pm_to_blib
/MYMETA.json /MYMETA.json
/MYMETA.yml /MYMETA.yml

View File

@ -507,8 +507,7 @@ sub editcomment ($$) {
$subject = "comment ".(num_comments($page, $config{srcdir}) + 1); $subject = "comment ".(num_comments($page, $config{srcdir}) + 1);
} }
$content .= " subject=\"$subject\"\n"; $content .= " subject=\"$subject\"\n";
$content .= " " . commentdate() . "\n";
$content .= " date=\"" . strftime_utf8('%Y-%m-%dT%H:%M:%SZ', gmtime) . "\"\n";
my $editcontent = $form->field('editcontent'); my $editcontent = $form->field('editcontent');
$editcontent="" if ! defined $editcontent; $editcontent="" if ! defined $editcontent;
@ -636,6 +635,10 @@ sub editcomment ($$) {
exit; exit;
} }
sub commentdate () {
"date=\"" . strftime_utf8('%Y-%m-%dT%H:%M:%SZ', gmtime) . "\"";
}
sub getavatar ($) { sub getavatar ($) {
my $user=shift; my $user=shift;
return undef unless defined $user; return undef unless defined $user;
@ -1012,7 +1015,7 @@ sub num_comments ($$) {
return int @comments; return int @comments;
} }
sub unique_comment_location ($$$$) { sub unique_comment_location ($$$;$) {
my $page=shift; my $page=shift;
eval q{use Digest::MD5 'md5_hex'}; eval q{use Digest::MD5 'md5_hex'};
error($@) if $@; error($@) if $@;

View File

@ -24,7 +24,7 @@ MANDIR?=$(PREFIX)/share/man
tflag=$(shell if [ -n "$$NOTAINT" ] && [ "$$NOTAINT" != 1 ]; then printf -- "-T"; fi) tflag=$(shell if [ -n "$$NOTAINT" ] && [ "$$NOTAINT" != 1 ]; then printf -- "-T"; fi)
extramodules=$(shell if [ "$$PROFILE" = 1 ]; then printf -- "-d:NYTProf"; fi) extramodules=$(shell if [ "$$PROFILE" = 1 ]; then printf -- "-d:NYTProf"; fi)
outprogs=ikiwiki.out ikiwiki-transition.out ikiwiki-calendar.out outprogs=ikiwiki.out ikiwiki-transition.out ikiwiki-calendar.out ikiwiki-comment.out
scripts=ikiwiki-update-wikilist ikiwiki-makerepo scripts=ikiwiki-update-wikilist ikiwiki-makerepo
sysconfdir_scripts=ikiwiki-mass-rebuild ikiwiki-update-wikilist sysconfdir_scripts=ikiwiki-mass-rebuild ikiwiki-update-wikilist
shebang_scripts=$(shell $(FIND) . -type f \( -name '*.in' -o -name '*.cgi' -o -name '*.pm' -o -name '*.pm.example' -o -name '*.t' -o -name '*.setup' -o -name 'ikiwiki-mass-rebuild' -o -name 'ikiwiki-update-wikilist' -o -name 'gitremotes' -o -name 'mdwn2man' -o -name 'pm_filter' -o -name 'po2wiki' -o -name 'externaldemo' \)) shebang_scripts=$(shell $(FIND) . -type f \( -name '*.in' -o -name '*.cgi' -o -name '*.pm' -o -name '*.pm.example' -o -name '*.t' -o -name '*.setup' -o -name 'ikiwiki-mass-rebuild' -o -name 'ikiwiki-update-wikilist' -o -name 'gitremotes' -o -name 'mdwn2man' -o -name 'pm_filter' -o -name 'po2wiki' -o -name 'externaldemo' \))
@ -53,6 +53,7 @@ extra_build: perl_shebangs $(outprogs) ikiwiki.setup docwiki sysconfdir
./mdwn2man ikiwiki-transition 1 doc/ikiwiki-transition.mdwn > ikiwiki-transition.man ./mdwn2man ikiwiki-transition 1 doc/ikiwiki-transition.mdwn > ikiwiki-transition.man
./mdwn2man ikiwiki-update-wikilist 1 doc/ikiwiki-update-wikilist.mdwn > ikiwiki-update-wikilist.man ./mdwn2man ikiwiki-update-wikilist 1 doc/ikiwiki-update-wikilist.mdwn > ikiwiki-update-wikilist.man
./mdwn2man ikiwiki-calendar 1 doc/ikiwiki-calendar.mdwn > ikiwiki-calendar.man ./mdwn2man ikiwiki-calendar 1 doc/ikiwiki-calendar.mdwn > ikiwiki-calendar.man
./mdwn2man ikiwiki-comment 1 doc/ikiwiki-comment.mdwn > ikiwiki-comment.man
$(MAKE) -C po $(MAKE) -C po
$(PERL) -pi.bkp -e "s/Version:.*/Version: $(VER)/" ikiwiki.spec $(PERL) -pi.bkp -e "s/Version:.*/Version: $(VER)/" ikiwiki.spec
rm -f ikiwiki.spec.bkp rm -f ikiwiki.spec.bkp
@ -156,6 +157,7 @@ extra_install: underlay_install
install -m 644 ikiwiki-transition.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-transition.1 install -m 644 ikiwiki-transition.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-transition.1
install -m 644 ikiwiki-update-wikilist.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-update-wikilist.1 install -m 644 ikiwiki-update-wikilist.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-update-wikilist.1
install -m 644 ikiwiki-calendar.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-calendar.1 install -m 644 ikiwiki-calendar.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-calendar.1
install -m 644 ikiwiki-comment.man $(DESTDIR)$(MANDIR)/man1/ikiwiki-comment.1
install -d $(DESTDIR)$(MANDIR)/man8 install -d $(DESTDIR)$(MANDIR)/man8
install -m 644 ikiwiki-mass-rebuild.man $(DESTDIR)$(MANDIR)/man8/ikiwiki-mass-rebuild.8 install -m 644 ikiwiki-mass-rebuild.man $(DESTDIR)$(MANDIR)/man8/ikiwiki-mass-rebuild.8

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
ikiwiki (3.20141017) UNRELEASED; urgency=medium
* Added ikiwiki-comment program.
-- Joey Hess <joeyh@debian.org> Mon, 20 Oct 2014 12:04:49 -0400
ikiwiki (3.20141016) unstable; urgency=medium ikiwiki (3.20141016) unstable; urgency=medium
[ Joey Hess ] [ Joey Hess ]

View File

@ -0,0 +1,31 @@
# NAME
ikiwiki-comment - posts a comment
# SYNOPSIS
ikiwiki-comment page.mdwn
# DESCRIPTION
`ikiwiki-comment` creates a comment for the specified wiki page file,
and opens your editor to edit it.
Once you're done, it's up to you to add the comment to whatever version
control system is being used by the wiki, and do any necessary pushing to
publish it.
Note that since ikiwiki-comment is not passed the configuration of
the wiki it's acting on, it doesn't know what types of markup are
available. Instead, it always removes one level of extensions from the
file, so when run on a page.mdwn file, it puts the comment in page/
The username field is set to the unix account name you're using.
You may want to edit it to match the username you use elsewhere
on the wiki.
# AUTHOR
Joey Hess <joey@ikiwiki.info>
Warning: this page is automatically made into ikiwiki-comments's man page, edit with care

50
ikiwiki-comment.in 100755
View File

@ -0,0 +1,50 @@
#!/usr/bin/perl
use warnings;
use strict;
use lib '.'; # For use in nonstandard directory, munged by Makefile.
use IkiWiki;
use IkiWiki::Plugin::comments;
sub usage () {
die gettext("usage: ikiwiki-comment pagefile"), "\n";
}
my $pagefile=shift || usage ();
my $dir=IkiWiki::dirname($pagefile);
$dir="." unless length $dir;
my $page=IkiWiki::basename($pagefile);
$page=~s/\.[^.]+$//;
IkiWiki::Plugin::comments::checkconfig();
my $comment_num=1 + IkiWiki::Plugin::comments::num_comments($page, $dir);
my $username = getpwuid($<);
if (! defined $username) { $username="" }
my $comment="[[!comment format=mdwn\n";
$comment.=" username=\"$username\"\n";
$comment.=" subject=\"\"\"comment $comment_num\"\"\"\n";
$comment.=" " . IkiWiki::Plugin::comments::commentdate() . "\n";
$comment.=" content=\"\"\"\n\n\"\"\"]]\n";
# This will yield a hash of the comment before it's edited,
# but that's ok; the date provides sufficient entropy to avoid collisions,
# and the hash of a comment does not need to match its actual content.
# Doing it this way avoids needing to move the file to a final
# location after it's edited.
my $location=IkiWiki::Plugin::comments::unique_comment_location($page, $comment, $dir)."._comment";
IkiWiki::writefile($location, $dir, $comment);
my @editor="vi";
if (-x "/usr/bin/editor") {
@editor="/usr/bin/editor";
}
if (exists $ENV{EDITOR}) {
@editor=split(' ', $ENV{EDITOR});
}
if (exists $ENV{VISUAL}) {
@editor=split(' ', $ENV{VISUAL});
}
exec(@editor, "$dir/$location");