Added the framework to allow us to populate standards parts of the
authorrich <rich>
Wed, 8 Sep 2004 15:46:52 +0000 (15:46 +0000)
committerrich <rich>
Wed, 8 Sep 2004 15:46:52 +0000 (15:46 +0000)
templates on all pages.  This specifically will allow us to provide
the host-specific site menu on every page.

32 files changed:
scripts/.depend
scripts/admin/admin.ml
scripts/admin/create_host_form.ml
scripts/admin/edit_emails_form.ml
scripts/admin/edit_host_css_form.ml
scripts/admin/edit_hostnames_form.ml
scripts/admin/host.ml
scripts/cocanwiki_ok.ml
scripts/cocanwiki_template.ml
scripts/cocanwiki_template.mli [new file with mode: 0644]
scripts/create_form.ml
scripts/delete_file_form.ml
scripts/delete_image_form.ml
scripts/diff.ml
scripts/edit.ml
scripts/edit_page_css_form.ml
scripts/edit_sitemenu.ml
scripts/edit_user_form.ml
scripts/files.ml
scripts/forgot_password_form.ml
scripts/history.ml
scripts/images.ml
scripts/login_form.ml
scripts/page.ml
scripts/recent.ml
scripts/restore_form.ml
scripts/sitemap.ml
scripts/undelete_file_form.ml
scripts/undelete_image_form.ml
scripts/upload_file_form.ml
scripts/upload_image_form.ml
scripts/users.ml

index 2fc976e..d2335d3 100644 (file)
@@ -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 
index 907d00b..2394428 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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. *)
index dabc5f0..777bf7e 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 404a07b..b057473 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 71e4eca..11a5e48 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 2665fb6..2070b86 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 5058722..99b3bf2 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index a1e43b6..d8d28ac 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 =
index 2f39581..9e267da 100644 (file)
@@ -1,27 +1,58 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 (file)
index 0000000..2da3316
--- /dev/null
@@ -0,0 +1,11 @@
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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
index 829b72a..1523fbc 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
 
index 5283ad4..48c87cc 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 3efe9bc..d0d282f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index ceeaed7..4defd29 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
 
index 0d22746..527db2a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 <button>
    * elements.
    *)
index ec9ff2f..befceb0 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_page_css_form.ml,v 1.3 2004/09/08 09:54:28 rich Exp $
+ * $Id: edit_page_css_form.ml,v 1.4 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "edit_page_css_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "edit_page_css_form.html" in
+
   let page = q#param "page" in
 
   let sth = dbh#prepare_cached "select css from pages
index 25997e8..36d48f7 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_sitemenu.ml,v 1.1 2004/09/08 14:47:47 rich Exp $
+ * $Id: edit_sitemenu.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -18,14 +18,14 @@ open Cocanwiki_ok
 open Cocanwiki_emailnotify
 open Cocanwiki_strings
 
-let template = get_template "edit_sitemenu.html"
-
 (* We keep an "internal model" of the menu - see build_internal_model ()
  * below.
  *)
 type model_t = (string * string) list  (* label, url *)
 
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
+  let template = get_template dbh hostid "edit_sitemenu.html" in
+
   (* Workaround bugs in IE, specifically lack of support for <button>
    * elements.
    *)
index 7a2e63f..9a08c8a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_user_form.ml,v 1.1 2004/09/08 12:45:38 rich Exp $
+ * $Id: edit_user_form.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -13,9 +13,9 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let template = get_template "edit_user_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "edit_user_form.html" in
+
   let userid = int_of_string (q#param "userid") in
 
   let sth =
index cfade36..c14d9df 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: files.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: files.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "files.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "files.html" in
+
   let deleted = q#param_true "deleted" in
   template#conditional "deleted" deleted;
 
index 700f0b8..1e5b733 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: forgot_password_form.ml,v 1.1 2004/09/07 17:16:46 rich Exp $
+ * $Id: forgot_password_form.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "forgot_password_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "forgot_password_form.html" in
+
   q#template template
 
 let () =
index ae47e64..186822e 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: history.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: history.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -13,9 +13,9 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let template = get_template "history.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "history.html" in
+
   let page = q#param "page" in
   let page = if page = "" then "index" else page in
 
index 9484239..95bbb81 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: images.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: images.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "images.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "images.html" in
+
   let deleted = q#param_true "deleted" in
   template#conditional "deleted" deleted;
 
index 9bd2fe3..b16921f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: login_form.ml,v 1.1 2004/09/07 16:19:43 rich Exp $
+ * $Id: login_form.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -13,9 +13,9 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_strings
 
-let template = get_template "login_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "login_form.html" in
+
   let redirect = try q#param "redirect" with Not_found -> "" in
 
   if string_is_whitespace redirect then
index c405ffe..38eb595 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.7 2004/09/08 14:01:17 rich Exp $
+ * $Id: page.ml,v 1.8 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -16,9 +16,6 @@ open Cocanwiki_template
 open Cocanwiki_ok
 open Cocanwiki_date
 
-let template_page = get_template "page.html"
-let template_404  = get_template "page_404.html"
-
 (* Maximum level of redirection. *)
 let max_redirect = 4
 
@@ -27,6 +24,9 @@ type fp_status = FPOK of int * string * string * Dbi.datetime * bool
               | FPNotFound
 
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user =
+  let template_page = get_template dbh hostid "page.html" in
+  let template_404  = get_template dbh hostid "page_404.html" in
+
   let page = q#param "page" in
   let page = if page = "" then "index" else page in
 
index 4af4886..bf75ab2 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: recent.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: recent.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -13,11 +13,11 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let template = get_template "recent.html"
-
 let max_age = "3 months"
 
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "recent.html" in
+
   let sth =
     dbh#prepare_cached
       "select id, url, url_deleted, title, last_modified_date, logged_ip
index 41e7c4a..99ab121 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: restore_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: restore_form.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -14,9 +14,9 @@ open Cocanwiki_template
 open Cocanwiki_ok
 open Cocanwiki_diff
 
-let template = get_template "restore_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "restore_form.html" in
+
   (* Parameters. *)
   let page = q#param "page" in
   let old_version = int_of_string (q#param "version") in
index ecf0d81..c8914d5 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: sitemap.ml,v 1.3 2004/09/07 14:58:34 rich Exp $
+ * $Id: sitemap.ml,v 1.4 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -14,9 +14,9 @@ open Cocanwiki_template
 open Cocanwiki_date
 open Cocanwiki_strings
 
-let template = get_template "sitemap.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
+  let template = get_template dbh hostid "sitemap.html" in
+
   (* Pull out all the current pages, and a bit of content from each. *)
   let sth = dbh#prepare_cached "select p.url, p.url = 'index',
                                        p.title, p.description,
index f8ada78..ef534c2 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: undelete_file_form.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "undelete_file_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "undelete_file_form.html" in
+
   let id = int_of_string (q#param "id") in
 
   let sth = dbh#prepare_cached "select name, name_deleted
index 0fe6ee3..94ba133 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: undelete_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: undelete_image_form.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "undelete_image_form.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "undelete_image_form.html" in
+
   let id = int_of_string (q#param "id") in
 
   let sth = dbh#prepare_cached "select name, name_deleted, width, height, alt
index 8606a9d..8e4d207 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_file_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: upload_file_form.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "upload_file_form.html"
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "upload_file_form.html" in
 
-let run r (q : cgi) (dbh : Dbi.connection) _ _ =
   q#template template
 
 let () =
index 3706417..53ad2b4 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: upload_image_form.ml,v 1.4 2004/09/08 09:54:28 rich Exp $
+ * $Id: upload_image_form.ml,v 1.5 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -12,9 +12,9 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let template = get_template "upload_image_form.html"
+let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "upload_image_form.html" in
 
-let run r (q : cgi) (dbh : Dbi.connection) _ _ =
   q#template template
 
 let () =
index 8fff55c..e36c836 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: users.ml,v 1.1 2004/09/08 10:42:20 rich Exp $
+ * $Id: users.ml,v 1.2 2004/09/08 15:46:53 rich Exp $
  *)
 
 open Apache
@@ -13,9 +13,9 @@ open Cocanwiki
 open Cocanwiki_template
 open Cocanwiki_date
 
-let template = get_template "users.html"
-
 let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ =
+  let template = get_template dbh hostid "users.html" in
+
   let sth =
     dbh#prepare_cached
       "select id, name, email, registration_date, can_edit, can_manage_users