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 void display_wiki_page_backend(const StrBuf *roomname, char *pagename)
40 str_wiki_index(pagename);
42 if (StrLength(roomname) > 0) {
44 /* If we're not in the correct room, try going there. */
45 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
49 /* If we're still not in the correct room, it doesn't exist. */
50 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
51 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
57 if (WC->wc_view != VIEW_WIKI) {
58 wc_printf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
62 if (IsEmptyStr(pagename)) {
63 strcpy(pagename, "home");
66 /* Found it! Now read it. */
67 msgnum = locate_message_by_uid(pagename);
69 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
73 wc_printf("<br /><br />"
74 "<div align=\"center\">"
75 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
76 "<tr><td align=\"center\">"
79 wc_printf(_("There is no page called '%s' here."), pagename);
80 wc_printf("</b><br><br>");
81 wc_printf(_("Select the 'Edit this page' link in the room banner "
82 "if you would like to create this page."));
83 wc_printf("<br><br>");
84 wc_printf("</td></tr></table></div>\n");
89 * Display a specific page from a wiki room
91 void display_wiki_page(void)
93 const StrBuf *roomname;
96 output_headers(1, 1, 1, 0, 0, 0);
97 roomname = sbstr("room");
98 safestrncpy(pagename, bstr("page"), sizeof pagename);
99 display_wiki_page_backend(roomname, pagename);
105 * Display the revision history for a wiki page (template callback)
107 void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
109 const StrBuf *roomname;
113 roomname = sbstr("room");
114 safestrncpy(pagename, bstr("page"), sizeof pagename);
115 str_wiki_index(pagename);
117 if (StrLength(roomname) > 0) {
119 /* If we're not in the correct room, try going there. */
120 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
124 /* If we're still not in the correct room, it doesn't exist. */
125 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
126 wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
132 serv_printf("WIKI history|%s", pagename);
134 StrBuf_ServGetln(Buf);
135 if (GetServerStatus(Buf, NULL) == 1) {
136 while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
137 wc_printf("<tt>%s</tt><br>\n", ChrPtr(Buf));
141 wc_printf("%s", ChrPtr(Buf));
149 * Display the revision history for a wiki page
151 void display_wiki_history(void)
153 output_headers(1, 1, 1, 0, 0, 0);
154 do_template("wiki_history", NULL);
159 int wiki_Cleanup(void **ViewSpecific)
162 safestrncpy(pagename, "home", sizeof pagename);
163 display_wiki_page_backend(WC->wc_roomname, pagename);
172 RegisterReadLoopHandlerset(
181 WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
182 WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
183 RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);