From 4e3e7c6443e7dbe1570e8a2c18a71e5d4f5c8d89 Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 8 Sep 2004 15:46:52 +0000 Subject: [PATCH] Added the framework to allow us to populate standards parts of the templates on all pages. This specifically will allow us to provide the host-specific site menu on every page. --- scripts/.depend | 72 +++++++++++++++++++----------------- scripts/admin/admin.ml | 4 +- scripts/admin/create_host_form.ml | 4 +- scripts/admin/edit_emails_form.ml | 4 +- scripts/admin/edit_host_css_form.ml | 4 +- scripts/admin/edit_hostnames_form.ml | 4 +- scripts/admin/host.ml | 4 +- scripts/cocanwiki_ok.ml | 4 +- scripts/cocanwiki_template.ml | 53 ++++++++++++++++++++------ scripts/cocanwiki_template.mli | 11 ++++++ scripts/create_form.ml | 6 +-- scripts/delete_file_form.ml | 6 +-- scripts/delete_image_form.ml | 6 +-- scripts/diff.ml | 6 +-- scripts/edit.ml | 8 ++-- scripts/edit_page_css_form.ml | 6 +-- scripts/edit_sitemenu.ml | 6 +-- scripts/edit_user_form.ml | 6 +-- scripts/files.ml | 6 +-- scripts/forgot_password_form.ml | 6 +-- scripts/history.ml | 6 +-- scripts/images.ml | 6 +-- scripts/login_form.ml | 6 +-- scripts/page.ml | 8 ++-- scripts/recent.ml | 6 +-- scripts/restore_form.ml | 6 +-- scripts/sitemap.ml | 6 +-- scripts/undelete_file_form.ml | 6 +-- scripts/undelete_image_form.ml | 6 +-- scripts/upload_file_form.ml | 6 +-- scripts/upload_image_form.ml | 6 +-- scripts/users.ml | 6 +-- 32 files changed, 173 insertions(+), 127 deletions(-) create mode 100644 scripts/cocanwiki_template.mli diff --git a/scripts/.depend b/scripts/.depend index 2fc976e..d2335d3 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -8,80 +8,84 @@ cocanwiki_images.cmo: cocanwiki_files.cmo cocanwiki_strings.cmo \ cocanwiki_images.cmi cocanwiki_images.cmx: cocanwiki_files.cmx cocanwiki_strings.cmx \ cocanwiki_images.cmi -cocanwiki_ok.cmo: cocanwiki_template.cmo +cocanwiki_ok.cmo: cocanwiki_template.cmi cocanwiki_ok.cmx: cocanwiki_template.cmx -cocanwiki_template.cmo: cocanwiki_files.cmo -cocanwiki_template.cmx: cocanwiki_files.cmx +cocanwiki_template.cmo: cocanwiki_files.cmo cocanwiki_template.cmi +cocanwiki_template.cmx: cocanwiki_files.cmx cocanwiki_template.cmi create.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo \ wikilib.cmi create.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx \ wikilib.cmx -create_form.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmo \ +create_form.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi \ wikilib.cmi create_form.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx \ wikilib.cmx delete_file.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo delete_file.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx -delete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +delete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmi delete_file_form.cmx: cocanwiki.cmx cocanwiki_template.cmx delete_image.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo delete_image.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx -delete_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +delete_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi delete_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx -diff.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_template.cmo +diff.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_template.cmi diff.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_template.cmx edit.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \ - cocanwiki_ok.cmo cocanwiki_strings.cmo cocanwiki_template.cmo + cocanwiki_ok.cmo cocanwiki_strings.cmo cocanwiki_template.cmi edit.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \ cocanwiki_ok.cmx cocanwiki_strings.cmx cocanwiki_template.cmx edit_page_css.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \ cocanwiki_ok.cmo cocanwiki_strings.cmo edit_page_css.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \ cocanwiki_ok.cmx cocanwiki_strings.cmx -edit_page_css_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +edit_page_css_form.cmo: cocanwiki.cmo cocanwiki_template.cmi edit_page_css_form.cmx: cocanwiki.cmx cocanwiki_template.cmx +edit_sitemenu.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo \ + cocanwiki_strings.cmo cocanwiki_template.cmi +edit_sitemenu.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx \ + cocanwiki_strings.cmx cocanwiki_template.cmx edit_user.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo edit_user.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx -edit_user_form.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +edit_user_form.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi edit_user_form.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx file.cmo: cgi_expires.cmo cocanwiki.cmo file.cmx: cgi_expires.cmx cocanwiki.cmx -files.cmo: cocanwiki.cmo cocanwiki_template.cmo +files.cmo: cocanwiki.cmo cocanwiki_template.cmi files.cmx: cocanwiki.cmx cocanwiki_template.cmx forgot_password.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo forgot_password.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx -forgot_password_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +forgot_password_form.cmo: cocanwiki.cmo cocanwiki_template.cmi forgot_password_form.cmx: cocanwiki.cmx cocanwiki_template.cmx -history.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +history.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi history.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx -hoststyle.cmo: cgi_expires.cmo cocanwiki.cmo cocanwiki_template.cmo +hoststyle.cmo: cgi_expires.cmo cocanwiki.cmo cocanwiki_template.cmi hoststyle.cmx: cgi_expires.cmx cocanwiki.cmx cocanwiki_template.cmx image.cmo: cgi_expires.cmo cocanwiki.cmo image.cmx: cgi_expires.cmx cocanwiki.cmx -images.cmo: cocanwiki.cmo cocanwiki_template.cmo +images.cmo: cocanwiki.cmo cocanwiki_template.cmi images.cmx: cocanwiki.cmx cocanwiki_template.cmx login.cmo: cocanwiki.cmo cocanwiki_ok.cmo login.cmx: cocanwiki.cmx cocanwiki_ok.cmx -login_form.cmo: cocanwiki.cmo cocanwiki_strings.cmo cocanwiki_template.cmo +login_form.cmo: cocanwiki.cmo cocanwiki_strings.cmo cocanwiki_template.cmi login_form.cmx: cocanwiki.cmx cocanwiki_strings.cmx cocanwiki_template.cmx logout.cmo: cocanwiki.cmo cocanwiki_ok.cmo logout.cmx: cocanwiki.cmx cocanwiki_ok.cmx page.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_ok.cmo \ - cocanwiki_template.cmo cocanwiki_version.cmo wikilib.cmi + cocanwiki_template.cmi cocanwiki_version.cmo wikilib.cmi page.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_ok.cmx \ cocanwiki_template.cmx cocanwiki_version.cmx wikilib.cmx pagestyle.cmo: cgi_expires.cmo cocanwiki.cmo pagestyle.cmx: cgi_expires.cmx cocanwiki.cmx preview.cmo: cocanwiki.cmo wikilib.cmi preview.cmx: cocanwiki.cmx wikilib.cmx -recent.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +recent.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi recent.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx restore.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_emailnotify.cmo \ cocanwiki_ok.cmo restore.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_emailnotify.cmx \ cocanwiki_ok.cmx restore_form.cmo: cocanwiki.cmo cocanwiki_diff.cmo cocanwiki_ok.cmo \ - cocanwiki_template.cmo + cocanwiki_template.cmi restore_form.cmx: cocanwiki.cmx cocanwiki_diff.cmx cocanwiki_ok.cmx \ cocanwiki_template.cmx search.cmo: cocanwiki.cmo @@ -89,52 +93,52 @@ search.cmx: cocanwiki.cmx signup.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo signup.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx sitemap.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_strings.cmo \ - cocanwiki_template.cmo wikilib.cmi + cocanwiki_template.cmi wikilib.cmi sitemap.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_strings.cmx \ cocanwiki_template.cmx wikilib.cmx -undelete_file.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmo +undelete_file.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi undelete_file.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx -undelete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +undelete_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmi undelete_file_form.cmx: cocanwiki.cmx cocanwiki_template.cmx -undelete_image.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmo +undelete_image.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi undelete_image.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx -undelete_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +undelete_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi undelete_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx upload_file.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_images.cmi \ - cocanwiki_ok.cmo cocanwiki_template.cmo + cocanwiki_ok.cmo cocanwiki_template.cmi upload_file.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_images.cmx \ cocanwiki_ok.cmx cocanwiki_template.cmx -upload_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +upload_file_form.cmo: cocanwiki.cmo cocanwiki_template.cmi upload_file_form.cmx: cocanwiki.cmx cocanwiki_template.cmx upload_image.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo \ cocanwiki_images.cmi cocanwiki_ok.cmo upload_image.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx \ cocanwiki_images.cmx cocanwiki_ok.cmx -upload_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +upload_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi upload_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx -users.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +users.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi users.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx wikilib.cmo: wikilib.cmi wikilib.cmx: wikilib.cmi -admin/admin.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +admin/admin.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi admin/admin.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx admin/create_host.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo admin/create_host.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx -admin/create_host_form.cmo: cocanwiki_template.cmo +admin/create_host_form.cmo: cocanwiki_template.cmi admin/create_host_form.cmx: cocanwiki_template.cmx admin/edit_emails.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo admin/edit_emails.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx -admin/edit_emails_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +admin/edit_emails_form.cmo: cocanwiki.cmo cocanwiki_template.cmi admin/edit_emails_form.cmx: cocanwiki.cmx cocanwiki_template.cmx admin/edit_host_css.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo admin/edit_host_css.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_strings.cmx -admin/edit_host_css_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +admin/edit_host_css_form.cmo: cocanwiki.cmo cocanwiki_template.cmi admin/edit_host_css_form.cmx: cocanwiki.cmx cocanwiki_template.cmx admin/edit_hostnames.cmo: cocanwiki.cmo cocanwiki_ok.cmo \ cocanwiki_strings.cmo admin/edit_hostnames.cmx: cocanwiki.cmx cocanwiki_ok.cmx \ cocanwiki_strings.cmx -admin/edit_hostnames_form.cmo: cocanwiki.cmo cocanwiki_template.cmo +admin/edit_hostnames_form.cmo: cocanwiki.cmo cocanwiki_template.cmi admin/edit_hostnames_form.cmx: cocanwiki.cmx cocanwiki_template.cmx -admin/host.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmo +admin/host.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi admin/host.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx diff --git a/scripts/admin/admin.ml b/scripts/admin/admin.ml index 907d00b..2394428 100644 --- a/scripts/admin/admin.ml +++ b/scripts/admin/admin.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: admin.ml,v 1.3 2004/09/07 14:58:34 rich Exp $ + * $Id: admin.ml,v 1.4 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -13,7 +13,7 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_date -let template = get_template "admin/admin.html" +let template = _get_template "admin/admin.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = (* Select out the alternative hostnames. *) diff --git a/scripts/admin/create_host_form.ml b/scripts/admin/create_host_form.ml index dabc5f0..777bf7e 100644 --- a/scripts/admin/create_host_form.ml +++ b/scripts/admin/create_host_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: create_host_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $ + * $Id: create_host_form.ml,v 1.3 2004/09/08 15:46:53 rich Exp $ * * NB. Because there might not be any hosts existing when this Wiki * is created, this is not a normal Cocanwiki.register_script script. @@ -13,7 +13,7 @@ open Registry open Cgi open Printf -let template = Cocanwiki_template.get_template "admin/create_host_form.html" +let template = Cocanwiki_template._get_template "admin/create_host_form.html" let run r = let q = new cgi r in diff --git a/scripts/admin/edit_emails_form.ml b/scripts/admin/edit_emails_form.ml index 404a07b..b057473 100644 --- a/scripts/admin/edit_emails_form.ml +++ b/scripts/admin/edit_emails_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_emails_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $ + * $Id: edit_emails_form.ml,v 1.3 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -12,7 +12,7 @@ open Printf open Cocanwiki open Cocanwiki_template -let template = get_template "admin/edit_emails_form.html" +let template = _get_template "admin/edit_emails_form.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = let hostid = int_of_string (q#param "hostid") in diff --git a/scripts/admin/edit_host_css_form.ml b/scripts/admin/edit_host_css_form.ml index 71e4eca..11a5e48 100644 --- a/scripts/admin/edit_host_css_form.ml +++ b/scripts/admin/edit_host_css_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_host_css_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $ + * $Id: edit_host_css_form.ml,v 1.3 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -12,7 +12,7 @@ open Printf open Cocanwiki open Cocanwiki_template -let template = get_template "admin/edit_host_css_form.html" +let template = _get_template "admin/edit_host_css_form.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = let hostid = int_of_string (q#param "hostid") in diff --git a/scripts/admin/edit_hostnames_form.ml b/scripts/admin/edit_hostnames_form.ml index 2665fb6..2070b86 100644 --- a/scripts/admin/edit_hostnames_form.ml +++ b/scripts/admin/edit_hostnames_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_hostnames_form.ml,v 1.2 2004/09/07 13:40:10 rich Exp $ + * $Id: edit_hostnames_form.ml,v 1.3 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -12,7 +12,7 @@ open Printf open Cocanwiki open Cocanwiki_template -let template = get_template "admin/edit_hostnames_form.html" +let template = _get_template "admin/edit_hostnames_form.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = let hostid = int_of_string (q#param "hostid") in diff --git a/scripts/admin/host.ml b/scripts/admin/host.ml index 5058722..99b3bf2 100644 --- a/scripts/admin/host.ml +++ b/scripts/admin/host.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: host.ml,v 1.3 2004/09/07 14:58:34 rich Exp $ + * $Id: host.ml,v 1.4 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -13,7 +13,7 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_date -let template = get_template "admin/host.html" +let template = _get_template "admin/host.html" let run r (q : cgi) (dbh : Dbi.connection) _ _ = let hostid = int_of_string (q#param "hostid") in diff --git a/scripts/cocanwiki_ok.ml b/scripts/cocanwiki_ok.ml index a1e43b6..d8d28ac 100644 --- a/scripts/cocanwiki_ok.ml +++ b/scripts/cocanwiki_ok.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_ok.ml,v 1.3 2004/09/07 14:58:34 rich Exp $ + * $Id: cocanwiki_ok.ml,v 1.4 2004/09/08 15:46:52 rich Exp $ *) open Apache @@ -14,7 +14,7 @@ open Cocanwiki_template (* Override StdPages.ok and StdPages.error with out our versions. * Also have some standard buttons around. *) -let ok_error_template = get_template "ok_error.html" +let ok_error_template = _get_template "ok_error.html" let error ?cookie ?cookies ?title ?(icon = "/_graphics/error.png") ?icon_alt ?back_button ?close_button q message = diff --git a/scripts/cocanwiki_template.ml b/scripts/cocanwiki_template.ml index 2f39581..9e267da 100644 --- a/scripts/cocanwiki_template.ml +++ b/scripts/cocanwiki_template.ml @@ -1,27 +1,58 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_template.ml,v 1.2 2004/09/07 14:58:34 rich Exp $ + * $Id: cocanwiki_template.ml,v 1.3 2004/09/08 15:46:52 rich Exp $ + * + * This module wraps around the Template library. It provides caching + * of templates and fills in standard fields on a host-specific basis. + * *) -open Apache -open Cgi +open Unix open Cocanwiki_files -(* Wrapper around [Cgi.Template.template] function which loads the - * template from a pre-defined path and sets up some default variables. - *) -let get_template = - let path = +let base = + let base = try Sys.getenv "COCANWIKI_TEMPLATES" with Not_found -> "/usr/share/cocanwiki/templates" in let is_dir path = try (Unix.stat path).Unix.st_kind = Unix.S_DIR with Unix.Unix_error _ -> false in - if not (is_dir path) then + if not (is_dir base) then failwith ("environment variable $COCANWIKI_TEMPLATES " ^ "must be set to point to my 'templates' directory " ^ "(see README file for more details)"); - fun filename -> - Template.template (path // filename) + base + +(* Cache of precompiled templates, arranged by full path. *) +let cache = Hashtbl.create 32 + +let _get_template filename = + let path = base // filename in + let stat = Unix.stat path in + let mtime = stat.st_mtime in + + try + let template, old_mtime = Hashtbl.find cache path in + if old_mtime < mtime then ( + (* The template has changed on disk since it was compiled. Reload. *) + let template = Template.template path in + Hashtbl.replace cache path (template, mtime); + template + ) else + template + with + Not_found -> + (* Template not seen before, so load it. *) + let template = Template.template path in + Hashtbl.replace cache path (template, mtime); + template + +let get_template (dbh : Dbi.connection) hostid filename = + let template = _get_template filename in + + (* Get standard fields concerning this host from the database. *) + (* XXX *) + + template diff --git a/scripts/cocanwiki_template.mli b/scripts/cocanwiki_template.mli new file mode 100644 index 0000000..2da3316 --- /dev/null +++ b/scripts/cocanwiki_template.mli @@ -0,0 +1,11 @@ +(* COCANWIKI scripts. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: cocanwiki_template.mli,v 1.1 2004/09/08 15:46:52 rich Exp $ + *) + +(** Get template from filename, with no host-specific substitutions. *) +val _get_template : string -> Template.template + +(** Get template from filename, with host-specific substitutions. *) +val get_template : Dbi.connection -> int -> string -> Template.template diff --git a/scripts/create_form.ml b/scripts/create_form.ml index 829b72a..1523fbc 100644 --- a/scripts/create_form.ml +++ b/scripts/create_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: create_form.ml,v 1.3 2004/09/08 09:54:28 rich Exp $ + * $Id: create_form.ml,v 1.4 2004/09/08 15:46:52 rich Exp $ *) open Apache @@ -15,9 +15,9 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_ok -let template = get_template "create_form.html" - let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ = + let template = get_template dbh hostid "create_form.html" in + (* Get the page title. *) let title = q#param "title" in diff --git a/scripts/delete_file_form.ml b/scripts/delete_file_form.ml index 5283ad4..48c87cc 100644 --- a/scripts/delete_file_form.ml +++ b/scripts/delete_file_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: delete_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $ + * $Id: delete_file_form.ml,v 1.5 2004/09/08 15:46:52 rich Exp $ *) open Apache @@ -12,9 +12,9 @@ open Printf open Cocanwiki open Cocanwiki_template -let template = get_template "delete_file_form.html" - let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = + let template = get_template dbh hostid "delete_file_form.html" in + let id = int_of_string (q#param "id") in let sth = dbh#prepare_cached "select name from files diff --git a/scripts/delete_image_form.ml b/scripts/delete_image_form.ml index 3efe9bc..d0d282f 100644 --- a/scripts/delete_image_form.ml +++ b/scripts/delete_image_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: delete_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $ + * $Id: delete_image_form.ml,v 1.5 2004/09/08 15:46:52 rich Exp $ *) open Apache @@ -12,9 +12,9 @@ open Printf open Cocanwiki open Cocanwiki_template -let template = get_template "delete_image_form.html" - let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = + let template = get_template dbh hostid "delete_image_form.html" in + let id = int_of_string (q#param "id") in let sth = dbh#prepare_cached "select name, width, height, alt diff --git a/scripts/diff.ml b/scripts/diff.ml index ceeaed7..4defd29 100644 --- a/scripts/diff.ml +++ b/scripts/diff.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: diff.ml,v 1.4 2004/09/08 09:54:28 rich Exp $ + * $Id: diff.ml,v 1.5 2004/09/08 15:46:52 rich Exp $ *) open Apache @@ -13,9 +13,9 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_diff -let template = get_template "diff.html" - let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = + let template = get_template dbh hostid "diff.html" in + let page = q#param "page" in let page = if page = "" then "index" else page in diff --git a/scripts/edit.ml b/scripts/edit.ml index 0d22746..527db2a 100644 --- a/scripts/edit.ml +++ b/scripts/edit.ml @@ -1,7 +1,7 @@ (* COCANWIKI scripts. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit.ml,v 1.5 2004/09/08 13:09:05 rich Exp $ + * $Id: edit.ml,v 1.6 2004/09/08 15:46:53 rich Exp $ *) open Apache @@ -18,9 +18,6 @@ open Cocanwiki_emailnotify open Cocanwiki_diff open Cocanwiki_strings -let template = get_template "edit.html" -let template_conflict = get_template "edit_conflict.html" - (* We keep an "internal model" of the page - see build_internal_model () * below. *) @@ -34,6 +31,9 @@ type model_t = { } let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ = + let template = get_template dbh hostid "edit.html" in + let template_conflict = get_template dbh hostid "edit_conflict.html" in + (* Workaround bugs in IE, specifically lack of support for