The following code simulates a simple forum inside a wiki. Use the "Add Comment" (at the bottom of the page) to reply.
Note: an updated, template-based version may be found here. Once we figure out a way to properly present templates on this wiki, we'll pull it back here.
<p>{{wiki.create("Create New Topic",page.path,_,true,"Put Your Title Here")}}</p>
<table cellspacing="0" cellpadding="4" border="1" block="var topics = [];
foreach (var p in page.subpages) {
var originator = wiki.getuser(web.list(p.api .. '/revisions?revision=1', '/page/user.author/username')[0]);
var originator=(originator.id!=0)?originator:p.author;
var lastAuthor = originator;
var lastDate = date.format(p.date, 's');
if (#p.comments != 0) {
var lastComment = list.reverse(p.comments)[0];
if (date.isafter(lastComment.date,p.date)){
let lastAuthor = lastComment.author;
let lastDate =date.format(lastComment.date, 's');
}
}
let topics ..= [ { page:p, originator:originator, lastAuthor:lastAuthor, lastDate:lastDate } ];
}
let topics = list.sort(topics, 'lastDate', true);" class="table">
<tbody>
<tr>
<th valign="top" style="width: 70%;">Topic/Starter</th>
<th valign="top" style="width: 15%;">Last Post</th>
<th valign="top" style="width: 7%;">#Views</th>
<th valign="top" style="width: 7%;">#Replies</th>
</tr>
<tr foreach="var t in topics" class="{{__count % 2 == 0 ? 'bg1' : 'bg2'}}">
<td valign="top"><font style="font-size: 17px;"><strong>{{web.link(t.page.uri, t.page.title)}}</strong></font> <br />
{{web.link(t.originator.uri, t.originator.name); }}</td>
<td valign="top">{{date.format(t.lastDate,'yyyy-MM-d hh:mm');}} <br />
by {{web.link(t.lastAuthor.uri, t.lastAuthor.name)}}</td>
<td valign="top">{{t.page.viewcount}}</td>
<td valign="top">{{#t.page.comments}}</td>
</tr>
</tbody>
</table>
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by
I have an alternate solution, though, that I will possibly roll into this code when I get a chance. That is, insert the originator and original date into the topic itself using a template. Then, rather than do the API call, the originator can be found by a wiki.page() call. Another benefit is that this will fix the fact that the originator is currently not knowable on the topic page.
I'll get to this soon! :-) edited 16:18, 31 Aug 2008