Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / edit_image.ml
index 0d2e6c0..4ddd68b 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_image.ml,v 1.2 2005/07/19 08:58:39 rich Exp $
+ * $Id: edit_image.ml,v 1.4 2006/03/27 18:09:46 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
@@ -29,8 +29,8 @@ open Cocanwiki_ok
 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
@@ -41,38 +41,37 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} user =
   (* Check some ALT text was supplied. *)
   if string_is_whitespace alt then (
     error ~title:"Missing Alt text" ~back_button:true
-      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.");
+      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
-    q "The description fields were updated."
+    dbh hostid q "The description fields were updated."
 
 let () =
   register_script ~restrict:[CanEdit] run