]> code.citadel.org Git - citadel.git/blobdiff - webcit/wiki.c
* Noticed something that was technically correct but confusing: when viewing a wiki...
[citadel.git] / webcit / wiki.c
index f0287eb0667c028c35824e465e54b9488e533d87..3e470fe8a93cdf0babb49f09a27891db3ed89e6c 100644 (file)
@@ -38,6 +38,7 @@ void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev
 {
        const StrBuf *Mime;
        long msgnum = (-1L);
+       char buf[256];
 
        str_wiki_index(pagename);
 
@@ -65,8 +66,21 @@ void display_wiki_page_backend(const StrBuf *roomname, char *pagename, char *rev
                strcpy(pagename, "home");
        }
 
-       /* 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);
+       /* Found it!  Now read it. */
+
+       if ((rev != NULL) && (strlen(rev) > 0)) {
+               /* read an older revision */
+               serv_printf("WIKI rev|%s|%s|fetch", pagename, rev);
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '2') {
+                       msgnum = extract_long(&buf[4], 0);
+               }
+       }
+       else {
+               /* read the current revision? */
+               msgnum = locate_message_by_uid(pagename);
+       }
+
        if (msgnum >= 0L) {
                read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
                return;
@@ -154,16 +168,12 @@ void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
 
                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("<tr bgcolor=\"%s\">", ((row%2) ? "#FFFFFF" : "#DDDDDD"));
                        wc_printf("<td>%s</td><td>", rev_date_displayed);
-
                        if (!strcasecmp(ChrPtr(node), (char *)WC->serv_info->serv_nodename)) {
                                escputs(ChrPtr(author));
                                wc_printf(" @ ");
@@ -176,18 +186,39 @@ void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
                                escputs(ChrPtr(author));
                                wc_printf("</a>");
                        }
+                       wc_printf("</td>");
+
+                       if (row == 0) {
+                               wc_printf("<td><a href=\"wiki?page=%s\">%s</a></td>",
+                                       bstr("page"),
+                                       _("(show)")
+                               );
+                               wc_printf("<td>(%s)</td>", _("Current version"));
+                       }
 
-                       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)")
-                       );
+                       else {
+                               wc_printf("<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");
+
+                       /* Extract all fields except the author and date after displaying the row.  This
+                        * is deliberate, because the timestamp reflects when the diff was written, not
+                        * when the version which it reflects was written.  Similarly, the name associated
+                        * with each diff is the author who created the newer version of the page that
+                        * made the diff happen.
+                        */
+                       StrBufExtract_token(rev_uuid, Buf, 0, '|');
+                       StrBufExtract_token(node, Buf, 3, '|');
+                       ++row;
                }
 
                wc_printf("</table>\n");
@@ -239,5 +270,6 @@ InitModule_WIKI
 
        WebcitAddUrlHandler(HKEY("wiki"), "", 0, display_wiki_page, 0);
        WebcitAddUrlHandler(HKEY("wiki_history"), "", 0, display_wiki_history, 0);
+       /* WebcitAddUrlHandler(HKEY("wiki_revert"), "", 0, wiki_revert, 0); FIXME implement this */
        RegisterNamespace("WIKI:DISPLAYHISTORY", 0, 0, tmplput_display_wiki_history, NULL, CTX_NONE);
 }