Changes done on the Mac.
[cocanwiki.git] / scripts / largest_pages.ml
index 7f1c53a..90d0988 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: largest_pages.ml,v 1.1 2004/09/21 17:07:58 rich Exp $
+ * $Id: largest_pages.ml,v 1.5 2006/03/28 13:20:00 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
@@ -31,7 +31,7 @@ let limit = 50
 let modem_speed = 56000 / 10           (* 56kbps modem. *)
 let overhead = 2 (* Number of seconds to open connection + render page. *)
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
   let template = get_template dbh hostid "largest_pages.html" in
 
   (* Grab the pages from the database, ordered by size.
@@ -39,17 +39,17 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
    * approximation of the final size of the page.  Also, we are not taking
    * into account images.
    *)
-  let sth =
-    dbh#prepare_cached
+  let rows =
+    PGSQL(dbh)
       "select p.id, p.url, p.title, sum (length (c.content))
          from pages p, contents c
-        where p.hostid = ? and p.url is not null and p.redirect is null
+        where p.hostid = $hostid and p.url is not null and p.redirect is null
           and c.pageid = p.id group by 1, 2, 3 order by 4 desc" in
-  sth#execute [`Int hostid];
 
   let table =
-    sth#map
-      (function [`Int pageid; `String page; `String title; `Int size] ->
+    List.map
+      (function [pageid; page; title; Some size] ->
+        let size = Int32.to_int size in
         let download_time = overhead + size / modem_speed in (* seconds *)
         let download_time =
           if download_time <= 4 then "<= 4 s"
@@ -61,15 +61,15 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
           if size < 4096 then sprintf "%d bytes" size
           else sprintf "%d K" (size / 1024) in
 
-        [ "pageid", Template.VarString (string_of_int pageid);
+        [ "pageid", Template.VarString (Int32.to_string pageid);
           "page", Template.VarString page;
           "title", Template.VarString title;
           "size", Template.VarString size;
           "download_time", Template.VarString download_time ]
-        | _ -> assert false) in
+       | _ -> assert false) in
   template#table "pages" table;
 
   q#template template
 
 let () =
-  register_script ~restrict:[CanManageUsers] run
+  register_script ~restrict:[CanView] run