1 I would love to see more traditional support for comments in ikiwiki. One
2 way would be to structure data on the discussion page in such a way that a
3 "comment" plugin could parse it and yet the discussion page would still be
4 a valid and usable wiki page.
6 For example if the discussion page looked like this:
8 # Subject of First Comment
9 Posted by [Adam Shand](http://adam.shand.net/) at 10:34PM on 14/04/2007
11 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi consectetuer nunc quis
12 magna. Etiam non est eget sapien vulputate varius. Vivamus magna. Sed justo. Donec
13 pellentesque ultrices urna.
15 # Subject of the Second Comment
16 Posted by [Foo Bar](http://foobar.net/) at 11:41PM on 14/04/2007
18 Quisque lacinia, lorem eget ornare facilisis, enim eros iaculis felis, id volutpat nibh
19 mauris ut felis. Vestibulum risus nibh, adipiscing volutpat, volutpat et, lacinia ut,
20 pede. Maecenas dolor. Vivamus feugiat volutpat ligula.
22 Each header marks the start of a new comment and the line immediately
23 following is the comments meta data (author, email/url, datestamp).
24 Hopefully you could structure it in such a way that the scope
28 * A comment plugin to render the comments in "traditional blog" format .
29 * Possibly even support nesting comments by the header level?
30 * A comment plugin to create a form at the bottom of the page for people to add comments in the appropriate format to the discussion page
31 * Still remain usable and readable by people who work via svn.
32 * When there is ACL support you could mark the discussion page as read only so it could only be updated by the comment plugin (if that's what you wanted)
34 Is this simple enough to be sensible?
38 > Well, if it's going to look like a blog, why not store the data the same
39 > way ikiwiki stores blogs, with a separate page per comment? As already
40 > suggested in [[discussion_page_as_blog]] though there are some things to
41 > be worked out also discussed there.
44 >> I certainly won't be fussy about how it gets implemented, I was just trying to think of the lightest weight most "wiki" solution. :-) -- Adam.
46 >>> As a side note, the feature described above (having a form not to add a page but to expand it in a formated way) would be useful for other things when the content is short (timetracking, sub-todo list items, etc..) --[[hb]]
48 I've been looking into this. I'd like to implement a "blogcomments"
49 plugin. Looking at the code, I think the way to go is to have a
50 formbuilder_setup hook that uses a different template instead of the
51 standard editpage one. That template would not display the editcontent
52 field. The problem that I'm running into is that I need to append the new
53 content to the old one.
55 -- [[MarceloMagallon]]
57 > Anything I can do to help? --[[Joey]]
59 >> Figured it out. Can you comment on the code below? Thanks. -- [[MarceloMagallon]]
61 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...
63 What I ended up doing is write something like this to the page:
65 [[blogcomment from="""Username""" timestamp="""12345""" subject="""Some text""" text="""the text of the comment"""]]
67 Each comment is processed to something like this:
71 <dt>From</dt><dd>Username</dd>
72 <dt>Date</dt><dd>Date (needs fixing)</dd>
73 <dt>Subject</dt><dd>Subject text</dd>
76 <p>Text of the comment...</p>
79 . In this way the comments can be styled using CSS.
81 -- [[MarceloMagallon]]
86 package IkiWiki::Plugin::comments;
93 hook(type => "formbuilder_setup", id => "comments",
94 call => \&formbuilder_setup);
95 hook(type => "preprocess", id => "blogcomment",
96 call => \&preprocess);
99 sub formbuilder_setup (@) { #{{{
101 my $cgi = $params{cgi};
102 my $form = $params{form};
103 my $session = $params{session};
105 my ($page)=$form->field('page');
106 $page=IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($page));
108 # XXX: This needs something to make it blog specific
109 unless ($page =~ m{/discussion$} &&
110 $cgi->param('do') eq 'edit' &&
111 ! exists $form->{title})
116 if (! $form->submitted)
118 $form->template(IkiWiki::template_file("makeblogcomment.tmpl"));
119 $form->field(name => "blogcomment", type => "textarea", rows => 20,
125 if (exists $pagesources{$page}) {
126 $content=readfile(srcfile($pagesources{$page}));
129 my $name=defined $session->param('name') ?
130 $session->param('name') : gettext('Anonymous');
132 my $subject=defined $cgi->param('comments') ?
133 $cgi->param('comments') : '';
134 my $comment=$cgi->param('blogcomment');
136 $content.=qq{[[blogcomment from="""$name""" timestamp="""$timestamp""" subject="""$subject""" text="""$comment"""]]\n\n};
137 $content=~s/\n/\r\n/g;
138 $form->field(name => "editcontent", value => $content, force => 1);
141 sub preprocess (@) { #{{{
144 my ($text, $date, $from, $subject, $r);
146 $text=IkiWiki::preprocess($params{page}, $params{destpage},
147 IkiWiki::filter($params{page}, $params{text}));
148 $from=exists $params{from} ? $params{from} : gettext("Anonymous");
149 $date=localtime($params{timestamp}) if exists $params{timestamp};
150 $subject=$params{subject} if exists $params{subject};
152 $r = qq{<div class="blogcomment"><dl>\n};
153 $r .= '<dt>' . gettext("From") . "</dt><dd>$from</dd>\n" if defined $from;
154 $r .= '<dt>' . gettext("Date") . "</dt><dd>$date</dd>\n" if defined $date;
155 $r .= '<dt>' . gettext("Subject") . "</dt><dd>$subject</dd>\n"
157 $r .= "</dl>\n" . $text . "</div>\n";