4 * Server-side module for Wiki rooms. This will handle things like version control.
6 * Copyright (c) 2009 / released under the GNU General Public License v3
18 #include <sys/types.h>
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
34 #include <libcitadel.h>
37 #include "citserver.h"
46 #include "euidindex.h"
47 #include "ctdl_module.h"
50 * Before allowing a wiki page save to execute, we have to perform version control.
51 * This involves fetching the old version of the page if it exists... FIXME finish this
53 int wiki_upload_beforesave(struct CtdlMessage *msg) {
54 struct CitContext *CCC = CC;
55 long old_msgnum = (-1L);
56 struct CtdlMessage *old_msg = NULL;
57 int no_changes_were_made = 0;
59 if (!CCC->logged_in) return(0); /* Only do this if logged in. */
61 /* Is this a room with a Wiki in it, don't run this hook. */
62 if (CCC->room.QRdefaultview != VIEW_WIKI) {
66 /* If this isn't a MIME message, don't bother. */
67 if (msg->cm_format_type != 4) return(0);
69 /* If there's no EUID we can't do this. */
70 if (msg->cm_fields['E'] == NULL) return(0);
72 /* See if we can retrieve the previous version. */
73 old_msgnum = locate_message_by_euid(msg->cm_fields['E'], &CCC->room);
74 if (old_msgnum <= 0L) return(0);
76 old_msg = CtdlFetchMessage(old_msgnum, 1);
77 if (old_msg == NULL) return(0);
79 if ((msg->cm_fields['M'] != NULL) && (old_msg->cm_fields['M'] != NULL)) {
81 /* If no changes were made, don't bother saving it again */
82 if (!strcmp(msg->cm_fields['M'], old_msg->cm_fields['M'])) {
83 no_changes_were_made = 1;
86 /* FIXME here's where diffs should be generated
89 fp = fopen("/tmp/new.txt", "w");
90 fwrite(msg->cm_fields['M'], strlen(msg->cm_fields['M']), 1, fp);
92 fp = fopen("/tmp/old.txt", "w");
93 fwrite(old_msg->cm_fields['M'], strlen(old_msg->cm_fields['M']), 1, fp);
99 CtdlFreeMessage(old_msg);
100 return(no_changes_were_made);
105 * Module initialization
107 CTDL_MODULE_INIT(wiki)
111 CtdlRegisterMessageHook(wiki_upload_beforesave, EVT_BEFORESAVE);
114 /* return our Subversion id for the Log */