(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: links.ml,v 1.1 2004/10/27 21:14:05 rich Exp $
+ * $Id: links.ml,v 1.5 2006/03/28 16:24:07 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
* can show inbound or outbound links only. The format in all cases is a
* simple machine-parsable text file.
*)
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
+let run r (q : cgi) dbh hostid _ _ =
let template = get_template dbh hostid "links.txt" in
if q#param_exists "page" then (
) else if type_ = "outbound" then (
(* Display a list of links outbound from this page. *)
- let sth =
- dbh#prepare_cached "select to_url from links
- where hostid = ? and from_url = ?" in
-
- sth#execute [`Int hostid; `String page];
+ let rows =
+ PGSQL(dbh)
+ "select to_url from links
+ where hostid = $hostid and from_url = $page" in
q#header ~content_type:"text/plain" ();
- sth#iter (function [`String url] -> ignore (print_endline r url)
- | _ -> assert false)
+ List.iter (fun url -> ignore (print_endline r url)) rows
) else
failwith "'type' parameter should be 'inbound' or 'outbound'"
(* Just return the single-row "links database" relating to this
* page.
*)
- let sth = dbh#prepare_cached "select to_url from links
- where hostid = ? and from_url = ?" in
- sth#execute [`Int hostid; `String page];
+ let rows = PGSQL(dbh)
+ "select to_url from links
+ where hostid = $hostid and from_url = $page" in
let table =
- sth#map (function [`String to_url] ->
- [ "to", Template.VarString to_url ]
- | _ -> assert false) in
+ List.map (fun to_url ->
+ [ "to", Template.VarString to_url ]) rows in
let table =
[ [ "from", Template.VarString page;
"to", Template.VarTable table ] ] in
Hashtbl.replace h from_url xs
in
- let sth = dbh#prepare_cached "select from_url, to_url from links
- where hostid = ?" in
- sth#execute [`Int hostid];
+ let rows = PGSQL(dbh) "select from_url, to_url from links
+ where hostid = $hostid" in
- sth#iter (function [`String from_url; `String to_url] ->
- add_link from_url to_url
- | _ -> assert false);
+ List.iter (fun (from_url, to_url) ->
+ add_link from_url to_url) rows;
(* Don't forget redirects! They're kinda like links ... *)
- let sth = dbh#prepare_cached "select url, redirect from pages
- where hostid = ? and url is not null
- and redirect is not null" in
- sth#execute [`Int hostid];
+ let rows = PGSQL(dbh) "select url, redirect from pages
+ where hostid = $hostid and url is not null
+ and redirect is not null" in
- sth#iter (function [`String url; `String redirect] ->
- add_link url redirect
- | _ -> assert false);
+ List.iter (function
+ | (Some url, Some redirect) -> add_link url redirect
+ | _ -> ()
+ ) rows;
let keys h = Hashtbl.fold (fun key _ xs -> key :: xs) h [] in
)
let () =
- register_script run
+ register_script ~restrict:[CanView] run