X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flib%2Fcocanwiki_ext_calendar.ml;h=1d54ca7aea19f000256b00693a0cd2c045f13694;hb=d303f75eed3a09bbe2516d9a2a9a4aa9b862ceb3;hp=2b3951f1548642aa80732cf0a724f0a5f5aa80b4;hpb=fb1c781bdbe4a2b296651a051dda11d210c9ad33;p=cocanwiki.git diff --git a/scripts/lib/cocanwiki_ext_calendar.ml b/scripts/lib/cocanwiki_ext_calendar.ml index 2b3951f..1d54ca7 100644 --- a/scripts/lib/cocanwiki_ext_calendar.ml +++ b/scripts/lib/cocanwiki_ext_calendar.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_ext_calendar.ml,v 1.2 2005/04/02 17:30:54 rich Exp $ + * $Id: cocanwiki_ext_calendar.ml,v 1.3 2006/03/27 16:43:44 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 @@ -52,7 +52,7 @@ let rec range a b = else [] -let extension (dbh : Dbi.connection) hostid url = +let extension dbh hostid url = (* Validate a date in the form "yyyy[/mm[/dd]]". Returns a (yyyy, mm, dd) * tuple with missing fields set to 0. If the string doesn't parse or the * date isn't valid, then raises Not_found. @@ -93,19 +93,18 @@ let extension (dbh : Dbi.connection) hostid url = (* From the links table, find all links to this page, or sub-calendar pages. * This query overselects. We then filter the real pages in OCaml. *) - let sth = - dbh#prepare_cached + let rows = + let patt = url ^ "%" in + PGSQL(dbh) "select li.from_url, p.title, li.to_url from links li, pages p - where li.hostid = ? and li.to_url like ? + where li.hostid = $hostid and li.to_url like $patt and li.hostid = p.hostid and li.from_url = p.url" in - sth#execute [`Int hostid; `String (url ^ "%")]; let pages = let results = - sth#map (function [`String from_url; `String title; `String to_url] -> - from_url, title, to_url - | _ -> assert false) in + List.map (fun (from_url, title, to_url) -> + from_url, title, to_url) rows in List.filter_map (fun (from_url, title, to_url) -> try let date = valid_date to_url in Some (date, (title, from_url)) @@ -144,7 +143,8 @@ let extension (dbh : Dbi.connection) hostid url = let template = year_1m_template in template#set "yyyy" (string_of_int yyyy); template#set "mm" (sprintf "%02d" mm); - template#set "month_name" (long_month mm); + template#set "month_name" + (!Printer.month_name (Date.month_of_int mm)); let dow = Date.day_of_week (Date.make yyyy mm 1) in let max_dd = Date.days_in_month (Date.make yyyy mm 1) in let dd = ref (1 - int_of_day_of_week dow) in @@ -196,7 +196,7 @@ let extension (dbh : Dbi.connection) hostid url = | Some (yyyy, mm, 0) -> (* Month view. *) let template = month_template in - template#set "month_name" (long_month mm); + template#set "month_name" (!Printer.month_name (Date.month_of_int mm)); template#set "yyyy" (string_of_int yyyy); template#set "mm" (sprintf "%02d" mm); @@ -258,11 +258,11 @@ let extension (dbh : Dbi.connection) hostid url = template#set "mm" (sprintf "%02d" mm); template#set "dd" (sprintf "%02d" dd); - template#set "month_name" (long_month mm); + template#set "month_name" (!Printer.month_name (Date.month_of_int mm)); let t = Date.make yyyy mm dd in let dow = Date.day_of_week t in - template#set "short_weekday" (short_weekday dow); + template#set "short_weekday" (Printer.short_name_of_day dow); let oneday = Date.Period.day 1 in let prev_t = Date.rem t oneday in