scripts/cocanwiki_images.ml
scripts/cocanwiki_images.mli
scripts/cocanwiki_ok.ml
+scripts/cocanwiki_server_settings.ml
scripts/cocanwiki_strings.ml
scripts/cocanwiki_template.ml
scripts/cocanwiki_template.mli
scripts/set_password_form.ml
scripts/signup.ml
scripts/sitemap.ml
+scripts/stats.ml
+scripts/stats_top.ml
scripts/undelete_file.ml
scripts/undelete_file_form.ml
scripts/undelete_image.ml
templates/send_feedback_form.html
templates/set_password_form.html
templates/sitemap.html
+templates/stats.html
+templates/stats_top.html
templates/undelete_file_form.html
templates/undelete_image_form.html
templates/upload_file_form.html
--
CREATE TABLE server_settings (
- "version" integer NOT NULL
+ "version" integer NOT NULL,
+ stats_page text
);
# Apache configuration for COCANWIKI.
-# $Id: cocanwiki.conf,v 1.6 2004/09/23 09:48:45 rich Exp $
+# $Id: cocanwiki.conf,v 1.7 2004/09/23 15:16:20 rich Exp $
# Uncomment the following lines if necessary. You will probably need
# to adjust the paths to reflect where cocanwiki is really installed.
RewriteRule ^/_logout$ /_bin/logout.cmo [PT,L,QSA]
RewriteRule ^/_recent$ /_bin/recent.cmo [PT,L,QSA]
RewriteRule ^/_sitemap$ /_bin/sitemap.cmo [PT,L,QSA]
-RewriteRule ^/_stats$ /_bin/stats.cmo [PT,L,QSA]
RewriteRule ^/_users$ /_bin/users.cmo [PT,L,QSA]
# Image and file downloads.
RewriteRule ^/([^_].*)/editcss$ /_bin/edit_page_css_form.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/history$ /_bin/history.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/index.rss$ /_bin/rss.cmo?page=$1 [PT,L,QSA]
+RewriteRule ^/([^_].*)/stats$ /_bin/stats.cmo?page=$1 [PT,L,QSA]
RewriteRule ^/([^_].*)/styles.css$ /_bin/pagestyle.cmo?page=$1 [PT,L,QSA]
# Serve pages.
# Makefile for COCANWIKI.
-# $Id: Makefile,v 1.20 2004/09/22 12:04:28 rich Exp $
+# $Id: Makefile,v 1.21 2004/09/23 15:16:21 rich Exp $
include ../Makefile.config
cocanwiki_images.cmo \
cocanwiki_template.cmo \
cocanwiki_ok.cmo \
+ cocanwiki_server_settings.cmo \
cocanwiki.cmo \
cocanwiki_diff.cmo \
cocanwiki_emailnotify.cmo \
set_password_form.cmo \
signup.cmo \
sitemap.cmo \
+ stats.cmo \
+ stats_top.cmo \
undelete_file.cmo \
undelete_file_form.cmo \
undelete_image.cmo \
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki.ml,v 1.11 2004/09/23 11:56:47 rich Exp $
+ * $Id: cocanwiki.ml,v 1.12 2004/09/23 15:16:21 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
*)
let _get_dbh r = Pool.get r "cocanwiki"
-(* Server-wide settings.
- *
- * These are stored in a single row in the database in the table
- * 'server_settings'. You must restart the server if you change
- * this row.
- *
- * It's not possible to read these at server start-up time because the
- * Apache server is still running as 'root' and will not normally be
- * allowed to access the database. We thus read them at the earliest
- * opportunity, in a request context, and cache the results.
- *)
-let server_settings_version =
- let settings = ref None in
- let get_settings (dbh : Dbi.connection) =
- let sth = dbh#prepare "select version from server_settings" in
- sth#execute [];
- let s =
- match sth#fetch1 () with
- | [ `Int version ] -> version
- | _ -> assert false in
- sth#finish ();
- settings := Some s;
- s
- in
-
- let server_settings_version dbh =
- let (version) =
- match !settings with
- None -> get_settings dbh
- | Some settings -> settings in
- version
- in
-
- server_settings_version
-
(* The [CgiExit] exception should be folded back into the base
* mod_caml code at some point. It just causes the 'run' function to
* return at that point safely. (XXX)
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: cocanwiki_server_settings.ml,v 1.1 2004/09/23 15:16:21 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+(* Server-wide settings.
+ *
+ * These are stored in a single row in the database in the table
+ * 'server_settings'. You must restart the server if you change
+ * this row.
+ *
+ * It's not possible to read these at server start-up time because the
+ * Apache server is still running as 'root' and will not normally be
+ * allowed to access the database. We thus read them at the earliest
+ * opportunity, in a request context, and cache the results.
+ *)
+let server_settings_version, server_settings_stats_page =
+ let settings = ref None in
+ let get_settings (dbh : Dbi.connection) =
+ let sth = dbh#prepare "select version, stats_page from server_settings" in
+ sth#execute [];
+ let s =
+ match sth#fetch1 () with
+ | [ `Int version; (`String _ | `Null) as stats_page ] ->
+ let stats_page =
+ match stats_page with `String s -> Some s | `Null -> None in
+ version, stats_page
+ | _ -> assert false in
+ sth#finish ();
+ settings := Some s;
+ s
+ in
+
+ let server_settings_version dbh =
+ let (version, _) =
+ match !settings with
+ None -> get_settings dbh
+ | Some settings -> settings in
+ version
+ in
+
+ let server_settings_stats_page dbh =
+ let (_, stats_page) =
+ match !settings with
+ None -> get_settings dbh
+ | Some settings -> settings in
+ stats_page
+ in
+
+ server_settings_version, server_settings_stats_page
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.18 2004/09/23 11:56:47 rich Exp $
+ * $Id: page.ml,v 1.19 2004/09/23 15:16:21 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
open Cocanwiki_template
open Cocanwiki_ok
open Cocanwiki_date
+open Cocanwiki_server_settings
(* Maximum level of redirection. *)
let max_redirect = 4
let can_manage_site = can_manage_site user in
let can_edit_global_css = can_edit_global_css user in
+ (* Do we have a stats page set up? *)
+ let has_stats = server_settings_stats_page dbh <> None in
+
(* This code generates ordinary pages. *)
let make_page title description pageid last_modified_date has_page_css
version page page' =
t#conditional "can_manage_site" can_manage_site;
t#conditional "can_edit_global_css" can_edit_global_css;
+ t#conditional "has_stats" has_stats;
+
(* Pull out the sections in this page. *)
let sth = dbh#prepare_cached
"select ordering, sectionname, content, divname
t#conditional "can_manage_site" can_manage_site;
t#conditional "can_edit_global_css" can_edit_global_css;
+ t#conditional "has_stats" has_stats;
+
q#template t
in
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: stats.ml,v 1.1 2004/09/23 15:16:21 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+open Cocanwiki_server_settings
+
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
+ let template = get_template dbh hostid "stats.html" in
+
+ let page = q#param "page" in
+
+ (* Get the stats_page. *)
+ let stats_page =
+ match server_settings_stats_page dbh with
+ None -> failwith "no server_settings.stats_page set up for this server"
+ | Some s -> s in
+
+ template#set "stats_page" stats_page;
+
+ (* Get the current business week. Tricky - because GregorianDate isn't
+ * around to help us, it's best to get the database to help us out.
+ *
+ * XXX This fails sometimes near New Year. Better to get GD into extlib
+ * or this codebase.
+ *)
+ let sth =
+ dbh#prepare_cached "select extract (year from current_date) :: int,
+ extract (week from current_date) :: int" in
+ sth#execute [];
+ let year, week =
+ match sth#fetch1 () with
+ [ `Int year; `Int week ] -> year, week
+ | _ -> assert false in
+
+ template#set "year" (string_of_int year);
+ template#set "week" (string_of_int week);
+
+ (* Standard hashing function which we also use in tools/rocket/analysis.ml *)
+ let hash s = Digest.to_hex (Digest.string s) in
+
+ let url = "/" ^ if page = "index" then "" else page in
+ let h = hash url in
+
+ template#set "page" page;
+ template#set "url" url;
+ template#set "hash" h;
+ template#set "hostname" hostname;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEdit] run
--- /dev/null
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: stats_top.ml,v 1.1 2004/09/23 15:16:21 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+open Cocanwiki_server_settings
+
+let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ =
+ let template = get_template dbh hostid "stats_top.html" in
+
+ let page = q#param "page" in
+
+ (* Get the stats_page. *)
+ let stats_page =
+ match server_settings_stats_page dbh with
+ None -> failwith "no server_settings.stats_page set up for this server"
+ | Some s -> s in
+
+ template#set "stats_page" stats_page;
+ template#set "hostname" hostname;
+ template#set "page" page;
+
+ q#template template
+
+let () =
+ register_script ~restrict:[CanEdit] run
<li> <a href="/_bin/largest_pages.cmo">Largest pages</a> </li>
<li> <a href="/_images">Images</a> </li>
<li> <a href="/_files">Files</a> </li>
-<li> <a href="/_stats">Stats</a> </li>
+::if(has_stats)::
+<li> <a href="/::page_html_tag::/stats">Stats</a> </li>
+::end::
::end::
::if(can_manage_users)::
<li> <a href="/_users">Users</a> </li>
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Page stats</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head>
+<frameset rows="10%, 90%">
+ <frame src="/_bin/stats_top.cmo?page=::page_url::" name="top_frame"/>
+ <frame src="::stats_page_html_tag::::hostname_html_tag::/::year::W::week::/page-::hash_html_tag::.html" name="stats_frame"/>
+
+<noframes>
+<h1>Page stats</h1>
+
+<p>
+<a href="::stats_page_html_tag::::hostname_html_tag::/::year::W::week::/page-::hash_html_tag::.html">Logfile statistics for this page, this week.</a>
+</p>
+
+<ul id="topmenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+<li> <a href="/_sitemap">Sitemap</a> </li>
+<li> <a href="/_recent">Recent changes</a> </li>
+</ul>
+
+<div id="menu_div">
+<ul id="bottommenu" class="menu">
+<li class="first"> <a href="/">Home page</a> </li>
+::table(sitemenu)::<li> <a href="/::url_html_tag::">::label_html::</a> </li>
+::end::
+<li> <a href="/_sitemap">Sitemap</a> </li>
+</ul>
+</div>
+
+<div id="footer_div">
+<hr/>
+
+<ul id="footer" class="menu">
+<li class="first"> <a href="/copyright">Copyright © ::year::</a> </li>
+<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li>
+</ul>
+</div>
+
+</noframes>
+</frameset>
+
+</html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Stats navigation frame</title>
+<meta name="robots" content="noindex,nofollow"/>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="::theme_css_html_tag::" type="text/css" title="Standard"/>
+</head><body>
+
+<ul class="menu">
+<li class="first"> <a href="/::page_html_tag::" target="_top">Back to page</a> </li>
+<li> <a href="::stats_page_html_tag::::hostname_html_tag::" target="stats_frame">Stats overview</a> </li>
+</ul>
+
+</body>
+</html>
\ No newline at end of file