+/*
+ * MIME Parser callback for wiki_history()
+ *
+ * The "filename" field will contain a memo field. All we have to do is decode
+ * the base64 and output it. The data is already in a delimited format suitable
+ * for our client protocol.
+ */
+void wiki_history_callback(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, char *cbcharset, size_t length,
+ char *encoding, char *cbid, void *cbuserdata)
+{
+ char memo[1024];
+
+ CtdlDecodeBase64(memo, filename, strlen(filename));
+ cprintf("%s\n", memo);
+}
+
+
+/*
+ * Fetch a list of revisions for a particular wiki page
+ */
+void wiki_history(char *pagename) {
+ int r;
+ char history_page_name[270];
+ long msgnum;
+ struct CtdlMessage *msg;
+
+ r = CtdlDoIHavePermissionToReadMessagesInThisRoom();
+ if (r != om_ok) {
+ if (r == om_not_logged_in) {
+ cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
+ }
+ else {
+ cprintf("%d An unknown error has occurred.\n", ERROR);
+ }
+ return;
+ }
+
+ snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
+ msgnum = locate_message_by_euid(history_page_name, &CC->room);
+ if (msgnum > 0L) {
+ msg = CtdlFetchMessage(msgnum, 1);
+ }
+ else {
+ msg = NULL;
+ }
+
+ if ((msg != NULL) && (msg->cm_fields['M'] == NULL)) {
+ CtdlFreeMessage(msg);
+ msg = NULL;
+ }
+
+ if (msg == NULL) {
+ cprintf("%d Revision history for '%s' was not found.\n", ERROR+MESSAGE_NOT_FOUND, pagename);
+ return;
+ }
+
+
+ cprintf("%d Revision history for '%s'\n", LISTING_FOLLOWS, pagename);
+ mime_parser(msg->cm_fields['M'], NULL, *wiki_history_callback, NULL, NULL, NULL, 0);
+ cprintf("000\n");
+
+ CtdlFreeMessage(msg);
+ return;
+}
+