Show all changed fields in the diff report.
[cocanwiki.git] / scripts / lib / cocanwiki_diff.ml
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
   )