(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_image.ml,v 1.3 2005/11/24 14:54:11 rich Exp $
+ * $Id: edit_image.ml,v 1.5 2006/12/06 09:46:57 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 Cocanwiki_strings
open Cocanwiki_emailnotify
-let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
- let id = int_of_string (q#param "id") in
+let run r (q : cgi) dbh hostid {hostname = hostname} user =
+ let id = Int32.of_string (q#param "id") in
(* Get the fields. *)
let alt = q#param "alt" in
(* Check some ALT text was supplied. *)
if string_is_whitespace alt then (
error ~title:"Missing Alt text" ~back_button:true
- dbh hostid q
+ r dbh hostid q
("You must supply Alt text describing the image. This is required " ^
"by accessibility laws and to allow search engines to discover the " ^
"content of images.");
return ()
);
- let title = if string_is_whitespace title then `Null else `String title in
+ let title = if string_is_whitespace title then None else Some title in
let longdesc =
- if string_is_whitespace longdesc then `Null else `String longdesc in
- let clazz = if string_is_whitespace clazz then `Null else `String clazz in
+ if string_is_whitespace longdesc then None else Some longdesc in
+ let clazz = if string_is_whitespace clazz then None else Some clazz in
(* Edit it. *)
- let sth = dbh#prepare_cached "update images set alt = ?, title = ?,
- longdesc = ?, class = ?
- where hostid = ? and id = ?
- and name is not null" in
- sth#execute [`String alt; title; longdesc; clazz;
- `Int hostid; `Int id];
+ PGSQL(dbh)
+ "update images set alt = $alt, title = $?title,
+ longdesc = $?longdesc, class = $?clazz
+ where hostid = $hostid and id = $id and name is not null";
(* Email notify. *)
let subject = "Description fields on image #" ^
- string_of_int id ^ " were changed." in
+ Int32.to_string id ^ " were changed." in
let body = fun () -> "Page: http://" ^ hostname ^ "/_images" in
email_notify ~body ~subject ~user dbh hostid;
(* Done it. *)
- dbh#commit ();
+ PGOCaml.commit dbh;
let buttons = [ ok_button "/_images" ] in
ok ~title:"Description fields updated" ~buttons
- dbh hostid q "The description fields were updated."
+ r dbh hostid q "The description fields were updated."
let () =
register_script ~restrict:[CanEdit] run