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: cocanwiki_server_settings.ml,v 1.2 2004/09/27 09:46:00 rich Exp $
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.
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.
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.
27 (* Server-wide settings.
29 * These are stored in a single row in the database in the table
30 * 'server_settings'. You must restart the server if you change
33 * It's not possible to read these at server start-up time because the
34 * Apache server is still running as 'root' and will not normally be
35 * allowed to access the database. We thus read them at the earliest
36 * opportunity, in a request context, and cache the results.
38 let server_settings_version, server_settings_stats_page =
39 let default = 1, None in
40 let settings = ref None in
41 let get_settings (dbh : Dbi.connection) =
42 let sth = dbh#prepare "select version, stats_page from server_settings" in
46 (match sth#fetch1 () with
47 | [ `Int version; (`String _ | `Null) as stats_page ] ->
49 match stats_page with `String s -> Some s | `Null -> None in
53 Not_found -> default in
59 let server_settings_version dbh =
62 None -> get_settings dbh
63 | Some settings -> settings in
67 let server_settings_stats_page dbh =
70 None -> get_settings dbh
71 | Some settings -> settings in
75 server_settings_version, server_settings_stats_page