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.
37 void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev)
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->wc_roomname))) {
51 /* If we're still not in the correct room, it doesn't exist. */
52 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
53 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
59 if (WC->wc_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. FIXME this is where we have to add the ability to read an old rev */
69 msgnum = locate_message_by_uid(pagename);
71 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
75 wc_printf("<br /><br />"
76 "<div align=\"center\">"
77 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
78 "<tr><td align=\"center\">"
81 wc_printf(_("There is no page called '%s' here."), pagename);
82 wc_printf("</b><br><br>");
83 wc_printf(_("Select the 'Edit this page' link in the room banner "
84 "if you would like to create this page."));
85 wc_printf("<br><br>");
86 wc_printf("</td></tr></table></div>\n");
91 * Display a specific page from a wiki room
93 void display_wiki_page(void)
95 const StrBuf *roomname;
99 output_headers(1, 1, 1, 0, 0, 0);
100 roomname = sbstr("room");
101 safestrncpy(pagename, bstr("page"), sizeof pagename);
102 safestrncpy(rev, bstr("rev"), sizeof rev);
103 display_wiki_page_backend(roomname, pagename, rev);
109 * Display the revision history for a wiki page (template callback)
111 void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
113 const StrBuf *roomname;
118 roomname = sbstr("room");
119 safestrncpy(pagename, bstr("page"), sizeof pagename);
120 str_wiki_index(pagename);
122 if (StrLength(roomname) > 0) {
124 /* If we're not in the correct room, try going there. */
125 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
129 /* If we're still not in the correct room, it doesn't exist. */
130 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
131 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
137 serv_printf("WIKI history|%s", pagename);
139 StrBuf_ServGetln(Buf);
140 if (GetServerStatus(Buf, NULL) == 1) {
143 char rev_date_displayed[64];
144 StrBuf *rev_uuid = NewStrBuf();
145 StrBuf *author = NewStrBuf();
146 StrBuf *node = NewStrBuf();
148 wc_printf("<div class=\"fix_scrollbar_bug\">"
149 "<table class=\"wiki_history_background\">"
152 wc_printf("<th>%s</th>", _("Date"));
153 wc_printf("<th>%s</th>", _("Author"));
155 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
157 StrBufExtract_token(rev_uuid, Buf, 0, '|');
158 rev_date = extract_long(ChrPtr(Buf), 1);
159 webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL);
160 StrBufExtract_token(author, Buf, 2, '|');
161 StrBufExtract_token(node, Buf, 3, '|');
163 wc_printf("<tr bgcolor=\"%s\">", (row ? "#FFFFFF" : "#DDDDDD"));
165 wc_printf("<td>%s</td><td>", rev_date_displayed);
167 if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
168 escputs(ChrPtr(author));
170 escputs(ChrPtr(node));
173 wc_printf("<a href=\"showuser?who=");
174 urlescputs(ChrPtr(author));
176 escputs(ChrPtr(author));
180 wc_printf("</td><td><a href=\"wiki?page=%s?rev=%s\">%s</a></td>",
185 wc_printf("</td><td><a href=\"wiki_revert?page=%s?rev=%s\">%s</a></td>",
190 wc_printf("</tr>\n");
193 wc_printf("</table>\n");
196 FreeStrBuf(&rev_uuid);
199 wc_printf("%s", ChrPtr(Buf));
208 * Display the revision history for a wiki page
210 void display_wiki_history(void)
212 output_headers(1, 1, 1, 0, 0, 0);
213 do_template("wiki_history", NULL);
218 int wiki_Cleanup(void **ViewSpecific)
221 safestrncpy(pagename, "home", sizeof pagename);
222 display_wiki_page_backend(WC->wc_roomname, pagename, "");
231 RegisterReadLoopHandlerset(
240 WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
241 WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
242 RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);