X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fpage.ml;h=9e63c07a9497b824464d42a76fcf29aea3c99e47;hb=bfa88724ee152ba00c2b2fca881dd78a6599820a;hp=aa66aeddfdd9b4a995832f0eed5ed9dcf093e61c;hpb=6d64033b48791cf96d2d91b9fe24674c75fd0f67;p=cocanwiki.git diff --git a/scripts/page.ml b/scripts/page.ml index aa66aed..9e63c07 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.41 2005/11/23 11:05:54 rich Exp $ + * $Id: page.ml,v 1.43 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 @@ -53,7 +53,7 @@ let split_qs_re = Pcre.regexp "\\?" let xhtml_re = Pcre.regexp "<.*?>|[^<>]+" -let run r (q : cgi) (dbh : Dbi.connection) hostid +let run r (q : cgi) dbh hostid ({ edit_anon = edit_anon; view_anon = view_anon } as host) user = let page = q#param "page" in @@ -80,7 +80,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid feedback_email is not null, mailing_list, navigation from hosts where id = ?" in - sth#execute [`Int hostid]; + sth#execute [Some hostid]; let has_host_css, has_feedback_email, mailing_list, navigation = match sth#fetch1 () with | [ `Bool has_host_css; `Bool has_feedback_email; `Bool mailing_list; @@ -171,7 +171,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid where ? ~ url_regexp order by ordering limit 1" in - sth#execute [`String url]; + sth#execute [Some url]; try let name = sth#fetch1string () in @@ -217,8 +217,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid | Some pageid -> t#conditional "is_old_version" true; th#conditional "is_old_version" true; - t#set "old_version" (string_of_int pageid); - th#set "old_version" (string_of_int pageid)); + t#set "old_version" (Int32.to_string pageid); + th#set "old_version" (Int32.to_string pageid)); (* At this point, we can print out the header and flush it back to * the user, allowing the browser to start fetching stylesheets @@ -244,23 +244,23 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid let sth = dbh#prepare_cached "select ordering, sectionname, content, divname from contents where pageid = ? order by ordering" in - sth#execute [`Int pageid]; + sth#execute [Some pageid]; sth#map - (function [`Int ordering; - (`Null | `String _) as sectionname; - `String content; - (`Null | `String _) as divname] -> + (function [Some ordering; + (None | Some _) as sectionname; + Some content; + (None | Some _) as divname] -> let divname, has_divname = match divname with - `Null -> "", false - | `String divname -> divname, true in + None -> "", false + | Some divname -> divname, true in let sectionname, has_sectionname = match sectionname with - `Null -> "", false - | `String sectionname -> sectionname, true in + None -> "", false + | Some sectionname -> sectionname, true in let linkname = linkname_of_sectionname sectionname in - [ "ordering", Template.VarString (string_of_int ordering); + [ "ordering", Template.VarString (Int32.to_string ordering); "has_sectionname", Template.VarConditional has_sectionname; "sectionname", Template.VarString sectionname; @@ -305,12 +305,12 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid let sth = dbh#prepare_cached "delete from recently_visited where hostid = ? and userid = ? and url = ?" in - sth#execute [`Int hostid; `Int userid; `String page']; + sth#execute [Some hostid; Some userid; Some page']; let sth = dbh#prepare_cached "insert into recently_visited (hostid, userid, url) values (?, ?, ?)" in - sth#execute [`Int hostid; `Int userid; `String page']; - dbh#commit () + sth#execute [Some hostid; Some userid; Some page']; + PGOCaml.commit dbh | _ -> () ); @@ -341,11 +341,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid and rv.hostid = p.hostid and rv.url = p.url order by 3 desc limit ?") in - let args = List.map (fun s -> `String s) not_urls in + let args = List.map (fun s -> Some s) not_urls in sth#execute - ([`Int hostid; `Int userid] @ args @ [`Int limit]); + ([Some hostid; Some userid] @ args @ [Some limit]); sth#map - (function [`String url; `String title; _] -> + (function [Some url; Some title; _] -> url, title | _ -> assert false) | _ -> [] in @@ -422,16 +422,16 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid "select url, redirect, id, title, description, last_modified_date, css is not null from pages where hostid = ? and lower (url) = lower (?)" in - sth#execute [`Int hostid; `String page]; + sth#execute [Some hostid; Some page]; (try (match sth#fetch1 () with - | `String page' :: _ when page <> page' -> (* different case *) + | Some page' :: _ when page <> page' -> (* different case *) FPExternalRedirect page' - | [ _; `Null; `Int id; `String title; `String description; + | [ _; None; Some id; Some title; Some description; `Timestamp last_modified_date; `Bool has_page_css ] -> FPOK (id, title, description, last_modified_date, has_page_css) - | _ :: `String redirect :: _ -> + | _ :: Some redirect :: _ -> FPInternalRedirect redirect | xs -> failwith (Dbi.sdebug xs)) with @@ -442,10 +442,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid "select id, title, description, last_modified_date, css is not null from pages where hostid = ? and url = ?" in - sth#execute [`Int hostid; `String page]; + sth#execute [Some hostid; Some page]; (try (match sth#fetch1 () with - | [ `Int id; `String title; `String description; + | [ Some id; Some title; Some description; `Timestamp last_modified_date; `Bool has_page_css ] -> FPOK (id, title, description, last_modified_date, has_page_css) @@ -461,11 +461,11 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid from pages where hostid = ? and id = ? and (url = ? or url_deleted = ?)" in - sth#execute [`Int hostid; `Int version; - `String page; `String page]; + sth#execute [Some hostid; Some version; + Some page; Some page]; (try (match sth#fetch1 () with - | [ `Int id; `String title; `String description; + | [ Some id; Some title; Some description; `Timestamp last_modified_date; `Bool has_page_css ] -> FPOK (id, title, description, last_modified_date, has_page_css) @@ -479,15 +479,16 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid let allow_redirect, version = if can_edit then ( not (q#param_true "no_redirect"), - try Some (int_of_string (q#param "version")) with Not_found -> None + try Some (Int32.of_string (q#param "version")) with Not_found -> None ) else (true, None) in let rec loop page' i = if i > max_redirect then ( error ~title:"Too many redirections" ~back_button:true - q ("Too many redirects between pages. This may happen because " ^ - "of a cycle of redirections."); + dbh hostid q + ("Too many redirects between pages. This may happen because " ^ + "of a cycle of redirections."); return () ) else match fetch_page page' version allow_redirect with