Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / recent_rss.ml
index 08fde14..5fe133e 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: recent_rss.ml,v 1.1 2004/11/01 17:46:21 rich Exp $
+ * $Id: recent_rss.ml,v 1.4 2006/03/28 16:24:08 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
@@ -28,41 +28,38 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let limit = 30
+let limit = 30_l
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ =
+let run r (q : cgi) dbh hostid {hostname = hostname} _ =
   let template = get_template dbh hostid "recent_rss.xml" in
 
   template#set "hostname" hostname;
 
   (* Get the changes. *)
-  let sth =
-    dbh#prepare_cached
+  let rows =
+    PGSQL(dbh) "nullable-results"
       "select p.id, p.url, p.url_deleted, p.title, p.last_modified_date,
               p.logged_ip, u.name
          from pages p left outer join users u on p.logged_user = u.id
-        where p.hostid = ?
+        where p.hostid = $hostid
         order by p.last_modified_date desc
-        limit ?" in
-  sth#execute [`Int hostid; `Int limit];
+        limit $limit" in
 
   let table =
-    sth#map
+    List.map
       (function
-        | [`Int version; `String url; _; `String title;
-           `Timestamp last_modified_date; logged_ip; logged_user] ->
+        | (Some version, Some url, _, Some title,
+           Some last_modified_date, logged_ip, logged_user) ->
             let date = printable_date_time last_modified_date in
             let has_logged_ip, logged_ip =
               match logged_ip with
-                  `Null -> false, ""
-                | `String ip -> true, ip
-                | _ -> assert false in
+                  None -> false, ""
+                | Some ip -> true, ip in
             let has_logged_user, logged_user =
               match logged_user with
-                  `Null -> false, ""
-                | `String name -> true, name
-                | _ -> assert false in
-            [ "version", Template.VarString (string_of_int version);
+                  None -> false, ""
+                | Some name -> true, name in
+            [ "version", Template.VarString (Int32.to_string version);
               "url", Template.VarString url;
               "title", Template.VarString title;
               "last_modified_date", Template.VarString date;
@@ -71,20 +68,18 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ =
               "has_logged_user", Template.VarConditional has_logged_user;
               "logged_user", Template.VarString logged_user;
               "is_live", Template.VarConditional true ]
-        | [`Int version; `Null; `String url; `String title;
-           `Timestamp last_modified_date; logged_ip; logged_user] ->
+        | (Some version, None, Some url, Some title,
+           Some last_modified_date, logged_ip, logged_user) ->
             let date = printable_date_time last_modified_date in
             let has_logged_ip, logged_ip =
               match logged_ip with
-                  `Null -> false, ""
-                | `String ip -> true, ip
-                | _ -> assert false in
+                  None -> false, ""
+                | Some ip -> true, ip in
             let has_logged_user, logged_user =
               match logged_user with
-                  `Null -> false, ""
-                | `String name -> true, name
-                | _ -> assert false in
-            [ "version", Template.VarString (string_of_int version);
+                  None -> false, ""
+                | Some name -> true, name in
+            [ "version", Template.VarString (Int32.to_string version);
               "url", Template.VarString url;
               "title", Template.VarString title;
               "last_modified_date", Template.VarString date;
@@ -93,11 +88,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {hostname = hostname} _ =
               "has_logged_user", Template.VarConditional has_logged_user;
               "logged_user", Template.VarString logged_user;
               "is_live", Template.VarConditional false ]
-        | _ -> assert false) in
+        | _ -> assert false) rows in
 
   template#table "recent_changes" table;
 
-  q#template template
+  q#template ~content_type:"application/rss+xml" template
 
 let () =
   register_script ~restrict:[CanEdit] run