* When saving a wiki page, set the message subject to the page name. This will make...
[citadel.git] / citadel / modules / wiki / serv_wiki.c
1 /*
2  * $Id$
3  *
4  * Server-side module for Wiki rooms.  This handles things like version control. 
5  * 
6  * Copyright (c) 2009 by the citadel.org team
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "sysdep.h"
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <stdio.h>
27 #include <fcntl.h>
28 #include <signal.h>
29 #include <pwd.h>
30 #include <errno.h>
31 #include <ctype.h>
32 #include <sys/types.h>
33
34 #if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
36 # include <time.h>
37 #else
38 # if HAVE_SYS_TIME_H
39 #  include <sys/time.h>
40 # else
41 #  include <time.h>
42 # endif
43 #endif
44
45 #include <sys/wait.h>
46 #include <string.h>
47 #include <limits.h>
48 #include <libcitadel.h>
49 #include "citadel.h"
50 #include "server.h"
51 #include "citserver.h"
52 #include "support.h"
53 #include "config.h"
54 #include "control.h"
55 #include "user_ops.h"
56 #include "policy.h"
57 #include "database.h"
58 #include "msgbase.h"
59 #include "euidindex.h"
60 #include "ctdl_module.h"
61
62 /*
63  * Data passed back and forth between wiki_rev() and its MIME parser callback
64  */
65 struct HistoryEraserCallBackData {
66         char *tempfilename;             /* name of temp file being patched */
67         char *stop_when;                /* stop when we hit this uuid */
68         int done;                       /* set to nonzero when we're done patching */
69 };
70
71 /*
72  * Name of the temporary room we create to store old revisions when someone requests them.
73  * We put it in an invalid namespace so the DAP cleans up after us later.
74  */
75 char *wwm = "9999999999.WikiWaybackMachine";
76
77 /*
78  * Before allowing a wiki page save to execute, we have to perform version control.
79  * This involves fetching the old version of the page if it exists.
80  */
81 int wiki_upload_beforesave(struct CtdlMessage *msg) {
82         struct CitContext *CCC = CC;
83         long old_msgnum = (-1L);
84         struct CtdlMessage *old_msg = NULL;
85         long history_msgnum = (-1L);
86         struct CtdlMessage *history_msg = NULL;
87         char diff_old_filename[PATH_MAX];
88         char diff_new_filename[PATH_MAX];
89         char diff_cmd[PATH_MAX];
90         FILE *fp;
91         int rv;
92         char history_page[1024];
93         char boundary[256];
94         char prefixed_boundary[258];
95         char buf[1024];
96         int nbytes = 0;
97         char *diffbuf = NULL;
98         size_t diffbuf_len = 0;
99         char *ptr = NULL;
100
101         if (!CCC->logged_in) return(0); /* Only do this if logged in. */
102
103         /* Is this a room with a Wiki in it, don't run this hook. */
104         if (CCC->room.QRdefaultview != VIEW_WIKI) {
105                 return(0);
106         }
107
108         /* If this isn't a MIME message, don't bother. */
109         if (msg->cm_format_type != 4) return(0);
110
111         /* If there's no EUID we can't do this. */
112         if (msg->cm_fields['E'] == NULL) return(0);
113         snprintf(history_page, sizeof history_page, "%s_HISTORY_", msg->cm_fields['E']);
114
115         /* Make sure we're saving a real wiki page rather than a wiki history page.
116          * This is important in order to avoid recursing infinitely into this hook.
117          */
118         if (    (strlen(msg->cm_fields['E']) >= 9)
119                 && (!strcasecmp(&msg->cm_fields['E'][strlen(msg->cm_fields['E'])-9], "_HISTORY_"))
120         ) {
121                 CtdlLogPrintf(CTDL_DEBUG, "History page not being historied\n");
122                 return(0);
123         }
124
125         /* If there's no message text, obviously this is all b0rken and shouldn't happen at all */
126         if (msg->cm_fields['M'] == NULL) return(0);
127
128         /* Set the message subject identical to the page name */
129         if (msg->cm_fields['U'] != NULL) {
130                 free(msg->cm_fields['U']);
131         }
132         msg->cm_fields['U'] = strdup(msg->cm_fields['E']);
133
134         /* See if we can retrieve the previous version. */
135         old_msgnum = locate_message_by_euid(msg->cm_fields['E'], &CCC->room);
136         if (old_msgnum > 0L) {
137                 old_msg = CtdlFetchMessage(old_msgnum, 1);
138         }
139         else {
140                 old_msg = NULL;
141         }
142
143         if ((old_msg != NULL) && (old_msg->cm_fields['M'] == NULL)) {   /* old version is corrupt? */
144                 CtdlFreeMessage(old_msg);
145                 old_msg = NULL;
146         }
147         
148         /* If no changes were made, don't bother saving it again */
149         if ((old_msg != NULL) && (!strcmp(msg->cm_fields['M'], old_msg->cm_fields['M']))) {
150                 CtdlFreeMessage(old_msg);
151                 return(1);
152         }
153
154         /*
155          * Generate diffs
156          */
157         CtdlMakeTempFileName(diff_old_filename, sizeof diff_old_filename);
158         CtdlMakeTempFileName(diff_new_filename, sizeof diff_new_filename);
159
160         if (old_msg != NULL) {
161                 fp = fopen(diff_old_filename, "w");
162                 rv = fwrite(old_msg->cm_fields['M'], strlen(old_msg->cm_fields['M']), 1, fp);
163                 fclose(fp);
164                 CtdlFreeMessage(old_msg);
165         }
166
167         fp = fopen(diff_new_filename, "w");
168         rv = fwrite(msg->cm_fields['M'], strlen(msg->cm_fields['M']), 1, fp);
169         fclose(fp);
170
171         diffbuf_len = 0;
172         diffbuf = NULL;
173         snprintf(diff_cmd, sizeof diff_cmd,
174                 "diff -u %s %s",
175                 diff_new_filename,
176                 ((old_msg != NULL) ? diff_old_filename : "/dev/null")
177         );
178         fp = popen(diff_cmd, "r");
179         if (fp != NULL) {
180                 do {
181                         diffbuf = realloc(diffbuf, diffbuf_len + 1025);
182                         nbytes = fread(&diffbuf[diffbuf_len], 1, 1024, fp);
183                         diffbuf_len += nbytes;
184                 } while (nbytes == 1024);
185                 diffbuf[diffbuf_len] = 0;
186                 pclose(fp);
187         }
188         CtdlLogPrintf(CTDL_DEBUG, "diff length is %d bytes\n", diffbuf_len);
189
190         unlink(diff_old_filename);
191         unlink(diff_new_filename);
192
193         /* Determine whether this was a bogus (empty) edit */
194         if ((diffbuf_len = 0) && (diffbuf != NULL)) {
195                 free(diffbuf);
196                 diffbuf = NULL;
197         }
198         if (diffbuf == NULL) {
199                 return(1);              /* No changes at all?  Abandon the post entirely! */
200         }
201
202         /* Now look for the existing edit history */
203
204         history_msgnum = locate_message_by_euid(history_page, &CCC->room);
205         history_msg = NULL;
206         if (history_msgnum > 0L) {
207                 history_msg = CtdlFetchMessage(history_msgnum, 1);
208         }
209
210         /* Create a new history message if necessary */
211         if (history_msg == NULL) {
212                 history_msg = malloc(sizeof(struct CtdlMessage));
213                 memset(history_msg, 0, sizeof(struct CtdlMessage));
214                 history_msg->cm_magic = CTDLMESSAGE_MAGIC;
215                 history_msg->cm_anon_type = MES_NORMAL;
216                 history_msg->cm_format_type = FMT_RFC822;
217                 history_msg->cm_fields['A'] = strdup("Citadel");
218                 history_msg->cm_fields['R'] = strdup(CCC->room.QRname);
219                 history_msg->cm_fields['E'] = strdup(history_page);
220                 history_msg->cm_fields['U'] = strdup(history_page);
221                 snprintf(boundary, sizeof boundary, "Citadel--Multipart--%04x--%08lx", getpid(), time(NULL));
222                 history_msg->cm_fields['M'] = malloc(1024);
223                 snprintf(history_msg->cm_fields['M'], 1024,
224                         "Content-type: multipart/mixed; boundary=\"%s\"\n\n"
225                         "This is a Citadel wiki history encoded as multipart MIME.\n"
226                         "Each part is comprised of a diff script representing one change set.\n"
227                         "\n"
228                         "--%s--\n"
229                         ,
230                         boundary, boundary
231                 );
232         }
233
234         /* Update the history message (regardless of whether it's new or existing) */
235
236         /* First, figure out the boundary string.  We do this even when we generated the
237          * boundary string in the above code, just to be safe and consistent.
238          */
239         strcpy(boundary, "");
240
241         ptr = history_msg->cm_fields['M'];
242         do {
243                 ptr = memreadline(ptr, buf, sizeof buf);
244                 if (*ptr != 0) {
245                         striplt(buf);
246                         if (!IsEmptyStr(buf) && (!strncasecmp(buf, "Content-type:", 13))) {
247                                 if (
248                                         (bmstrcasestr(buf, "multipart") != NULL)
249                                         && (bmstrcasestr(buf, "boundary=") != NULL)
250                                 ) {
251                                         safestrncpy(boundary, bmstrcasestr(buf, "\""), sizeof boundary);
252                                         char *qu;
253                                         qu = strchr(boundary, '\"');
254                                         if (qu) {
255                                                 strcpy(boundary, ++qu);
256                                         }
257                                         qu = strchr(boundary, '\"');
258                                         if (qu) {
259                                                 *qu = 0;
260                                         }
261                                 }
262                         }
263                 }
264         } while ( (IsEmptyStr(boundary)) && (*ptr != 0) );
265
266         /* Now look for the first boundary.  That is where we need to insert our fun.
267          */
268         if (!IsEmptyStr(boundary)) {
269                 snprintf(prefixed_boundary, sizeof prefixed_boundary, "--%s", boundary);
270                 history_msg->cm_fields['M'] = realloc(history_msg->cm_fields['M'],
271                         strlen(history_msg->cm_fields['M']) + strlen(diffbuf) + 1024
272                 );
273                 ptr = bmstrcasestr(history_msg->cm_fields['M'], prefixed_boundary);
274                 if (ptr != NULL) {
275                         char *the_rest_of_it = strdup(ptr);
276                         char uuid[32];
277                         char memo[512];
278                         char encoded_memo[768];
279                         generate_uuid(uuid);
280                         snprintf(memo, sizeof memo, "%s|%ld|%s|%s", 
281                                 uuid,
282                                 time(NULL),
283                                 CCC->user.fullname,
284                                 config.c_nodename
285                                 /* no longer logging CCC->cs_inet_email */
286                         );
287                         CtdlEncodeBase64(encoded_memo, memo, strlen(memo), 0);
288                         sprintf(ptr, "--%s\n"
289                                         "Content-type: text/plain\n"
290                                         "Content-Disposition: inline; filename=\"%s\"\n"
291                                         "Content-Transfer-Encoding: 8bit\n"
292                                         "\n"
293                                         "%s\n"
294                                         "%s"
295                                         ,
296                                 boundary,
297                                 encoded_memo,
298                                 diffbuf,
299                                 the_rest_of_it
300                         );
301                         free(the_rest_of_it);
302                 }
303
304                 history_msg->cm_fields['T'] = realloc(history_msg->cm_fields['T'], 32);
305                 snprintf(history_msg->cm_fields['T'], 32, "%ld", time(NULL));
306         
307                 CtdlSubmitMsg(history_msg, NULL, "", 0);
308         }
309         else {
310                 CtdlLogPrintf(CTDL_ALERT, "Empty boundary string in history message.  No history!\n");
311         }
312
313         free(diffbuf);
314         free(history_msg);
315         return(0);
316 }
317
318
319 /*
320  * MIME Parser callback for wiki_history()
321  *
322  * The "filename" field will contain a memo field.  All we have to do is decode
323  * the base64 and output it.  The data is already in a delimited format suitable
324  * for our client protocol.
325  */
326 void wiki_history_callback(char *name, char *filename, char *partnum, char *disp,
327                    void *content, char *cbtype, char *cbcharset, size_t length,
328                    char *encoding, char *cbid, void *cbuserdata)
329 {
330         char memo[1024];
331
332         CtdlDecodeBase64(memo, filename, strlen(filename));
333         cprintf("%s\n", memo);
334 }
335
336
337 /*
338  * Fetch a list of revisions for a particular wiki page
339  */
340 void wiki_history(char *pagename) {
341         int r;
342         char history_page_name[270];
343         long msgnum;
344         struct CtdlMessage *msg;
345
346         r = CtdlDoIHavePermissionToReadMessagesInThisRoom();
347         if (r != om_ok) {
348                 if (r == om_not_logged_in) {
349                         cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
350                 }
351                 else {
352                         cprintf("%d An unknown error has occurred.\n", ERROR);
353                 }
354                 return;
355         }
356
357         snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
358         msgnum = locate_message_by_euid(history_page_name, &CC->room);
359         if (msgnum > 0L) {
360                 msg = CtdlFetchMessage(msgnum, 1);
361         }
362         else {
363                 msg = NULL;
364         }
365
366         if ((msg != NULL) && (msg->cm_fields['M'] == NULL)) {
367                 CtdlFreeMessage(msg);
368                 msg = NULL;
369         }
370
371         if (msg == NULL) {
372                 cprintf("%d Revision history for '%s' was not found.\n", ERROR+MESSAGE_NOT_FOUND, pagename);
373                 return;
374         }
375
376         
377         cprintf("%d Revision history for '%s'\n", LISTING_FOLLOWS, pagename);
378         mime_parser(msg->cm_fields['M'], NULL, *wiki_history_callback, NULL, NULL, NULL, 0);
379         cprintf("000\n");
380
381         CtdlFreeMessage(msg);
382         return;
383 }
384
385 /*
386  * MIME Parser callback for wiki_rev()
387  *
388  * The "filename" field will contain a memo field, which includes (among other things)
389  * the uuid of this revision.  After we hit the desired revision, we stop processing.
390  *
391  * The "content" filed will contain "diff" output suitable for applying via "patch"
392  * to our temporary file.
393  */
394 void wiki_rev_callback(char *name, char *filename, char *partnum, char *disp,
395                    void *content, char *cbtype, char *cbcharset, size_t length,
396                    char *encoding, char *cbid, void *cbuserdata)
397 {
398         struct HistoryEraserCallBackData *hecbd = (struct HistoryEraserCallBackData *)cbuserdata;
399         char memo[1024];
400         char this_rev[256];
401         FILE *fp;
402         char *ptr = NULL;
403         char buf[1024];
404
405         /* Did a previous callback already indicate that we've reached our target uuid?
406          * If so, don't process anything else.
407          */
408         if (hecbd->done) {
409                 return;
410         }
411
412         CtdlDecodeBase64(memo, filename, strlen(filename));
413         extract_token(this_rev, memo, 0, '|', sizeof this_rev);
414         CtdlLogPrintf(CTDL_DEBUG, "callback found rev: %s\n", this_rev);
415
416         /* Perform the patch */
417         fp = popen("patch -f -s -p0 >/dev/null 2>/dev/null", "w");
418         if (fp) {
419                 /* Replace the filenames in the patch with the tempfilename we're actually tweaking */
420                 fprintf(fp, "--- %s\n", hecbd->tempfilename);
421                 fprintf(fp, "+++ %s\n", hecbd->tempfilename);
422
423                 ptr = (char *)content;
424                 int linenum = 0;
425                 do {
426                         ++linenum;
427                         ptr = memreadline(ptr, buf, sizeof buf);
428                         if (*ptr != 0) {
429                                 if (linenum <= 2) {
430                                         /* skip the first two lines; they contain bogus filenames */
431                                 }
432                                 else {
433                                         fprintf(fp, "%s\n", buf);
434                                 }
435                         }
436                 } while ((*ptr != 0) && ((int)ptr < ((int)content + length)));
437                 pclose(fp);
438         }
439
440         if (!strcasecmp(this_rev, hecbd->stop_when)) {
441                 /* Found our target rev.  Tell any subsequent callbacks to suppress processing. */
442                 CtdlLogPrintf(CTDL_DEBUG, "Target revision has been reached -- stop patching.\n");
443                 hecbd->done = 1;
444         }
445 }
446
447
448 /*
449  * Fetch a specific revision of a wiki page.  The "operation" string may be set to "fetch" in order
450  * to simply fetch the desired revision and store it in a temporary location for viewing, or "revert"
451  * to revert the currently active page to that revision.
452  */
453 void wiki_rev(char *pagename, char *rev, char *operation)
454 {
455         int r;
456         char history_page_name[270];
457         long msgnum;
458         char temp[PATH_MAX];
459         char timestamp[64];
460         struct CtdlMessage *msg;
461         FILE *fp;
462         struct HistoryEraserCallBackData hecbd;
463         long len = 0L;
464         int rv;
465
466         r = CtdlDoIHavePermissionToReadMessagesInThisRoom();
467         if (r != om_ok) {
468                 if (r == om_not_logged_in) {
469                         cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
470                 }
471                 else {
472                         cprintf("%d An unknown error has occurred.\n", ERROR);
473                 }
474                 return;
475         }
476
477         /* Begin by fetching the current version of the page.  We're going to patch
478          * backwards through the diffs until we get the one we want.
479          */
480         msgnum = locate_message_by_euid(pagename, &CC->room);
481         if (msgnum > 0L) {
482                 msg = CtdlFetchMessage(msgnum, 1);
483         }
484         else {
485                 msg = NULL;
486         }
487
488         if ((msg != NULL) && (msg->cm_fields['M'] == NULL)) {
489                 CtdlFreeMessage(msg);
490                 msg = NULL;
491         }
492
493         if (msg == NULL) {
494                 cprintf("%d Page '%s' was not found.\n", ERROR+MESSAGE_NOT_FOUND, pagename);
495                 return;
496         }
497
498         /* Output it to a temporary file */
499
500         CtdlMakeTempFileName(temp, sizeof temp);
501         fp = fopen(temp, "w");
502         if (fp != NULL) {
503                 r = fwrite(msg->cm_fields['M'], strlen(msg->cm_fields['M']), 1, fp);
504                 fclose(fp);
505         }
506         else {
507                 CtdlLogPrintf(CTDL_ALERT, "Cannot open %s: %s\n", temp, strerror(errno));
508         }
509         CtdlFreeMessage(msg);
510
511         /* Get the revision history */
512
513         snprintf(history_page_name, sizeof history_page_name, "%s_HISTORY_", pagename);
514         msgnum = locate_message_by_euid(history_page_name, &CC->room);
515         if (msgnum > 0L) {
516                 msg = CtdlFetchMessage(msgnum, 1);
517         }
518         else {
519                 msg = NULL;
520         }
521
522         if ((msg != NULL) && (msg->cm_fields['M'] == NULL)) {
523                 CtdlFreeMessage(msg);
524                 msg = NULL;
525         }
526
527         if (msg == NULL) {
528                 cprintf("%d Revision history for '%s' was not found.\n", ERROR+MESSAGE_NOT_FOUND, pagename);
529                 return;
530         }
531
532         /* Start patching backwards (newest to oldest) through the revision history until we
533          * hit the revision uuid requested by the user.  (The callback will perform each one.)
534          */
535
536         memset(&hecbd, 0, sizeof(struct HistoryEraserCallBackData));
537         hecbd.tempfilename = temp;
538         hecbd.stop_when = rev;
539
540         mime_parser(msg->cm_fields['M'], NULL, *wiki_rev_callback, NULL, NULL, (void *)&hecbd, 0);
541         CtdlFreeMessage(msg);
542
543         /* Were we successful? */
544         if (hecbd.done == 0) {
545                 cprintf("%d Revision '%s' of page '%s' was not found.\n",
546                         ERROR + MESSAGE_NOT_FOUND, rev, pagename
547                 );
548         }
549
550         /* We have the desired revision on disk.  Now do something with it. */
551
552         else if ( (!strcasecmp(operation, "fetch")) || (!strcasecmp(operation, "revert")) ) {
553                 msg = malloc(sizeof(struct CtdlMessage));
554                 memset(msg, 0, sizeof(struct CtdlMessage));
555                 msg->cm_magic = CTDLMESSAGE_MAGIC;
556                 msg->cm_anon_type = MES_NORMAL;
557                 msg->cm_format_type = FMT_RFC822;
558                 fp = fopen(temp, "r");
559                 if (fp) {
560                         fseek(fp, 0L, SEEK_END);
561                         len = ftell(fp);
562                         fseek(fp, 0L, SEEK_SET);
563                         msg->cm_fields['M'] = malloc(len + 1);
564                         rv = fread(msg->cm_fields['M'], len, 1, fp);
565                         CtdlLogPrintf(CTDL_DEBUG, "\033[32mdid %d blocks of %d bytes\033[0m\n", rv, len);
566                         msg->cm_fields['M'][len] = 0;
567                         fclose(fp);
568                 }
569                 if (len <= 0) {
570                         msgnum = (-1L);
571                 }
572                 else if (!strcasecmp(operation, "fetch")) {
573                         msg->cm_fields['A'] = strdup("Citadel");
574                         CtdlCreateRoom(wwm, 5, "", 0, 1, 1, VIEW_BBS);  /* Not an error if already exists */
575                         msgnum = CtdlSubmitMsg(msg, NULL, wwm, 0);      /* Store the revision here */
576                 }
577                 else if (!strcasecmp(operation, "revert")) {
578                         snprintf(timestamp, sizeof timestamp, "%ld", time(NULL));
579                         msg->cm_fields['T'] = strdup(timestamp);
580                         msg->cm_fields['A'] = strdup(CC->user.fullname);
581                         msg->cm_fields['F'] = strdup(CC->cs_inet_email);
582                         msg->cm_fields['O'] = strdup(CC->room.QRname);
583                         msg->cm_fields['N'] = strdup(NODENAME);
584                         msg->cm_fields['E'] = strdup(pagename);
585                         msgnum = CtdlSubmitMsg(msg, NULL, "", 0);       /* Replace the current revision */
586                 }
587                 else {
588                         /* Theoretically it is impossible to get here, but throw an error anyway */
589                         msgnum = (-1L);
590                 }
591                 CtdlFreeMessage(msg);
592                 if (msgnum >= 0L) {
593                         cprintf("%d %ld\n", CIT_OK, msgnum);            /* Give the client a msgnum */
594                 }
595                 else {
596                         cprintf("%d Error %ld has occurred.\n", ERROR+INTERNAL_ERROR, msgnum);
597                 }
598         }
599
600         /* We did all this work for nothing.  Express anguish to the caller. */
601         else {
602                 cprintf("%d An unknown operation was requested.\n", ERROR+CMD_NOT_SUPPORTED);
603         }
604
605         unlink(temp);
606         return;
607 }
608
609
610
611 /*
612  * commands related to wiki management
613  */
614 void cmd_wiki(char *argbuf) {
615         char subcmd[32];
616         char pagename[256];
617         char rev[128];
618         char operation[16];
619
620         extract_token(subcmd, argbuf, 0, '|', sizeof subcmd);
621
622         if (!strcasecmp(subcmd, "history")) {
623                 extract_token(pagename, argbuf, 1, '|', sizeof pagename);
624                 wiki_history(pagename);
625                 return;
626         }
627
628         if (!strcasecmp(subcmd, "rev")) {
629                 extract_token(pagename, argbuf, 1, '|', sizeof pagename);
630                 extract_token(rev, argbuf, 2, '|', sizeof rev);
631                 extract_token(operation, argbuf, 3, '|', sizeof operation);
632                 wiki_rev(pagename, rev, operation);
633                 return;
634         }
635
636         cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
637 }
638
639
640
641 /*
642  * Module initialization
643  */
644 CTDL_MODULE_INIT(wiki)
645 {
646         if (!threading)
647         {
648                 CtdlRegisterMessageHook(wiki_upload_beforesave, EVT_BEFORESAVE);
649                 CtdlRegisterProtoHook(cmd_wiki, "WIKI", "Commands related to Wiki management");
650         }
651
652         /* return our Subversion id for the Log */
653         return "$Id$";
654 }