2 * Functions pertaining to rooms with a wiki view
9 * Convert a string to something suitable as a wiki index
11 void str_wiki_index(char *s)
15 if (s == NULL) return;
17 /* First remove all non-alphanumeric characters */
18 for (i=0; i<strlen(s); ++i) {
20 strcpy(&s[i], &s[i+1]);
24 /* Then make everything lower case */
25 for (i=0; i<strlen(s); ++i) {
31 * Display a specific page from a wiki room
33 * "rev" may be set to an empty string to display the current version.
34 * "do_revert" may be set to nonzero to perform a reversion to the specified version.
36 void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev, int do_revert)
42 str_wiki_index(pagename);
44 if (StrLength(roomname) > 0) {
46 /* If we're not in the correct room, try going there. */
47 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
51 /* If we're still not in the correct room, it doesn't exist. */
52 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
53 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
59 if (WC->CurRoom.view != VIEW_WIKI) {
60 wc_printf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
64 if (IsEmptyStr(pagename)) {
65 strcpy(pagename, "home");
68 /* Found it! Now read it. */
70 if ((rev != NULL) && (strlen(rev) > 0)) {
71 /* read an older revision */
72 serv_printf("WIKI rev|%s|%s|%s", pagename, rev, (do_revert ? "revert" : "fetch") );
73 serv_getln(buf, sizeof buf);
75 msgnum = extract_long(&buf[4], 0);
79 /* read the current revision? */
80 msgnum = locate_message_by_uid(pagename);
84 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
88 wc_printf("<br /><br />"
89 "<div align=\"center\">"
90 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
91 "<tr><td align=\"center\">"
94 wc_printf(_("There is no page called '%s' here."), pagename);
95 wc_printf("</b><br><br>");
96 wc_printf(_("Select the 'Edit this page' link in the room banner "
97 "if you would like to create this page."));
98 wc_printf("<br><br>");
99 wc_printf("</td></tr></table></div>\n");
104 * Display a specific page from a wiki room
106 void display_wiki_page(void)
108 const StrBuf *roomname;
113 output_headers(1, 1, 1, 0, 0, 0);
114 roomname = sbstr("room");
115 safestrncpy(pagename, bstr("page"), sizeof pagename);
116 safestrncpy(rev, bstr("rev"), sizeof rev);
117 do_revert = atoi(bstr("revert"));
118 display_wiki_page_backend(roomname, pagename, rev, do_revert);
124 * Display the revision history for a wiki page (template callback)
126 void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
128 const StrBuf *roomname;
133 roomname = sbstr("room");
134 safestrncpy(pagename, bstr("page"), sizeof pagename);
135 str_wiki_index(pagename);
137 if (StrLength(roomname) > 0) {
139 /* If we're not in the correct room, try going there. */
140 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
144 /* If we're still not in the correct room, it doesn't exist. */
145 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
146 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
152 serv_printf("WIKI history|%s", pagename);
154 StrBuf_ServGetln(Buf);
155 if (GetServerStatus(Buf, NULL) == 1) {
158 char rev_date_displayed[64];
159 StrBuf *rev_uuid = NewStrBuf();
160 StrBuf *author = NewStrBuf();
161 StrBuf *node = NewStrBuf();
163 wc_printf("<div class=\"fix_scrollbar_bug\">"
164 "<table class=\"wiki_history_background\">"
167 wc_printf("<th>%s</th>", _("Date"));
168 wc_printf("<th>%s</th>", _("Author"));
170 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
172 rev_date = extract_long(ChrPtr(Buf), 1);
173 webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL);
174 StrBufExtract_token(author, Buf, 2, '|');
176 wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD"));
177 wc_printf("<td>%s</td><td>", rev_date_displayed);
178 if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
179 escputs(ChrPtr(author));
181 escputs(ChrPtr(node));
184 wc_printf("<a href=\"showuser?who=");
185 urlescputs(ChrPtr(author));
187 escputs(ChrPtr(author));
193 wc_printf("<td><a href=\"wiki?page=%s\">%s</a></td>",
197 wc_printf("<td>(%s)</td>", _("Current version"));
201 wc_printf("<td><a href=\"wiki?page=%s?rev=%s\">%s</a></td>",
206 wc_printf("<td><a href=\"wiki?page=%s?rev=%s?revert=1\">%s</a></td>",
212 wc_printf("</tr>\n");
214 /* Extract all fields except the author and date after displaying the row. This
215 * is deliberate, because the timestamp reflects when the diff was written, not
216 * when the version which it reflects was written. Similarly, the name associated
217 * with each diff is the author who created the newer version of the page that
218 * made the diff happen.
220 StrBufExtract_token(rev_uuid, Buf, 0, '|');
221 StrBufExtract_token(node, Buf, 3, '|');
225 wc_printf("</table>\n");
228 FreeStrBuf(&rev_uuid);
231 wc_printf("%s", ChrPtr(Buf));
240 * Display the revision history for a wiki page
242 void display_wiki_history(void)
244 output_headers(1, 1, 1, 0, 0, 0);
245 do_template("wiki_history", NULL);
251 * Display a list of all pages in a Wiki room (template callback)
253 void tmplput_display_wiki_pagelist(StrBuf *Target, WCTemplputParams *TP)
255 const StrBuf *roomname;
259 roomname = sbstr("room");
260 if (StrLength(roomname) > 0) {
261 /* If we're not in the correct room, try going there. */
262 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
266 /* If we're still not in the correct room, it doesn't exist. */
267 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->CurRoom.name))) {
268 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
273 if (!IsEmptyStr(bstr("query"))) {
274 serv_printf("MSGS SEARCH|%s||4", bstr("query")); /* search-reduced list */
277 serv_printf("MSGS ALL|||4"); /* full list */
281 StrBuf_ServGetln(Buf);
282 if (GetServerStatus(Buf, NULL) == 1) {
283 StrBuf *pagetitle = NewStrBuf();
285 wc_printf("<div class=\"fix_scrollbar_bug\">"
286 "<table class=\"wiki_pagelist_background\">"
289 wc_printf("<th>%s</th>", _("Page title"));
291 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
292 StrBufExtract_token(pagetitle, Buf, 1, '|');
294 if (!bmstrcasestr((char *)ChrPtr(pagetitle), "_HISTORY_")) { /* no history pages */
295 wc_printf("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD"));
296 wc_printf("<td><a href=\"wiki?page=");
297 urlescputs(ChrPtr(pagetitle));
299 escputs(ChrPtr(pagetitle));
300 wc_printf("</a></td>");
301 wc_printf("</tr>\n");
305 wc_printf("</table>\n");
306 FreeStrBuf(&pagetitle);
314 * Display a list of all pages in a Wiki room. Search requests in a Wiki room also go here.
316 void display_wiki_pagelist(void)
318 output_headers(1, 1, 1, 0, 0, 0);
319 do_template("wiki_pagelist", NULL);
324 int wiki_Cleanup(void **ViewSpecific)
327 safestrncpy(pagename, "home", sizeof pagename);
328 display_wiki_page_backend(WC->CurRoom.name, pagename, "", 0);
338 int ConditionalHaveWikiPage(StrBuf *Target, WCTemplputParams *TP)
345 GetTemplateTokenString(Target, TP, 2, &pch, &len);
346 return strcasecmp(page, pch) == 0;
348 int ConditionalHavewikiType(StrBuf *Target, WCTemplputParams *TP)
354 GetTemplateTokenString(Target, TP, 1, &pch, &len);
355 return bmstrcasestr((char *)ChrPtr(WCC->Hdr->HR.ReqLine), pch) != NULL;
361 RegisterReadLoopHandlerset(
371 WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
372 WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
373 WebcitAddUrlHandler(HKEY("wiki_pagelist"), "", 0, display_wiki_pagelist, 0);
374 RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);
375 RegisterNamespace("WIKI:DISPLAYPAGELIST", 0, 0, tmplput_display_wiki_pagelist, NULL, CTX_NONE);
376 RegisterConditional(HKEY("COND:WIKI:PAGE"), 1, ConditionalHaveWikiPage, CTX_NONE);
377 RegisterConditional(HKEY("COND:WIKI:TYPE"), 1, ConditionalHavewikiType, CTX_NONE);