# 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
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
(* 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
(* 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. *)
(* 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
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"
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
)
(* 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
(* 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
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) *)
(* 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 =
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.
(* 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
(* 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. *)