4 * Functions pertaining to rooms with a wiki view
11 * Convert a string to something suitable as a wiki index
13 void str_wiki_index(char *s)
17 if (s == NULL) return;
19 /* First remove all non-alphanumeric characters */
20 for (i=0; i<strlen(s); ++i) {
22 strcpy(&s[i], &s[i+1]);
26 /* Then make everything lower case */
27 for (i=0; i<strlen(s); ++i) {
33 * Display a specific page from a wiki room
35 * "rev" may be set to an empty string to display the current version.
36 * "do_revert" may be set to nonzero to perform a reversion to the specified version.
38 void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev, int do_revert)
44 str_wiki_index(pagename);
46 if (StrLength(roomname) > 0) {
48 /* If we're not in the correct room, try going there. */
49 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
53 /* If we're still not in the correct room, it doesn't exist. */
54 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
55 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
61 if (WC->CurRoom.view != VIEW_WIKI) {
62 wc_printf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
66 if (IsEmptyStr(pagename)) {
67 strcpy(pagename, "home");
70 /* Found it! Now read it. */
72 if ((rev != NULL) && (strlen(rev) > 0)) {
73 /* read an older revision */
74 serv_printf("WIKI rev|%s|%s|%s", pagename, rev, (do_revert ? "revert" : "fetch") );
75 serv_getln(buf, sizeof buf);
77 msgnum = extract_long(&buf[4], 0);
81 /* read the current revision? */
82 msgnum = locate_message_by_uid(pagename);
86 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
90 wc_printf("<br /><br />"
91 "<div align=\"center\">"
92 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
93 "<tr><td align=\"center\">"
96 wc_printf(_("There is no page called '%s' here."), pagename);
97 wc_printf("</b><br><br>");
98 wc_printf(_("Select the 'Edit this page' link in the room banner "
99 "if you would like to create this page."));
100 wc_printf("<br><br>");
101 wc_printf("</td></tr></table></div>\n");
106 * Display a specific page from a wiki room
108 void display_wiki_page(void)
110 const StrBuf *roomname;
115 output_headers(1, 1, 1, 0, 0, 0);
116 roomname = sbstr("room");
117 safestrncpy(pagename, bstr("page"), sizeof pagename);
118 safestrncpy(rev, bstr("rev"), sizeof rev);
119 do_revert = atoi(bstr("revert"));
120 display_wiki_page_backend(roomname, pagename, rev, do_revert);
126 * Display the revision history for a wiki page (template callback)
128 void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
130 const StrBuf *roomname;
135 roomname = sbstr("room");
136 safestrncpy(pagename, bstr("page"), sizeof pagename);
137 str_wiki_index(pagename);
139 if (StrLength(roomname) > 0) {
141 /* If we're not in the correct room, try going there. */
142 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
146 /* If we're still not in the correct room, it doesn't exist. */
147 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
148 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
154 serv_printf("WIKI history|%s", pagename);
156 StrBuf_ServGetln(Buf);
157 if (GetServerStatus(Buf, NULL) == 1) {
160 char rev_date_displayed[64];
161 StrBuf *rev_uuid = NewStrBuf();
162 StrBuf *author = NewStrBuf();
163 StrBuf *node = NewStrBuf();
165 wc_printf("<div class=\"fix_scrollbar_bug\">"
166 "<table class=\"wiki_history_background\">"
169 wc_printf("<th>%s</th>", _("Date"));
170 wc_printf("<th>%s</th>", _("Author"));
172 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
174 rev_date = extract_long(ChrPtr(Buf), 1);
175 webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL);
176 StrBufExtract_token(author, Buf, 2, '|');
178 wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD"));
179 wc_printf("<td>%s</td><td>", rev_date_displayed);
180 if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
181 escputs(ChrPtr(author));
183 escputs(ChrPtr(node));
186 wc_printf("<a href=\"showuser?who=");
187 urlescputs(ChrPtr(author));
189 escputs(ChrPtr(author));
195 wc_printf("<td><a href=\"wiki?page=%s\">%s</a></td>",
199 wc_printf("<td>(%s)</td>", _("Current version"));
203 wc_printf("<td><a href=\"wiki?page=%s?rev=%s\">%s</a></td>",
208 wc_printf("<td><a href=\"wiki?page=%s?rev=%s?revert=1\">%s</a></td>",
214 wc_printf("</tr>\n");
216 /* Extract all fields except the author and date after displaying the row. This
217 * is deliberate, because the timestamp reflects when the diff was written, not
218 * when the version which it reflects was written. Similarly, the name associated
219 * with each diff is the author who created the newer version of the page that
220 * made the diff happen.
222 StrBufExtract_token(rev_uuid, Buf, 0, '|');
223 StrBufExtract_token(node, Buf, 3, '|');
227 wc_printf("</table>\n");
230 FreeStrBuf(&rev_uuid);
233 wc_printf("%s", ChrPtr(Buf));
242 * Display the revision history for a wiki page
244 void display_wiki_history(void)
246 output_headers(1, 1, 1, 0, 0, 0);
247 do_template("wiki_history", NULL);
253 * Display a list of all pages in a Wiki room (template callback)
255 void tmplput_display_wiki_pagelist(StrBuf *Target, WCTemplputParams *TP)
257 const StrBuf *roomname;
261 roomname = sbstr("room");
262 if (StrLength(roomname) > 0) {
263 /* If we're not in the correct room, try going there. */
264 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
268 /* If we're still not in the correct room, it doesn't exist. */
269 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
270 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
275 if (!IsEmptyStr(bstr("query"))) {
276 serv_printf("MSGS SEARCH|%s||4", bstr("query")); /* search-reduced list */
279 serv_printf("MSGS ALL|||4"); /* full list */
283 StrBuf_ServGetln(Buf);
284 if (GetServerStatus(Buf, NULL) == 1) {
285 StrBuf *pagetitle = NewStrBuf();
287 wc_printf("<div class=\"fix_scrollbar_bug\">"
288 "<table class=\"wiki_pagelist_background\">"
291 wc_printf("<th>%s</th>", _("Page title"));
293 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
294 StrBufExtract_token(pagetitle, Buf, 1, '|');
296 if (!bmstrcasestr((char *)ChrPtr(pagetitle), "_HISTORY_")) { /* no history pages */
297 wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD"));
298 wc_printf("<td><a href=\"wiki?page=");
299 urlescputs(ChrPtr(pagetitle));
301 escputs(ChrPtr(pagetitle));
302 wc_printf("</a></td>");
303 wc_printf("</tr>\n");
307 wc_printf("</table>\n");
308 FreeStrBuf(&pagetitle);
316 * Display a list of all pages in a Wiki room. Search requests in a Wiki room also go here.
318 void display_wiki_pagelist(void)
320 output_headers(1, 1, 1, 0, 0, 0);
321 do_template("wiki_pagelist", NULL);
326 int wiki_Cleanup(void **ViewSpecific)
329 safestrncpy(pagename, "home", sizeof pagename);
330 display_wiki_page_backend(WC->CurRoom.name, pagename, "", 0);
339 RegisterReadLoopHandlerset(
349 WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
350 WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
351 WebcitAddUrlHandler(HKEY("wiki_pagelist"), "", 0, display_wiki_pagelist, 0);
352 RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);
353 RegisterNamespace("WIKI:DISPLAYPAGELIST", 0, 0, tmplput_display_wiki_pagelist, NULL, CTX_NONE);