Split the 'page' template into two halves to enable pipelining. The
[cocanwiki.git] / scripts / host_menu.ml
1 (* COCANWIKI - a wiki written in Objective CAML.
2  * Written by Richard W.M. Jones <rich@merjis.com>.
3  * Copyright (C) 2004 Merjis Ltd.
4  * $Id: host_menu.ml,v 1.7 2004/11/03 13:36:45 rich Exp $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *)
21
22 open Apache
23 open Registry
24 open Cgi
25 open Printf
26
27 open Cocanwiki
28 open Cocanwiki_template
29
30 let run r (q : cgi) (dbh : Dbi.connection) hostid host user =
31   let template = get_template dbh hostid "host_menu.html" in
32
33   (* Get user's specific permissions. *)
34   let can_manage_users = can_manage_users host user in
35   let can_manage_contacts = can_manage_contacts host user in
36   let can_edit_global_css = can_edit_global_css host user in
37   let can_manage_site = can_manage_site host user in
38   template#conditional "can_manage_users" can_manage_users;
39   template#conditional "can_manage_contacts" can_manage_contacts;
40   template#conditional "can_edit_global_css" can_edit_global_css;
41   template#conditional "can_manage_site" can_manage_site;
42
43   if can_manage_site then (
44     (* Get lots of host-specific stuff from the database. *)
45     let sth =
46       dbh#prepare_cached
47         "select h.canonical_hostname, h.css is not null, h.edit_anon,
48                 h.create_account_anon, h.theme_css is not null,
49                 t.name, t.description, h.feedback_email, h.mailing_list,
50                 h.search_box, h.navigation, h.view_anon,
51                 h.brand, coalesce (h.brand_tagline, ''),
52                 coalesce (h.brand_description, '')
53            from hosts h left outer join themes t on h.theme_css = t.theme_css
54           where h.id = ?" in
55     sth#execute [`Int hostid];
56
57     let canonical_hostname, has_global_css, edit_anon, create_account_anon,
58     has_theme_css, theme_name, theme_description, has_feedback_email,
59     feedback_email, mailing_list, search_box, navigation, view_anon,
60     has_brand, brand, brand_tagline, brand_description =
61       match sth#fetch1 () with
62           [ `String canonical_hostname; `Bool has_global_css;
63             `Bool edit_anon; `Bool create_account_anon; `Bool has_theme_css;
64             (`String _ | `Null) as theme_name;
65             (`String _ | `Null) as theme_description;
66             (`String _ | `Null) as feedback_email;
67             `Bool mailing_list; `Bool search_box; `Bool navigation;
68             `Bool view_anon;
69             (`String _ | `Null) as brand; `String brand_tagline;
70             `String brand_description ] ->
71             let theme_name =
72               match theme_name with `String s -> s | `Null -> "" in
73             let theme_description =
74               match theme_description with `String s -> s | `Null -> "" in
75             let feedback_email, has_feedback_email =
76               match feedback_email with
77                   `String s -> s, true
78                 | `Null -> "", false in
79             let brand, has_brand =
80               match brand with
81                   `String s -> s, true
82                 | `Null -> "", false in
83             canonical_hostname, has_global_css, edit_anon, create_account_anon,
84             has_theme_css, theme_name, theme_description, has_feedback_email,
85             feedback_email, mailing_list, search_box, navigation, view_anon,
86             has_brand, brand, brand_tagline, brand_description
87         | _ -> assert false in
88
89     template#set "canonical_hostname" canonical_hostname;
90     template#conditional "has_global_css" has_global_css;
91     template#conditional "edit_anon" edit_anon;
92     template#conditional "create_account_anon" create_account_anon;
93     template#conditional "has_theme_css" has_theme_css;
94     template#set "theme_name" theme_name;
95     template#set "theme_description" theme_description;
96     template#conditional "has_feedback_email" has_feedback_email;
97     template#set "feedback_email" feedback_email;
98     template#conditional "mailing_list" mailing_list;
99     template#conditional "search_box" search_box;
100     template#conditional "navigation" navigation;
101     template#conditional "view_anon" view_anon;
102     template#conditional "has_brand" has_brand;
103     template#set "brand" brand;
104     template#set "brand_tagline" brand_tagline;
105     template#set "brand_description" brand_description;
106   );
107
108   q#template template
109
110 let () =
111   register_script ~restrict:[CanEdit] run