Show all changed fields in the diff report.
authorrich <rich>
Fri, 4 Aug 2006 12:20:06 +0000 (12:20 +0000)
committerrich <rich>
Fri, 4 Aug 2006 12:20:06 +0000 (12:20 +0000)
scripts/Makefile
scripts/edit.ml
scripts/lib/cocanwiki_diff.ml
scripts/lib/cocanwiki_diff.mli
scripts/lib/cocanwiki_pages.ml
scripts/lib/cocanwiki_pages.mli

index 5b85aaf..408fac6 100644 (file)
@@ -1,5 +1,5 @@
 # Makefile for COCANWIKI.
-# $Id: Makefile,v 1.49 2006/07/27 16:46:55 rich Exp $
+# $Id: Makefile,v 1.50 2006/08/04 12:20:06 rich Exp $
 
 include ../Makefile.config
 
@@ -46,8 +46,8 @@ LIB_OBJS := \
        lib/cocanwiki_links.cmo \
        lib/cocanwiki_ext_calendar.cmo \
        lib/cocanwiki_emailnotify.cmo \
-       lib/cocanwiki_diff.cmo \
        lib/cocanwiki_pages.cmo \
+       lib/cocanwiki_diff.cmo \
        lib/cocanwiki_mail.cmo \
        lib/cdvmm_phone_numbers.cmo
 
index 6ddbfc1..8b0a755 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit.ml,v 1.33 2006/08/01 14:50:47 rich Exp $
+ * $Id: edit.ml,v 1.34 2006/08/04 12:20:06 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -410,13 +410,7 @@ let run r (q : cgi) dbh hostid {hostname = hostname} user =
              (* Synthesize our own changes. *)
              let old_page = get_version_for_diff dbh old_version in
              let new_page =
-               page_for_diff css (List.map (
-                                    fun (sectionname, _, _, content) ->
-                                      let sectionname = match sectionname with
-                                        | None -> ""
-                                        | Some s -> s in
-                                      sectionname, content
-                                  ) model.contents_) in
+               page_for_diff model css in
              let our_diff = diff_cmd old_page new_page in
 
              (* Fill out the conflict template. *)
index 3b47d3e..9b8a7f0 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_diff.ml,v 1.5 2006/08/01 14:50:47 rich Exp $
+ * $Id: cocanwiki_diff.ml,v 1.6 2006/08/04 12:20:07 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,18 +24,39 @@ open Registry
 open Cgi
 open Printf
 
+open Cocanwiki_pages
 open Cocanwiki_files
 open Cocanwiki
 
 (* Convenience code for generating diffs between versions.  See diff.ml
  * and edit.ml which both use this code.
  *)
-let page_for_diff css sections =
+let page_for_diff model css =
+  let title_or_url = match model.pt with Page t -> t | Title t -> t in
+  "Title or URL: " ^ title_or_url ^ "\n" ^
+  "Description: " ^ model.description ^ "\n\n" ^
+  (match model.redirect with
+   | None -> ""
+   | Some redirect -> "Redirect: " ^ redirect ^ "\n\n") ^
   (String.concat ""
-     (List.map (fun (sectionname, content) ->
-                 "HEADING: " ^ sectionname ^ "\n\n" ^
-                 content ^ "\n\n") sections)) ^
-  "CSS:\n\n" ^ css
+     (List.map (
+       fun (sectionname, divname, jsgo, content) ->
+         (match sectionname with
+          | None -> ""
+          | Some sectionname -> "HEADING: " ^ sectionname ^ "\n\n") ^
+         content ^ "\n\n" ^
+         (match divname with
+          | None -> ""
+          | Some divname -> "CSS Id: " ^ divname ^ "\n") ^
+         (match jsgo with
+          | None -> ""
+          | Some jsgo -> "Javascript Onclick: " ^ jsgo ^ "\n") ^
+         "\n"
+      ) model.contents_)
+  ) ^
+  (match css with
+   | None -> ""
+   | Some css -> "CSS:\n\n" ^ css ^ "\n")
 
 let le_re = Pcre.regexp "\r?\n"
 let le_subst = Pcre.subst "\n"
@@ -82,26 +103,24 @@ let diff_cmd old_page new_page =
 let get_version_for_diff dbh version =
   if version = 0l then ""
   else (
-    let css = List.hd (
+    let title, description, redirect, css = List.hd (
       PGSQL(dbh)
-       "select css from pages where id = $version"
+       "select title, description, redirect, css from pages
+          where id = $version"
     ) in
-    let css = match css with None -> "" | Some css -> css in
 
-    let rows = PGSQL(dbh)
-      "select sectionname, content
+    let contents_ = PGSQL(dbh)
+      "select sectionname, divname, jsgo, content
          from contents where pageid = $version
         order by ordering" in
 
-    let sections =
-      List.map (
-       function
-       | (Some sectionname, content) ->
-           sectionname, content
-       | (None, content) ->
-           "", content
-      ) rows in
-    let page = page_for_diff css sections in
+    let model = { id = version;
+                 pt = Title title;
+                 description = description;
+                 redirect = redirect;
+                 contents_ = contents_ } in
+
+    let page = page_for_diff model css in
 
     page
   )
index 3f278dd..3ae6b7b 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_diff.mli,v 1.3 2006/03/27 16:43:44 rich Exp $
+ * $Id: cocanwiki_diff.mli,v 1.4 2006/08/04 12:20:07 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Boston, MA 02111-1307, USA.
  *)
 
-val page_for_diff : string -> (string * string) list -> string
+open Cocanwiki_pages
+
+val page_for_diff : model -> string option -> string
+(** model, CSS. *)
 
 val diff_cmd : string -> string -> string
 
index 31bb251..70eb525 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_pages.ml,v 1.7 2006/07/27 16:46:55 rich Exp $
+ * $Id: cocanwiki_pages.ml,v 1.8 2006/08/04 12:20:07 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,10 @@ open Cocanwiki_strings
 
 type pt = Page of string | Title of string
 
+type section =
+    string option * string option * string option * string
+    (* (sectionname, divname, jsgo, content) *)
+
 type model = {
   id : int32;                          (* Original page ID (0 = none). *)
   pt : pt;                             (* Page of title (only used if id=0) *)
@@ -34,12 +38,11 @@ type model = {
   (* NB. Don't call this 'contents' because that clashes with the
    * Pervasives.contents fields of the ref type.
    *)
-  contents_ : (string option * string option * string option * string) list;
-          (* (sectionname, divname, jsgo, content) for each section. *)
+  contents_ : section list;
 }
 
 exception SaveURLError
-exception SaveConflict of int32 * int32 * string * string
+exception SaveConflict of int32 * int32 * string * string option
 
 let new_page pt =
   let description =
@@ -183,10 +186,8 @@ let save_page r dbh hostid ?user model =
 
       let edited = max_id <> model_id in
 
-      if edited then (
-       let css = match css with None -> "" | Some css -> css in
-       raise (SaveConflict (max_id, model_id, url, css))
-      );
+      if edited then
+       raise (SaveConflict (max_id, model_id, url, css));
 
       (* Defer the pages_redirect_cn constraint because that would
        * temporarily fail on the next UPDATE.
index fb7c8c5..6503141 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_pages.mli,v 1.4 2006/07/27 16:46:55 rich Exp $
+ * $Id: cocanwiki_pages.mli,v 1.5 2006/08/04 12:20:07 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,17 +24,21 @@ open Cocanwiki
 (* Page (URL) or title. *)
 type pt = Page of string | Title of string
 
+type section =
+    string option * string option * string option * string
+    (* (sectionname, divname, jsgo, content) *)
+
 type model = {
   id : int32;                          (* Original page ID (0 = none). *)
   pt : pt;                             (* Page of title (only used if id=0) *)
   description : string;                        (* Description. *)
   redirect : string option;            (* Redirect to. *)
-  contents_ : (string option * string option * string option * string) list;
-          (* (sectionname, divname, jsgo, content) for each section. *)
+  contents_ : section list;            (* List of sections. *)
 }
 
 exception SaveURLError
-exception SaveConflict of int32 * int32 * string * string
+exception SaveConflict of int32 * int32 * string * string option
+  (** New version, old version, URL, CSS. *)
 
 val new_page : pt -> model
   (** Create a new, blank page. *)