X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/c2b0cebcd13d185b44b05955cc8dbcc9da25c658..376944cb026945ab597db01eb1e3aea4fa320007:/doc/todo/supporting_comments_via_disussion_pages.mdwn?ds=sidebyside
diff --git a/doc/todo/supporting_comments_via_disussion_pages.mdwn b/doc/todo/supporting_comments_via_disussion_pages.mdwn
index e1f4f2786..50bc17ba3 100644
--- a/doc/todo/supporting_comments_via_disussion_pages.mdwn
+++ b/doc/todo/supporting_comments_via_disussion_pages.mdwn
@@ -58,69 +58,105 @@ content to the old one.
>> Figured it out. Can you comment on the code below? Thanks. -- [[MarceloMagallon]]
+So, I have some code, included below. For some reason that I don't quite get it's not updating the wiki page after a submit. Maybe it's something silly on my side...
+
+What I ended up doing is write something like this to the page:
+
+ [[blogcomment from="""Username""" timestamp="""12345""" subject="""Some text""" text="""the text of the comment"""]]
+
+Each comment is processed to something like this:
+
+
+
+ - From
- Username
+ - Date
- Date (needs fixing)
+ - Subject
- Subject text
+
+
+
Text of the comment...
+
+
+. In this way the comments can be styled using CSS.
+
+-- [[MarceloMagallon]]
+
+# Code
+
+ #!/usr/bin/perl
+ package IkiWiki::Plugin::comments;
+
+ use warnings;
+ use strict;
+ use IkiWiki '1.02';
+
+ sub import { #{{{
+ hook(type => "formbuilder_setup", id => "comments",
+ call => \&formbuilder_setup);
+ hook(type => "preprocess", id => "blogcomment",
+ call => \&preprocess);
+ } # }}}
+
sub formbuilder_setup (@) { #{{{
my %params=@_;
my $cgi = $params{cgi};
- my $form = $params{form};
+ my $form = $params{form};
my $session = $params{session};
+ my ($page)=$form->field('page');
+ $page=IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($page));
+
# XXX: This needs something to make it blog specific
- unless ($cgi->param('page') =~ m{/discussion$} &&
+ unless ($page =~ m{/discussion$} &&
$cgi->param('do') eq 'edit' &&
- ! defined $form->{title})
+ ! exists $form->{title})
{
return;
}
- $form->template(IkiWiki::template_file("makeblogcomment.tmpl"));
- $form->field(name => "blogcomment", type => "textarea", rows => 20,
+ if (! $form->submitted)
+ {
+ $form->template(IkiWiki::template_file("makeblogcomment.tmpl"));
+ $form->field(name => "blogcomment", type => "textarea", rows => 20,
cols => 80);
+ return;
+ }
- my ($page)=$form->field('page');
my $content="";
if (exists $pagesources{$page}) {
$content=readfile(srcfile($pagesources{$page}));
$content.="\n\n";
}
- $content.="----\n\n";
- my $name=$session->param('name');
- $name||="Anonymous";
- $content.=sprintf(gettext("From: %s\n\n"), $name);
- $content.=sprintf(gettext("Date: %s\n\n"), scalar(localtime));
- if (defined $cgi->param('comments'))
- {
- $content.=sprintf(gettext("Subject: %s\n\n"),
- $cgi->param('comments'));
- }
- $content.=$cgi->param('blogcomment');
+ my $name=defined $session->param('name') ?
+ $session->param('name') : gettext('Anonymous');
+ my $timestamp=time;
+ my $subject=defined $cgi->param('comments') ?
+ $cgi->param('comments') : '';
+ my $comment=$cgi->param('blogcomment');
+
+ $content.=qq{[[blogcomment from="""$name""" timestamp="""$timestamp""" subject="""$subject""" text="""$comment"""]]\n\n};
$content=~s/\n/\r\n/g;
$form->field(name => "editcontent", value => $content, force => 1);
} # }}}
-The above produces a page that looks like this:
-
- From: Marcelo
-
- Date: Fri Apr 27 21:16:27 2007
-
- Subject: Pi
-
- 3.14
-
- ----
-
- From: Marcelo
-
- Date: Fri Apr 27 21:20:21 2007
-
- Subject:
-
- A comment...
+ sub preprocess (@) { #{{{
+ my %params=@_;
-Questions:
+ my ($text, $date, $from, $subject, $r);
- * Notice how this assumes that the page it's writing to is in mdwn format.
+ $text=IkiWiki::preprocess($params{page}, $params{destpage},
+ IkiWiki::filter($params{page}, $params{text}));
+ $from=exists $params{from} ? $params{from} : gettext("Anonymous");
+ $date=localtime($params{timestamp}) if exists $params{timestamp};
+ $subject=$params{subject} if exists $params{subject};
- * What to do about the bit marked XXX?
+ $r = qq{\n";
- * What about special formatting? Is mdwn enough?
+ return $r;
+ } # }}}
+
+ 1;
\ No newline at end of file
\n}; + $r .= '- ' . gettext("From") . "
- $from
\n" if defined $from;
+ $r .= '- ' . gettext("Date") . "
- $date
\n" if defined $date;
+ $r .= '- ' . gettext("Subject") . "
- $subject
\n"
+ if defined $subject;
+ $r .= "
\n" . $text . "