* Stub functions for wiki history display
[citadel.git] / webcit / wiki.c
1 /*
2  * $Id$
3  *
4  * Functions pertaining to rooms with a wiki view
5  */
6
7 #include "webcit.h"
8 #include "groupdav.h"
9
10 /* 
11  * Convert a string to something suitable as a wiki index
12  */
13 void str_wiki_index(char *s)
14 {
15         int i;
16
17         if (s == NULL) return;
18
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]);
23                 }
24         }
25
26         /* Then make everything lower case */
27         for (i=0; i<strlen(s); ++i) {
28                 s[i] = tolower(s[i]);
29         }
30 }
31
32 /*
33  * Display a specific page from a wiki room
34  */
35 void display_wiki_page_backend(const StrBuf *roomname, char *pagename)
36 {
37         const StrBuf *Mime;
38         long msgnum = (-1L);
39
40         str_wiki_index(pagename);
41
42         if (StrLength(roomname) > 0) {
43
44                 /* If we're not in the correct room, try going there. */
45                 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
46                         gotoroom(roomname);
47                 }
48         
49                 /* If we're still not in the correct room, it doesn't exist. */
50                 if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
51                         wprintf(_("There is no room called '%s'."), ChrPtr(roomname));
52                         return;
53                 }
54
55         }
56
57         if (WC->wc_view != VIEW_WIKI) {
58                 wprintf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
59                 return;
60         }
61
62         if (IsEmptyStr(pagename)) {
63                 strcpy(pagename, "home");
64         }
65
66         /* Found it!  Now read it. */
67         msgnum = locate_message_by_uid(pagename);
68         if (msgnum >= 0L) {
69                 wprintf("FIXME can we put wiki nav links in or something?<br>\n");
70                 read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
71                 return;
72         }
73
74         wprintf("<br /><br />"
75                 "<div align=\"center\">"
76                 "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
77                 "<tr><td align=\"center\">"
78         );
79         wprintf("<br><b>");
80         wprintf(_("There is no page called '%s' here."), pagename);
81         wprintf("</b><br><br>");
82         wprintf(_("Select the 'Edit this page' link in the room banner "
83                 "if you would like to create this page."));
84         wprintf("<br><br>");
85         wprintf("</td></tr></table></div>\n");
86 }
87
88
89 /*
90  * Display a specific page from a wiki room
91  */
92 void display_wiki_page(void)
93 {
94         const StrBuf *roomname;
95         char pagename[128];
96
97         output_headers(1, 1, 1, 0, 0, 0);
98         roomname = sbstr("room");
99         safestrncpy(pagename, bstr("page"), sizeof pagename);
100         display_wiki_page_backend(roomname, pagename);
101         wDumpContent(1);
102 }
103
104
105 /*
106  * Display the revision history for a wiki page
107  */
108 void display_wiki_history(void)
109 {
110         const StrBuf *roomname;
111         char pagename[128];
112
113         output_headers(1, 1, 1, 0, 0, 0);
114         roomname = sbstr("room");
115         safestrncpy(pagename, bstr("page"), sizeof pagename);
116
117         wprintf("FIXME put something here<br>\n");
118
119         wDumpContent(1);
120 }
121
122
123 int wiki_Cleanup(void **ViewSpecific)
124 {
125         char pagename[5];
126         safestrncpy(pagename, "home", sizeof pagename);
127         display_wiki_page_backend(WC->wc_roomname, pagename);
128         wDumpContent(1);
129         return 0;
130 }
131
132 void 
133 InitModule_WIKI
134 (void)
135 {
136         RegisterReadLoopHandlerset(
137                 VIEW_WIKI,
138                 NULL,
139                 NULL,
140                 NULL,
141                 NULL,
142                 wiki_Cleanup
143         );
144
145         WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
146         WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
147 }
148
149