]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/supporting_comments_via_disussion_pages.mdwn
web commit by http://mem.myopenid.com/: Fix typo and formatting
[ikiwiki.git] / doc / todo / supporting_comments_via_disussion_pages.mdwn
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.
5
6 For example if the discussion page looked like this:
7
8     # Subject of First Comment
9     Posted by [Adam Shand](http://adam.shand.net/) at 10:34PM on 14/04/2007
10
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.
14
15     # Subject of the Second Comment
16     Posted by [Foo Bar](http://foobar.net/) at 11:41PM on 14/04/2007
17
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.
21
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 
25
26 This would allow:
27
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)
33
34 Is this simple enough to be sensible?
35
36 -- [[AdamShand]]
37
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.
42 > --[[Joey]]
43
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.
45
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]]
47
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.
54
55 -- [[MarceloMagallon]]
56
57 > Anything I can do to help? --[[Joey]]
58
59 >> Figured it out.  Can you comment on the code below?  Thanks. -- [[MarceloMagallon]]
60
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...
62
63 What I ended up doing is write something like this to the page:
64
65     [[blogcomment from="""Username""" timestamp="""12345""" subject="""Some text""" text="""the text of the comment"""]]
66
67 Each comment is processed to a <<div>> with a <<dl>> and the text inside it.  In this way the comments can be styled using CSS.
68
69 -- [[MarceloMagallon]]
70
71 # Code
72
73     #!/usr/bin/perl
74     package IkiWiki::Plugin::comments;
75
76     use warnings;
77     use strict;
78     use IkiWiki '1.02';
79
80     sub import { #{{{
81         hook(type => "formbuilder_setup", id => "comments",
82             call => \&formbuilder_setup);
83         hook(type => "preprocess", id => "blogcomment",
84             call => \&preprocess);  
85     } # }}}
86
87     sub formbuilder_setup (@) { #{{{
88         my %params=@_;
89         my $cgi = $params{cgi};
90         my $form = $params{form};   
91         my $session = $params{session};
92
93         my ($page)=$form->field('page');
94         $page=IkiWiki::titlepage(IkiWiki::possibly_foolish_untaint($page));
95
96         # XXX: This needs something to make it blog specific
97         unless ($page =~ m{/discussion$} &&
98                 $cgi->param('do') eq 'edit' &&
99                 ! exists $form->{title})
100         {
101             return;
102         }
103
104         if (! $form->submitted)
105         {
106             $form->template(IkiWiki::template_file("makeblogcomment.tmpl"));
107             $form->field(name => "blogcomment", type => "textarea", rows => 20,
108                 cols => 80);
109             return;
110         }
111
112         my $content="";
113         if (exists $pagesources{$page}) {
114             $content=readfile(srcfile($pagesources{$page}));
115             $content.="\n\n";
116         }
117         my $name=defined $session->param('name') ?
118             $session->param('name') : gettext('Anonymous');
119         my $timestamp=time;
120         my $subject=defined $cgi->param('comments') ?
121             $cgi->param('comments') : '';
122         my $comment=$cgi->param('blogcomment');
123
124         $content.=qq{[[blogcomment from="""$name""" timestamp="""$timestamp""" subject="""$subject""" text="""$comment"""]]\n\n};
125         $content=~s/\n/\r\n/g;
126         $form->field(name => "editcontent", value => $content, force => 1);
127     } # }}}
128
129     sub preprocess (@) { #{{{
130         my %params=@_;
131
132         my ($text, $date, $from, $subject, $r);
133
134         $text=IkiWiki::preprocess($params{page}, $params{destpage},
135                 IkiWiki::filter($params{page}, $params{text}));
136         $from=exists $params{from} ? $params{from} : gettext("Anonymous");
137         $date=localtime($params{timestamp}) if exists $params{timestamp};
138         $subject=$params{subject} if exists $params{subject};
139
140         $r = qq{<div class="blogcomment"><dl>\n};
141         $r .= '<dt>' . gettext("From") . "</dt><dd>$from</dd>\n" if defined $from;
142         $r .= '<dt>' . gettext("Date") . "</dt><dd>$date</dd>\n" if defined $date;
143         $r .= '<dt>' . gettext("Subject") . "</dt><dd>$subject</dd>\n"
144             if defined $subject;
145         $r .= "</dl>\n" . $text . "</div>\n";
146
147         return $r;
148     } # }}}
149     
150     1;