Strict limit on the number of links in the 'what links here' section.
[cocanwiki.git] / scripts / recent.ml
index 91575e0..997462a 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.ml,v 1.7 2004/09/09 12:21:22 rich Exp $
+ * $Id: recent.ml,v 1.8 2004/09/21 13:01:16 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
@@ -35,45 +35,60 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
 
   let sth =
     dbh#prepare_cached
-      "select id, url, url_deleted, title, last_modified_date, logged_ip
-         from pages
-        where hostid = ?
-          and last_modified_date >= current_timestamp - interval ?
-        order by last_modified_date desc" in
+      "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 = ?
+          and p.last_modified_date >= current_timestamp - interval ?
+        order by p.last_modified_date desc" in
   sth#execute [`Int hostid; `String max_age];
 
   let table =
     sth#map
       (function
         | [`Int version; `String url; _; `String title;
-           `Timestamp last_modified_date; logged_ip] ->
+           `Timestamp 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
+            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);
               "url", Template.VarString url;
               "title", Template.VarString title;
               "last_modified_date", Template.VarString date;
               "has_logged_ip", Template.VarConditional has_logged_ip;
               "logged_ip", Template.VarString logged_ip;
+              "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] ->
+           `Timestamp 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
+            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);
               "url", Template.VarString url;
               "title", Template.VarString title;
               "last_modified_date", Template.VarString date;
               "has_logged_ip", Template.VarConditional has_logged_ip;
               "logged_ip", Template.VarString logged_ip;
+              "has_logged_user", Template.VarConditional has_logged_user;
+              "logged_user", Template.VarString logged_user;
               "is_live", Template.VarConditional false ]
         | _ -> assert false) in