* Got a primitive version of the wiki system in place. Needs a lot of fine
[citadel.git] / webcit / wiki.c
1 /*
2  * $Id:  $
3  */
4 /**
5  *
6  * \defgroup Wiki Wiki; Functions pertaining to rooms with a wiki view
7  *
8  */
9
10 /*@{*/
11 #include "webcit.h"
12
13
14
15 /** 
16  * \brief Convert a string to something suitable as a wiki index
17  *
18  * \param s The string to be converted.
19  */
20 void str_wiki_index(char *s)
21 {
22         int i;
23
24         if (s == NULL) return;
25
26         /* First remove all non-alphanumeric characters */
27         for (i=0; i<strlen(s); ++i) {
28                 if (!isalnum(s[i])) {
29                         strcpy(&s[i], &s[i+1]);
30                 }
31         }
32
33         /* Then make everything lower case */
34         for (i=0; i<strlen(s); ++i) {
35                 s[i] = tolower(s[i]);
36         }
37 }
38
39 /**
40  * \brief Display a specific page from a wiki room
41  */
42 void display_wiki_page(void)
43 {
44         char roomname[128];
45         char pagename[128];
46         char errmsg[256];
47         long msgnum = (-1L);
48
49         safestrncpy(roomname, bstr("room"), sizeof roomname);
50         safestrncpy(pagename, bstr("page"), sizeof pagename);
51         str_wiki_index(pagename);
52
53         if (strlen(roomname) > 0) {
54
55                 /* If we're not in the correct room, try going there. */
56                 if (strcasecmp(roomname, WC->wc_roomname)) {
57                         gotoroom(roomname);
58                 }
59         
60                 /* If we're still not in the correct room, it doesn't exist. */
61                 if (strcasecmp(roomname, WC->wc_roomname)) {
62                         snprintf(errmsg, sizeof errmsg,
63                                 _("There is no room called '%s'."),
64                                 roomname);
65                         convenience_page("FF0000", _("Error"), errmsg);
66                         return;
67                 }
68
69         }
70
71         if (WC->wc_view != VIEW_WIKI) {
72                 snprintf(errmsg, sizeof errmsg,
73                         _("'%s' is not a Wiki room."),
74                         roomname);
75                 convenience_page("FF0000", _("Error"), errmsg);
76                 return;
77         }
78
79         if (strlen(pagename) == 0) {
80                 strcpy(pagename, "home");
81         }
82
83         /* Found it!  Now read it. */
84         msgnum = locate_message_by_uid(pagename);
85         if (msgnum >= 0L) {
86                 output_headers(1, 1, 1, 0, 0, 0);
87                 read_message(msgnum, 0, "");
88                 wDumpContent(1);
89                 return;
90         }
91
92         output_headers(1, 1, 1, 0, 0, 0);
93         wprintf("<br /><br />"
94                 "<div align=\"center\">"
95                 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
96                 "<tr><td align=\"center\">"
97         );
98         wprintf("<br><b>");
99         wprintf(_("There is no page called '%s' here."), pagename);
100         wprintf("</b><br><br>");
101         wprintf("<a href=\"display_enter?wikipage=%s\">", pagename);
102         wprintf(_("Click here if you would like to create this page."));
103         wprintf("</a>");
104         wprintf("<br><br>");
105         wprintf("</td></tr></table></div>\n");
106         wDumpContent(1);
107 }
108
109
110 /** @} */