From 3d4aa065d6a689a017c98e7ea8b80da0b65ae361 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 18 Nov 2008 10:17:18 +0000 Subject: [PATCH] postcomment: Rename plugin to comments, use *._comment files The PageSpec is still called "postcomment" since that's what it means. --- .../Plugin/{postcomment.pm => comments.pm} | 54 +++++++++---------- doc/style.css | 8 +-- ...ent_comment.tmpl => comments_comment.tmpl} | 0 ...ent_display.tmpl => comments_display.tmpl} | 8 +-- templates/comments_embed.tmpl | 7 +++ ...stcomment_form.tmpl => comments_form.tmpl} | 4 +- templates/postcomment_embed.tmpl | 7 --- 7 files changed, 43 insertions(+), 45 deletions(-) rename IkiWiki/Plugin/{postcomment.pm => comments.pm} (86%) rename templates/{postcomment_comment.tmpl => comments_comment.tmpl} (100%) rename templates/{postcomment_display.tmpl => comments_display.tmpl} (65%) create mode 100644 templates/comments_embed.tmpl rename templates/{postcomment_form.tmpl => comments_form.tmpl} (90%) delete mode 100644 templates/postcomment_embed.tmpl diff --git a/IkiWiki/Plugin/postcomment.pm b/IkiWiki/Plugin/comments.pm similarity index 86% rename from IkiWiki/Plugin/postcomment.pm rename to IkiWiki/Plugin/comments.pm index 480ca58a5..b57735545 100644 --- a/IkiWiki/Plugin/postcomment.pm +++ b/IkiWiki/Plugin/comments.pm @@ -3,22 +3,21 @@ # Copyright © 2008 Simon McVittie # Licensed under the GNU GPL, version 2, or any later version published by the # Free Software Foundation -package IkiWiki::Plugin::postcomment; +package IkiWiki::Plugin::comments; use warnings; use strict; use IkiWiki 2.00; -use constant PLUGIN => "postcomment"; use constant PREVIEW => "Preview"; use constant POST_COMMENT => "Post comment"; use constant CANCEL => "Cancel"; sub import { #{{{ - hook(type => "getsetup", id => PLUGIN, call => \&getsetup); - hook(type => "preprocess", id => PLUGIN, call => \&preprocess); - hook(type => "sessioncgi", id => PLUGIN, call => \&sessioncgi); - hook(type => "htmlize", id => "_".PLUGIN, + hook(type => "getsetup", id => 'comments', call => \&getsetup); + hook(type => "preprocess", id => 'comments', call => \&preprocess); + hook(type => "sessioncgi", id => 'comment', call => \&sessioncgi); + hook(type => "htmlize", id => "_comment", call => \&IkiWiki::Plugin::mdwn::htmlize); IkiWiki::loadplugin("inline"); IkiWiki::loadplugin("mdwn"); @@ -43,26 +42,25 @@ sub preprocess (@) { #{{{ my %params=@_; unless (length $config{cgiurl}) { - error(sprintf (gettext("[[!%s plugin requires CGI enabled]]"), - PLUGIN)); + error(gettext("[[!comments plugin requires CGI enabled]]")); } my $page = $params{page}; - $pagestate{$page}{PLUGIN()}{comments} = defined $params{closed} + $pagestate{$page}{comments}{comments} = defined $params{closed} ? (not IkiWiki::yesno($params{closed})) : 1; - $pagestate{$page}{PLUGIN()}{allowhtml} = IkiWiki::yesno($params{allowhtml}); - $pagestate{$page}{PLUGIN()}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); - $pagestate{$page}{PLUGIN()}{commit} = defined $params{commit} + $pagestate{$page}{comments}{allowhtml} = IkiWiki::yesno($params{allowhtml}); + $pagestate{$page}{comments}{allowdirectives} = IkiWiki::yesno($params{allowdirectives}); + $pagestate{$page}{comments}{commit} = defined $params{commit} ? IkiWiki::yesno($params{commit}) : 1; - my $formtemplate = IkiWiki::template(PLUGIN . "_embed.tmpl", + my $formtemplate = IkiWiki::template("comments_embed.tmpl", blind_cache => 1); $formtemplate->param(cgiurl => $config{cgiurl}); $formtemplate->param(page => $params{page}); - if (not $pagestate{$page}{PLUGIN()}{comments}) { + if (not $pagestate{$page}{comments}{comments}) { $formtemplate->param("disabled" => gettext('comments are closed')); } @@ -79,7 +77,7 @@ sub preprocess (@) { #{{{ error($@) if ($@); my @args = ( pages => "internal($params{page}/_comment_*)", - template => PLUGIN . "_display", + template => "comments_display", show => 0, reverse => "yes", # special stuff passed through @@ -142,7 +140,7 @@ sub sessioncgi ($$) { #{{{ my $session=shift; my $do = $cgi->param('do'); - return unless $do eq PLUGIN; + return unless $do eq 'comment'; IkiWiki::decode_cgi_utf8($cgi); @@ -160,14 +158,14 @@ sub sessioncgi ($$) { #{{{ action => $config{cgiurl}, header => 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? wikiname => $config{wikiname}, ); IkiWiki::decode_form_utf8($form); IkiWiki::run_hooks(formbuilder_setup => sub { - shift->(title => PLUGIN, form => $form, cgi => $cgi, + shift->(title => "comment", form => $form, cgi => $cgi, session => $session, buttons => \@buttons); }); IkiWiki::decode_form_utf8($form); @@ -189,10 +187,10 @@ sub sessioncgi ($$) { #{{{ error(gettext("bad page name")); } - my $allow_directives = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $allow_html = $pagestate{$page}{PLUGIN()}{allowdirectives}; - my $commit_comments = defined $pagestate{$page}{PLUGIN()}{commit} - ? $pagestate{$page}{PLUGIN()}{commit} + my $allow_directives = $pagestate{$page}{comments}{allowdirectives}; + my $allow_html = $pagestate{$page}{comments}{allowdirectives}; + my $commit_comments = defined $pagestate{$page}{comments}{commit} + ? $pagestate{$page}{comments}{commit} : 1; # 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)); } - if (not $pagestate{$page}{PLUGIN()}{comments}) { + if (not $pagestate{$page}{comments}{comments}) { error(sprintf(gettext( "comments are not enabled on page '%s'"), $page)); @@ -227,7 +225,7 @@ sub sessioncgi ($$) { #{{{ exit; } - IkiWiki::check_canedit($page . "[" . PLUGIN . "]", $cgi, $session); + IkiWiki::check_canedit($page . "[postcomment]", $cgi, $session); my ($authorurl, $author) = linkuser(getcgiuser($session)); @@ -255,7 +253,7 @@ sub sessioncgi ($$) { #{{{ # In this template, the [[!meta]] directives should stay at the end, # so that they will override anything the user specifies. (For # 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(authorurl => $authorurl); $content_tmpl->param(subject => $form->field('subject')); @@ -272,7 +270,7 @@ sub sessioncgi ($$) { #{{{ if ($form->submitted eq PREVIEW) { # $fake is a location that has the same number of slashes # as the eventual location of this comment. - my $fake = "$page/_" . PLUGIN . "hypothetical"; + my $fake = "$page/_comments_hypothetical"; my $preview = IkiWiki::htmlize($fake, $page, 'mdwn', IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, @@ -284,7 +282,7 @@ sub sessioncgi ($$) { #{{{ content => $preview); }); - my $template = template(PLUGIN . "_display.tmpl"); + my $template = template("comments_display.tmpl"); $template->param(content => $preview); $template->param(title => $form->field('subject')); $template->param(ctime => displaytime(time)); @@ -311,7 +309,7 @@ sub sessioncgi ($$) { #{{{ my $file; do { $i++; - $file = "$page/_comment_${i}._" . PLUGIN; + $file = "$page/_comment_${i}._comment"; } while (-e "$config{srcdir}/$file"); # FIXME: could probably do some sort of graceful retry diff --git a/doc/style.css b/doc/style.css index 21ea9492c..70f31d325 100644 --- a/doc/style.css +++ b/doc/style.css @@ -373,7 +373,7 @@ span.color { padding: 2px; } -.postcomment-display .author { font-weight: bold; } -.postcomment-display { border: 1px inset #999; margin: 3px; padding: 3px; } -.postcomment-header { font-style: italic; } -.postcomment-subject { font-weight: bold; border-bottom: 1px solid #999; } +.comments-display .author { font-weight: bold; } +.comments-display { border: 1px inset #999; margin: 3px; padding: 3px; } +.comments-header { font-style: italic; } +.comments-subject { font-weight: bold; border-bottom: 1px solid #999; } diff --git a/templates/postcomment_comment.tmpl b/templates/comments_comment.tmpl similarity index 100% rename from templates/postcomment_comment.tmpl rename to templates/comments_comment.tmpl diff --git a/templates/postcomment_display.tmpl b/templates/comments_display.tmpl similarity index 65% rename from templates/postcomment_display.tmpl rename to templates/comments_display.tmpl index d3eabb3a1..04e0613e0 100644 --- a/templates/postcomment_display.tmpl +++ b/templates/comments_display.tmpl @@ -1,6 +1,6 @@ -
+
-
+
Posted by @@ -15,10 +15,10 @@ Posted by ()
-
+
-
+
diff --git a/templates/comments_embed.tmpl b/templates/comments_embed.tmpl new file mode 100644 index 000000000..cbb9247f2 --- /dev/null +++ b/templates/comments_embed.tmpl @@ -0,0 +1,7 @@ +
+ +[Posting comments disabled: ] + +Post a comment + +
diff --git a/templates/postcomment_form.tmpl b/templates/comments_form.tmpl similarity index 90% rename from templates/postcomment_form.tmpl rename to templates/comments_form.tmpl index 293f0f17e..fbf49be34 100644 --- a/templates/postcomment_form.tmpl +++ b/templates/comments_form.tmpl @@ -1,4 +1,4 @@ -
+
@@ -22,4 +22,4 @@ IkiWiki directives ([[!directive]]) are not
-
+
diff --git a/templates/postcomment_embed.tmpl b/templates/postcomment_embed.tmpl deleted file mode 100644 index eae741214..000000000 --- a/templates/postcomment_embed.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -
- -[Posting comments disabled: ] - -Post a comment - -
-- 2.32.0.93.g670b81a890