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