postcomment: Rename plugin to comments, use *._comment files

The PageSpec is still called "postcomment" since that's what it means.
master
Simon McVittie 2008-11-18 10:17:18 +00:00
parent 3c9ccb406b
commit 3d4aa065d6
7 changed files with 43 additions and 45 deletions

View File

@ -3,22 +3,21 @@
# Copyright © 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/> # Copyright © 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
# Licensed under the GNU GPL, version 2, or any later version published by the # Licensed under the GNU GPL, version 2, or any later version published by the
# Free Software Foundation # Free Software Foundation
package IkiWiki::Plugin::postcomment; package IkiWiki::Plugin::comments;
use warnings; use warnings;
use strict; use strict;
use IkiWiki 2.00; use IkiWiki 2.00;
use constant PLUGIN => "postcomment";
use constant PREVIEW => "Preview"; use constant PREVIEW => "Preview";
use constant POST_COMMENT => "Post comment"; use constant POST_COMMENT => "Post comment";
use constant CANCEL => "Cancel"; use constant CANCEL => "Cancel";
sub import { #{{{ sub import { #{{{
hook(type => "getsetup", id => PLUGIN, call => \&getsetup); hook(type => "getsetup", id => 'comments', call => \&getsetup);
hook(type => "preprocess", id => PLUGIN, call => \&preprocess); hook(type => "preprocess", id => 'comments', call => \&preprocess);
hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi);
hook(type => "htmlize", id => "_".PLUGIN, hook(type => "htmlize", id => "_comment",
call => \&IkiWiki::Plugin::mdwn::htmlize); call => \&IkiWiki::Plugin::mdwn::htmlize);
IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("inline");
IkiWiki::loadplugin("mdwn"); IkiWiki::loadplugin("mdwn");
@ -43,26 +42,25 @@ sub preprocess (@) { #{{{
my %params=@_; my %params=@_;
unless (length $config{cgiurl}) { unless (length $config{cgiurl}) {
error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), error(gettext("[[!comments plugin requires CGI enabled]]"));
PLUGIN));
} }
my $page = $params{page}; my $page = $params{page};
$pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} $pagestate{$page}{comments}{comments} = defined $params{closed}
? (not IkiWiki::yesno($params{closed})) ? (not IkiWiki::yesno($params{closed}))
: 1; : 1;
$pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); $pagestate{$page}{comments}{allowhtml} = IkiWiki::yesno($params{allowhtml});
$pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives});
$pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} $pagestate{$page}{comments}{commit} = defined $params{commit}
? IkiWiki::yesno($params{commit}) ? IkiWiki::yesno($params{commit})
: 1; : 1;
my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", my $formtemplate = IkiWiki::template("comments_embed.tmpl",
blind_cache => 1); blind_cache => 1);
$formtemplate->param(cgiurl => $config{cgiurl}); $formtemplate->param(cgiurl => $config{cgiurl});
$formtemplate->param(page => $params{page}); $formtemplate->param(page => $params{page});
if (not $pagestate{$page}{PLUGIN()}{comments}) { if (not $pagestate{$page}{comments}{comments}) {
$formtemplate->param("disabled" => $formtemplate->param("disabled" =>
gettext('comments are closed')); gettext('comments are closed'));
} }
@ -79,7 +77,7 @@ sub preprocess (@) { #{{{
error($@) if ($@); error($@) if ($@);
my @args = ( my @args = (
pages => "internal($params{page}/_comment_*)", pages => "internal($params{page}/_comment_*)",
template => PLUGIN . "_display", template => "comments_display",
show => 0, show => 0,
reverse => "yes", reverse => "yes",
# special stuff passed through # special stuff passed through
@ -142,7 +140,7 @@ sub sessioncgi ($$) { #{{{
my $session=shift; my $session=shift;
my $do = $cgi->param('do'); my $do = $cgi->param('do');
return unless $do eq PLUGIN; return unless $do eq 'comment';
IkiWiki::decode_cgi_utf8($cgi); IkiWiki::decode_cgi_utf8($cgi);
@ -160,14 +158,14 @@ sub sessioncgi ($$) { #{{{
action => $config{cgiurl}, action => $config{cgiurl},
header => 0, header => 0,
table => 0, table => 0,
template => scalar IkiWiki::template_params(PLUGIN . '_form.tmpl'), template => scalar IkiWiki::template_params('comments_form.tmpl'),
# wtf does this do in editpage? # wtf does this do in editpage?
wikiname => $config{wikiname}, wikiname => $config{wikiname},
); );
IkiWiki::decode_form_utf8($form); IkiWiki::decode_form_utf8($form);
IkiWiki::run_hooks(formbuilder_setup => sub { IkiWiki::run_hooks(formbuilder_setup => sub {
shift->(title => PLUGIN, form => $form, cgi => $cgi, shift->(title => "comment", form => $form, cgi => $cgi,
session => $session, buttons => \@buttons); session => $session, buttons => \@buttons);
}); });
IkiWiki::decode_form_utf8($form); IkiWiki::decode_form_utf8($form);
@ -189,10 +187,10 @@ sub sessioncgi ($$) { #{{{
error(gettext("bad page name")); error(gettext("bad page name"));
} }
my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; my $allow_directives = $pagestate{$page}{comments}{allowdirectives};
my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; my $allow_html = $pagestate{$page}{comments}{allowdirectives};
my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} my $commit_comments = defined $pagestate{$page}{comments}{commit}
? $pagestate{$page}{PLUGIN()}{commit} ? $pagestate{$page}{comments}{commit}
: 1; : 1;
# FIXME: is this right? Or should we be using the candidate subpage # FIXME: is this right? Or should we be using the candidate subpage
@ -214,7 +212,7 @@ sub sessioncgi ($$) { #{{{
"page '%s' doesn't exist, so you can't comment"), "page '%s' doesn't exist, so you can't comment"),
$page)); $page));
} }
if (not $pagestate{$page}{PLUGIN()}{comments}) { if (not $pagestate{$page}{comments}{comments}) {
error(sprintf(gettext( error(sprintf(gettext(
"comments are not enabled on page '%s'"), "comments are not enabled on page '%s'"),
$page)); $page));
@ -227,7 +225,7 @@ sub sessioncgi ($$) { #{{{
exit; exit;
} }
IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session);
my ($authorurl, $author) = linkuser(getcgiuser($session)); my ($authorurl, $author) = linkuser(getcgiuser($session));
@ -255,7 +253,7 @@ sub sessioncgi ($$) { #{{{
# In this template, the [[!meta]] directives should stay at the end, # In this template, the [[!meta]] directives should stay at the end,
# so that they will override anything the user specifies. (For # so that they will override anything the user specifies. (For
# instance, [[!meta author="I can fake the author"]]...) # instance, [[!meta author="I can fake the author"]]...)
my $content_tmpl = template(PLUGIN . '_comment.tmpl'); my $content_tmpl = template('comments_comment.tmpl');
$content_tmpl->param(author => $author); $content_tmpl->param(author => $author);
$content_tmpl->param(authorurl => $authorurl); $content_tmpl->param(authorurl => $authorurl);
$content_tmpl->param(subject => $form->field('subject')); $content_tmpl->param(subject => $form->field('subject'));
@ -272,7 +270,7 @@ sub sessioncgi ($$) { #{{{
if ($form->submitted eq PREVIEW) { if ($form->submitted eq PREVIEW) {
# $fake is a location that has the same number of slashes # $fake is a location that has the same number of slashes
# as the eventual location of this comment. # as the eventual location of this comment.
my $fake = "$page/_" . PLUGIN . "hypothetical"; my $fake = "$page/_comments_hypothetical";
my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', my $preview = IkiWiki::htmlize($fake, $page, 'mdwn',
IkiWiki::linkify($page, $page, IkiWiki::linkify($page, $page,
IkiWiki::preprocess($page, $page, IkiWiki::preprocess($page, $page,
@ -284,7 +282,7 @@ sub sessioncgi ($$) { #{{{
content => $preview); content => $preview);
}); });
my $template = template(PLUGIN . "_display.tmpl"); my $template = template("comments_display.tmpl");
$template->param(content => $preview); $template->param(content => $preview);
$template->param(title => $form->field('subject')); $template->param(title => $form->field('subject'));
$template->param(ctime => displaytime(time)); $template->param(ctime => displaytime(time));
@ -311,7 +309,7 @@ sub sessioncgi ($$) { #{{{
my $file; my $file;
do { do {
$i++; $i++;
$file = "$page/_comment_${i}._" . PLUGIN; $file = "$page/_comment_${i}._comment";
} while (-e "$config{srcdir}/$file"); } while (-e "$config{srcdir}/$file");
# FIXME: could probably do some sort of graceful retry # FIXME: could probably do some sort of graceful retry

View File

@ -373,7 +373,7 @@ span.color {
padding: 2px; padding: 2px;
} }
.postcomment-display .author { font-weight: bold; } .comments-display .author { font-weight: bold; }
.postcomment-display { border: 1px inset #999; margin: 3px; padding: 3px; } .comments-display { border: 1px inset #999; margin: 3px; padding: 3px; }
.postcomment-header { font-style: italic; } .comments-header { font-style: italic; }
.postcomment-subject { font-weight: bold; border-bottom: 1px solid #999; } .comments-subject { font-weight: bold; border-bottom: 1px solid #999; }

View File

@ -1,6 +1,6 @@
<div class="postcomment-display"> <div class="comments-display">
<div class="postcomment-header"> <div class="comments-header">
Posted by Posted by
<TMPL_IF NAME="AUTHOR"> <TMPL_IF NAME="AUTHOR">
<span class="author"> <span class="author">
@ -15,10 +15,10 @@ Posted by
(<TMPL_VAR CTIME>) (<TMPL_VAR CTIME>)
</div> </div>
<div class="postcomment-subject"><TMPL_VAR TITLE></div> <div class="comments-subject"><TMPL_VAR TITLE></div>
<div class="inlinecontent"> <div class="inlinecontent">
<TMPL_VAR CONTENT> <TMPL_VAR CONTENT>
</div> </div>
</div><!--.postcomment-display--> </div><!--.comments-display-->

View File

@ -0,0 +1,7 @@
<div class="comments-embed">
<TMPL_IF NAME=DISABLED>
[Posting comments disabled: <TMPL_VAR NAME=DISABLED>]
<TMPL_ELSE>
<a href="<TMPL_VAR CGIURL ESCAPE=HTML>?do=comment&amp;page=<TMPL_VAR PAGE ESCAPE=URL>">Post a comment</a>
</TMPL_IF>
</div>

View File

@ -1,4 +1,4 @@
<div class="postcomment-form"> <div class="comments-form">
<TMPL_VAR MESSAGE> <TMPL_VAR MESSAGE>
<TMPL_VAR FORM-START> <TMPL_VAR FORM-START>
<TMPL_VAR FIELD-DO> <TMPL_VAR FIELD-DO>
@ -22,4 +22,4 @@ IkiWiki directives ([[!directive]]) are <TMPL_UNLESS NAME="ALLOWDIRECTIVES">not
</div><!-- #preview --> </div><!-- #preview -->
</TMPL_IF> </TMPL_IF>
</div><!-- .postcomment-form --> </div><!-- .comments-form -->

View File

@ -1,7 +0,0 @@
<div class="postcomment-embed">
<TMPL_IF NAME=DISABLED>
[Posting comments disabled: <TMPL_VAR NAME=DISABLED>]
<TMPL_ELSE>
<a href="<TMPL_VAR CGIURL ESCAPE=HTML>?do=postcomment&amp;page=<TMPL_VAR PAGE ESCAPE=URL>">Post a comment</a>
</TMPL_IF>
</div>