]> code.citadel.org Git - citadel.git/blobdiff - webcit/wiki.c
* Added the code to let display_wiki_page_backend() know when it's expected to fetch...
[citadel.git] / webcit / wiki.c
index 9d6a6b59b6da5979c89a50299f287bca4cdc7227..f0287eb0667c028c35824e465e54b9488e533d87 100644 (file)
@@ -1,21 +1,14 @@
 /*
- * $Id:  $
- */
-/**
- *
- * \defgroup Wiki Wiki; Functions pertaining to rooms with a wiki view
+ * $Id$
  *
+ * Functions pertaining to rooms with a wiki view
  */
 
-/*@{*/
 #include "webcit.h"
+#include "groupdav.h"
 
-
-
-/** 
- * \brief Convert a string to something suitable as a wiki index
- *
- * \param s The string to be converted.
+/* 
+ * Convert a string to something suitable as a wiki index
  */
 void str_wiki_index(char *s)
 {
@@ -36,71 +29,215 @@ void str_wiki_index(char *s)
        }
 }
 
-/**
- * \brief Display a specific page from a wiki room
+/*
+ * Display a specific page from a wiki room
+ *
+ * "rev" may be set to an empty string to display the current version.
  */
-void display_wiki_page(void)
+void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev)
 {
-       char roomname[128];
-       char pagename[128];
-       char errmsg[256];
+       const StrBuf *Mime;
        long msgnum = (-1L);
 
-       safestrncpy(roomname, bstr("room"), sizeof roomname);
-       safestrncpy(pagename, bstr("page"), sizeof pagename);
        str_wiki_index(pagename);
 
-       /* If we're not in the correct room, try going there. */
-       if (strcasecmp(roomname, WC->wc_roomname)) {
-               gotoroom(roomname);
-       }
+       if (StrLength(roomname) > 0) {
+
+               /* If we're not in the correct room, try going there. */
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
+                       gotoroom(roomname);
+               }
+       
+               /* If we're still not in the correct room, it doesn't exist. */
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
+                       wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
+                       return;
+               }
 
-       /* If we're still not in the correct room, it doesn't exist. */
-       if (strcasecmp(roomname, WC->wc_roomname)) {
-               snprintf(errmsg, sizeof errmsg,
-                       _("There is no room called '%s'."),
-                       roomname);
-               convenience_page("FF0000", _("Error"), errmsg);
-               return;
        }
 
        if (WC->wc_view != VIEW_WIKI) {
-               snprintf(errmsg, sizeof errmsg,
-                       _("'%s' is not a Wiki room."),
-                       roomname);
-               convenience_page("FF0000", _("Error"), errmsg);
+               wc_printf(_("'%s' is not a Wiki room."), ChrPtr(roomname));
                return;
        }
 
-       if (strlen(pagename) == 0) {
+       if (IsEmptyStr(pagename)) {
                strcpy(pagename, "home");
        }
 
-       /* Found it!  Now read it. */
+       /* Found it!  Now read it.   FIXME this is where we have to add the ability to read an old rev */
        msgnum = locate_message_by_uid(pagename);
        if (msgnum >= 0L) {
-               output_headers(1, 1, 1, 0, 0, 0);
-               read_message(msgnum, 0, "");
-               wDumpContent(1);
+               read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
                return;
        }
 
-       output_headers(1, 1, 1, 0, 0, 0);
-       wprintf("<br /><br />"
+       wc_printf("<br /><br />"
                "<div align=\"center\">"
                "<table border=\"0\" bgcolor=\"#ffffff\" cellpadding=\"10\">"
                "<tr><td align=\"center\">"
        );
-       wprintf("<br><b>");
-       wprintf(_("There is no page called '%s' here."), pagename);
-       wprintf("</b><br><br>");
-       wprintf("<a href=\"display_enter?wikipage=%s\">", pagename);
-       wprintf(_("Click here if you would like to create this page."));
-       wprintf("</a>");
-       wprintf("<br><br>");
-       wprintf("</td></tr></table></div>\n");
+       wc_printf("<br><b>");
+       wc_printf(_("There is no page called '%s' here."), pagename);
+       wc_printf("</b><br><br>");
+       wc_printf(_("Select the 'Edit this page' link in the room banner "
+               "if you would like to create this page."));
+       wc_printf("<br><br>");
+       wc_printf("</td></tr></table></div>\n");
+}
+
+
+/*
+ * Display a specific page from a wiki room
+ */
+void display_wiki_page(void)
+{
+       const StrBuf *roomname;
+       char pagename[128];
+       char rev[128];
+
+       output_headers(1, 1, 1, 0, 0, 0);
+       roomname = sbstr("room");
+       safestrncpy(pagename, bstr("page"), sizeof pagename);
+       safestrncpy(rev, bstr("rev"), sizeof rev);
+       display_wiki_page_backend(roomname, pagename, rev);
+       wDumpContent(1);
+}
+
+
+/*
+ * Display the revision history for a wiki page (template callback)
+ */
+void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
+{
+       const StrBuf *roomname;
+       char pagename[128];
+       StrBuf *Buf;
+       int row = 0;
+
+       roomname = sbstr("room");
+       safestrncpy(pagename, bstr("page"), sizeof pagename);
+       str_wiki_index(pagename);
+
+       if (StrLength(roomname) > 0) {
+
+               /* If we're not in the correct room, try going there. */
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
+                       gotoroom(roomname);
+               }
+       
+               /* If we're still not in the correct room, it doesn't exist. */
+               if (strcasecmp(ChrPtr(roomname), ChrPtr(WC->wc_roomname))) {
+                       wc_printf(_("There is no room called '%s'."), ChrPtr(roomname));
+                       return;
+               }
+
+       }
+
+       serv_printf("WIKI history|%s", pagename);
+       Buf = NewStrBuf();
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 1) {
+
+               time_t rev_date;
+               char rev_date_displayed[64];
+               StrBuf *rev_uuid = NewStrBuf();
+               StrBuf *author = NewStrBuf();
+               StrBuf *node = NewStrBuf();
+
+               wc_printf("<div class=\"fix_scrollbar_bug\">"
+                       "<table class=\"wiki_history_background\">"
+               );
+
+               wc_printf("<th>%s</th>", _("Date"));
+               wc_printf("<th>%s</th>", _("Author"));
+
+               while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+
+                       StrBufExtract_token(rev_uuid, Buf, 0, '|');
+                       rev_date = extract_long(ChrPtr(Buf), 1);
+                       webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL);
+                       StrBufExtract_token(author, Buf, 2, '|');
+                       StrBufExtract_token(node, Buf, 3, '|');
+
+                       wc_printf("<tr bgcolor=\"%s\">", (row ? "#FFFFFF" : "#DDDDDD"));
+                       row = 1 - row;
+                       wc_printf("<td>%s</td><td>", rev_date_displayed);
+
+                       if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
+                               escputs(ChrPtr(author));
+                               wc_printf(" @ ");
+                               escputs(ChrPtr(node));
+                       }
+                       else {
+                               wc_printf("<a href=\"showuser?who=");
+                               urlescputs(ChrPtr(author));
+                               wc_printf("\">");
+                               escputs(ChrPtr(author));
+                               wc_printf("</a>");
+                       }
+
+                       wc_printf("</td><td><a href=\"wiki?page=%s?rev=%s\">%s</a></td>",
+                               bstr("page"),
+                               ChrPtr(rev_uuid),
+                               _("(show)")
+                       );
+                       wc_printf("</td><td><a href=\"wiki_revert?page=%s?rev=%s\">%s</a></td>",
+                               bstr("page"),
+                               ChrPtr(rev_uuid),
+                               _("(revert)")
+                       );
+                       wc_printf("</tr>\n");
+               }
+
+               wc_printf("</table>\n");
+               FreeStrBuf(&author);
+               FreeStrBuf(&node);
+               FreeStrBuf(&rev_uuid);
+       }
+       else {
+               wc_printf("%s", ChrPtr(Buf));
+       }
+
+       FreeStrBuf(&Buf);
+}
+
+
+
+/*
+ * Display the revision history for a wiki page
+ */
+void display_wiki_history(void)
+{
+       output_headers(1, 1, 1, 0, 0, 0);
+       do_template("wiki_history", NULL);
        wDumpContent(1);
 }
 
 
-/** @} */
+int wiki_Cleanup(void **ViewSpecific)
+{
+       char pagename[5];
+       safestrncpy(pagename, "home", sizeof pagename);
+       display_wiki_page_backend(WC->wc_roomname, pagename, "");
+       wDumpContent(1);
+       return 0;
+}
+
+void 
+InitModule_WIKI
+(void)
+{
+       RegisterReadLoopHandlerset(
+               VIEW_WIKI,
+               NULL,
+               NULL,
+               NULL,
+               NULL,
+               wiki_Cleanup
+       );
+
+       WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
+       WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
+       RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);
+}