* Reduced iconbar button size to 90% because it looked obtuse on a smaller screen
[citadel.git] / webcit / wiki.c
blob1bbb38dbe88711dc7733187081a24c6e839a2a27
1 /*
2 * $Id$
4 * Functions pertaining to rooms with a wiki view
5 */
7 #include "webcit.h"
8 #include "groupdav.h"
10 /*
11 * Convert a string to something suitable as a wiki index
13 void str_wiki_index(char *s)
15 int i;
17 if (s == NULL) return;
19 /* First remove all non-alphanumeric characters */
20 for (i=0; i<strlen(s); ++i) {
21 if (!isalnum(s[i])) {
22 strcpy(&s[i], &s[i+1]);
26 /* Then make everything lower case */
27 for (i=0; i<strlen(s); ++i) {
28 s[i] = tolower(s[i]);
33 * Display a specific page from a wiki room
35 void display_wiki_page(void)
37 const StrBuf *roomname;
38 char pagename[128];
39 char errmsg[256];
40 long msgnum = (-1L);
42 roomname = sbstr("room");
43 safestrncpy(pagename, bstr("page"), sizeof pagename);
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->wc_roomname))) {
50 gotoroom(roomname);
53 /* If we're still not in the correct room, it doesn't exist. */
54 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
55 snprintf(errmsg, sizeof errmsg,
56 _("There is no room called '%s'."),
57 ChrPtr(roomname));
58 convenience_page("FF0000", _("Error"), errmsg);
59 return;
64 if (WC->wc_view != VIEW_WIKI) {
65 snprintf(errmsg, sizeof errmsg,
66 _("'%s' is not a Wiki room."),
67 ChrPtr(roomname));
68 convenience_page("FF0000", _("Error"), errmsg);
69 return;
72 if (IsEmptyStr(pagename)) {
73 strcpy(pagename, "home");
76 /* Found it! Now read it. */
77 msgnum = locate_message_by_uid(pagename);
78 if (msgnum >= 0L) {
79 output_headers(1, 1, 1, 0, 0, 0);
80 read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
81 wDumpContent(1);
82 return;
85 output_headers(1, 1, 1, 0, 0, 0);
86 wprintf("<br /><br />"
87 "<div align=\"center\">"
88 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
89 "<tr><td align=\"center\">"
91 wprintf("<br><b>");
92 wprintf(_("There is no page called '%s' here."), pagename);
93 wprintf("</b><br><br>");
94 wprintf(_("Select the 'Edit this page' link in the room banner "
95 "if you would like to create this page."));
96 wprintf("<br><br>");
97 wprintf("</td></tr></table></div>\n");
98 wDumpContent(1);
101 void
102 InitModule_WIKI
103 (void)
105 WebcitAddUrlHandler(HKEY("wiki"), display_wiki_page, 0);
106 return ;