(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: source.ml,v 1.4 2006/03/27 18:09:47 rich Exp $
+ * $Id: source.ml,v 1.6 2006/07/26 13:41:37 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 ExtList
+
open Cocanwiki
open Cocanwiki_pages
open Cocanwiki_ok
*)
(* Get the title. *)
- let sth = dbh#prepare_cached "select title from pages
- where hostid = ? and id = ?" in
- sth#execute [Some hostid; Some model.id];
- let title = sth#fetch1string () in
+ let title = List.hd (
+ let model_id = model.id in
+ PGSQL(dbh) "select title from pages
+ where hostid = $hostid and id = $model_id"
+ ) in
(* Function to write out fields, with RFC822-like escaping. *)
let write key value =
- print_string r key;
- print_string r ": ";
- print_string r (Pcre.replace ~rex ~itempl value);
+ ignore (print_string r key);
+ ignore (print_string r ": ");
+ ignore (print_string r (Pcre.replace ~rex ~itempl value));
ignore (print_newline r);
in
write "Version" (Int32.to_string model.id);
write "Title" title;
write "Description" model.description;
- if model.redirect <> "" then
- write "Redirect" model.redirect
- else
- write "Section-Count" (Int32.to_string (List.length model.contents));
+ (match model.redirect with
+ | Some redirect -> write "Redirect" redirect
+ | None ->
+ write "Section-Count" (string_of_int (List.length model.contents_))
+ );
ignore (print_newline r);
(* Now write out the sections. *)
- if model.redirect = "" then
- List.iter
- (fun (sectionname, divname, content) ->
- write "Section-Header" sectionname;
- write "Css-Id" divname;
+ if model.redirect = None then
+ List.iteri
+ (fun i (sectionname, divname, jsgo, content) ->
+ write "Section-Id" (string_of_int i);
+ (match sectionname with None -> () | Some sectionname ->
+ write "Section-Header" sectionname);
+ (match divname with None -> () | Some divname ->
+ write "Css-Id" divname);
+ (match jsgo with None -> () | Some jsgo ->
+ write "Javascript-Onclick" jsgo);
write "Content" content;
- ignore (print_newline r)) model.contents
+ ignore (print_newline r)) model.contents_
let () =
register_script ~restrict:[CanView] run