From 03be670f1c2a13931f1b824f22cc9cebe4d61216 Mon Sep 17 00:00:00 2001 From: rich Date: Thu, 23 Sep 2004 15:16:20 +0000 Subject: [PATCH] Linked RA stats into the site. --- MANIFEST | 5 +++ cocanwiki.sql | 3 +- conf/cocanwiki.conf | 4 +- scripts/Makefile | 5 ++- scripts/cocanwiki.ml | 37 +----------------- scripts/cocanwiki_server_settings.ml | 71 +++++++++++++++++++++++++++++++++ scripts/page.ml | 10 ++++- scripts/stats.ml | 76 ++++++++++++++++++++++++++++++++++++ scripts/stats_top.ml | 49 +++++++++++++++++++++++ templates/page.html | 4 +- templates/stats.html | 47 ++++++++++++++++++++++ templates/stats_top.html | 16 ++++++++ 12 files changed, 285 insertions(+), 42 deletions(-) create mode 100644 scripts/cocanwiki_server_settings.ml create mode 100644 scripts/stats.ml create mode 100644 scripts/stats_top.ml create mode 100644 templates/stats.html create mode 100644 templates/stats_top.html diff --git a/MANIFEST b/MANIFEST index 386294f..1ff9732 100644 --- a/MANIFEST +++ b/MANIFEST @@ -57,6 +57,7 @@ scripts/cocanwiki_files.ml 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 @@ -118,6 +119,8 @@ scripts/set_password.ml 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 @@ -172,6 +175,8 @@ templates/send_feedback.txt 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 diff --git a/cocanwiki.sql b/cocanwiki.sql index 99b8127..ca322a8 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -445,7 +445,8 @@ SET SESSION AUTHORIZATION 'rich'; -- CREATE TABLE server_settings ( - "version" integer NOT NULL + "version" integer NOT NULL, + stats_page text ); diff --git a/conf/cocanwiki.conf b/conf/cocanwiki.conf index 80265f3..6cad2c5 100644 --- a/conf/cocanwiki.conf +++ b/conf/cocanwiki.conf @@ -1,5 +1,5 @@ # 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. @@ -56,7 +56,6 @@ RewriteRule ^/_login$ /_bin/login_form.cmo [PT,L] 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. @@ -72,6 +71,7 @@ RewriteRule ^/([^_].*)/edit$ /_bin/edit.cmo?page=$1 [PT,L,QSA] 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. diff --git a/scripts/Makefile b/scripts/Makefile index afcb3ad..f5ddf10 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # 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 @@ -15,6 +15,7 @@ LIB_OBJS := \ cocanwiki_images.cmo \ cocanwiki_template.cmo \ cocanwiki_ok.cmo \ + cocanwiki_server_settings.cmo \ cocanwiki.cmo \ cocanwiki_diff.cmo \ cocanwiki_emailnotify.cmo \ @@ -79,6 +80,8 @@ OBJS := 00-TEMPLATE.cmo \ set_password_form.cmo \ signup.cmo \ sitemap.cmo \ + stats.cmo \ + stats_top.cmo \ undelete_file.cmo \ undelete_file_form.cmo \ undelete_image.cmo \ diff --git a/scripts/cocanwiki.ml b/scripts/cocanwiki.ml index 61351d3..e6fb225 100644 --- a/scripts/cocanwiki.ml +++ b/scripts/cocanwiki.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 @@ -34,41 +34,6 @@ module Pool = DbiPool (Dbi_postgres) *) 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) diff --git a/scripts/cocanwiki_server_settings.ml b/scripts/cocanwiki_server_settings.ml new file mode 100644 index 0000000..cb4212a --- /dev/null +++ b/scripts/cocanwiki_server_settings.ml @@ -0,0 +1,71 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * 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 diff --git a/scripts/page.ml b/scripts/page.ml index db576c8..bd4d05a 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * 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 @@ -30,6 +30,7 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_ok open Cocanwiki_date +open Cocanwiki_server_settings (* Maximum level of redirection. *) let max_redirect = 4 @@ -63,6 +64,9 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = 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' = @@ -92,6 +96,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = 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 @@ -170,6 +176,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = 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 diff --git a/scripts/stats.ml b/scripts/stats.ml new file mode 100644 index 0000000..e92d182 --- /dev/null +++ b/scripts/stats.ml @@ -0,0 +1,76 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * 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 diff --git a/scripts/stats_top.ml b/scripts/stats_top.ml new file mode 100644 index 0000000..48ddea9 --- /dev/null +++ b/scripts/stats_top.ml @@ -0,0 +1,49 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * 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 diff --git a/templates/page.html b/templates/page.html index 0e43274..f65c494 100644 --- a/templates/page.html +++ b/templates/page.html @@ -66,7 +66,9 @@
  • Largest pages
  • Images
  • Files
  • -
  • Stats
  • +::if(has_stats):: +
  • Stats
  • +::end:: ::end:: ::if(can_manage_users)::
  • Users
  • diff --git a/templates/stats.html b/templates/stats.html new file mode 100644 index 0000000..9c78456 --- /dev/null +++ b/templates/stats.html @@ -0,0 +1,47 @@ + + + +Page stats + + + + + + + + + +<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&nbsp;page</a> </li> +<li> <a href="/_sitemap">Sitemap</a> </li> +<li> <a href="/_recent">Recent&nbsp;changes</a> </li> +</ul> + +<div id="menu_div"> +<ul id="bottommenu" class="menu"> +<li class="first"> <a href="/">Home&nbsp;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 &copy; ::year::</a> </li> +<li> Powered by <a href="http://sandbox.merjis.com/">::cocanwiki_package_html:: ::cocanwiki_version_html::</a> </li> +</ul> +</div> + + + + + \ No newline at end of file diff --git a/templates/stats_top.html b/templates/stats_top.html new file mode 100644 index 0000000..4b7d420 --- /dev/null +++ b/templates/stats_top.html @@ -0,0 +1,16 @@ + + + +Stats navigation frame + + + + + + + + + \ No newline at end of file -- 1.8.3.1