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)
43 str_wiki_index(pagename);
45 if (StrLength(roomname) > 0) {
47 /* If we're not in the correct room, try going there. */
48 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
52 /* If we're still not in the correct room, it doesn't exist. */
53 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
54 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
60 if (WC->wc_view != VIEW_WIKI) {
61 wc_printf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
65 if (IsEmptyStr(pagename)) {
66 strcpy(pagename, "home");
69 /* Found it! Now read it. */
71 if ((rev != NULL) && (strlen(rev) > 0)) {
72 /* read an older revision */
73 serv_printf("WIKI rev|%s|%s|fetch", pagename, rev);
74 serv_getln(buf, sizeof buf);
76 msgnum = extract_long(&buf[4], 0);
80 /* read the current revision? */
81 msgnum = locate_message_by_uid(pagename);
85 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
89 wc_printf("<br /><br />"
90 "<div align=\"center\">"
91 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
92 "<tr><td align=\"center\">"
95 wc_printf(_("There is no page called '%s' here."), pagename);
96 wc_printf("</b><br><br>");
97 wc_printf(_("Select the 'Edit this page' link in the room banner "
98 "if you would like to create this page."));
99 wc_printf("<br><br>");
100 wc_printf("</td></tr></table></div>\n");
105 * Display a specific page from a wiki room
107 void display_wiki_page(void)
109 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 display_wiki_page_backend(roomname, pagename, rev);
123 * Display the revision history for a wiki page (template callback)
125 void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
127 const StrBuf *roomname;
132 roomname = sbstr("room");
133 safestrncpy(pagename, bstr("page"), sizeof pagename);
134 str_wiki_index(pagename);
136 if (StrLength(roomname) > 0) {
138 /* If we're not in the correct room, try going there. */
139 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
143 /* If we're still not in the correct room, it doesn't exist. */
144 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
145 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
151 serv_printf("WIKI history|%s", pagename);
153 StrBuf_ServGetln(Buf);
154 if (GetServerStatus(Buf, NULL) == 1) {
157 char rev_date_displayed[64];
158 StrBuf *rev_uuid = NewStrBuf();
159 StrBuf *author = NewStrBuf();
160 StrBuf *node = NewStrBuf();
162 wc_printf("<div class=\"fix_scrollbar_bug\">"
163 "<table class=\"wiki_history_background\">"
166 wc_printf("<th>%s</th>", _("Date"));
167 wc_printf("<th>%s</th>", _("Author"));
169 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
171 StrBufExtract_token(rev_uuid, Buf, 0, '|');
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, '|');
175 StrBufExtract_token(node, Buf, 3, '|');
177 wc_printf("<tr bgcolor=\"%s\">", (row ? "#FFFFFF" : "#DDDDDD"));
179 wc_printf("<td>%s</td><td>", rev_date_displayed);
181 if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
182 escputs(ChrPtr(author));
184 escputs(ChrPtr(node));
187 wc_printf("<a href=\"showuser?who=");
188 urlescputs(ChrPtr(author));
190 escputs(ChrPtr(author));
194 wc_printf("</td><td><a href=\"wiki?page=%s?rev=%s\">%s</a></td>",
199 wc_printf("</td><td><a href=\"wiki_revert?page=%s?rev=%s\">%s</a></td>",
204 wc_printf("</tr>\n");
207 wc_printf("</table>\n");
210 FreeStrBuf(&rev_uuid);
213 wc_printf("%s", ChrPtr(Buf));
222 * Display the revision history for a wiki page
224 void display_wiki_history(void)
226 output_headers(1, 1, 1, 0, 0, 0);
227 do_template("wiki_history", NULL);
232 int wiki_Cleanup(void **ViewSpecific)
235 safestrncpy(pagename, "home", sizeof pagename);
236 display_wiki_page_backend(WC->wc_roomname, pagename, "");
245 RegisterReadLoopHandlerset(
254 WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
255 WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
256 /* WebcitAddUrlHandler(HKEY("wiki_revert"), "", 0, wiki_revert, 0); FIXME implement this */
257 RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);