Linked RA stats into the site.
authorrich <rich>
Thu, 23 Sep 2004 15:16:20 +0000 (15:16 +0000)
committerrich <rich>
Thu, 23 Sep 2004 15:16:20 +0000 (15:16 +0000)
12 files changed:
MANIFEST
cocanwiki.sql
conf/cocanwiki.conf
scripts/Makefile
scripts/cocanwiki.ml
scripts/cocanwiki_server_settings.ml [new file with mode: 0644]
scripts/page.ml
scripts/stats.ml [new file with mode: 0644]
scripts/stats_top.ml [new file with mode: 0644]
templates/page.html
templates/stats.html [new file with mode: 0644]
templates/stats_top.html [new file with mode: 0644]

index 386294f..1ff9732 100644 (file)
--- 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_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/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/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
 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/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
 templates/undelete_file_form.html
 templates/undelete_image_form.html
 templates/upload_file_form.html
index 99b8127..ca322a8 100644 (file)
@@ -445,7 +445,8 @@ SET SESSION AUTHORIZATION 'rich';
 --
 
 CREATE TABLE server_settings (
 --
 
 CREATE TABLE server_settings (
-    "version" integer NOT NULL
+    "version" integer NOT NULL,
+    stats_page text
 );
 
 
 );
 
 
index 80265f3..6cad2c5 100644 (file)
@@ -1,5 +1,5 @@
 # Apache configuration for COCANWIKI.
 # 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.
 
 # 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 ^/_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 ^/_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 ^/([^_].*)/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.
 RewriteRule ^/([^_].*)/styles.css$ /_bin/pagestyle.cmo?page=$1 [PT,L,QSA]
 
 # Serve pages.
index afcb3ad..f5ddf10 100644 (file)
@@ -1,5 +1,5 @@
 # Makefile for COCANWIKI.
 # 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
 
 
 include ../Makefile.config
 
@@ -15,6 +15,7 @@ LIB_OBJS := \
        cocanwiki_images.cmo \
        cocanwiki_template.cmo \
        cocanwiki_ok.cmo \
        cocanwiki_images.cmo \
        cocanwiki_template.cmo \
        cocanwiki_ok.cmo \
+       cocanwiki_server_settings.cmo \
        cocanwiki.cmo \
        cocanwiki_diff.cmo \
        cocanwiki_emailnotify.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 \
        set_password_form.cmo \
        signup.cmo \
        sitemap.cmo \
+       stats.cmo \
+       stats_top.cmo \
        undelete_file.cmo \
        undelete_file_form.cmo \
        undelete_image.cmo \
        undelete_file.cmo \
        undelete_file_form.cmo \
        undelete_image.cmo \
index 61351d3..e6fb225 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
 (* 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
  *
  * 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"
 
  *)
 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)
 (* 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 (file)
index 0000000..cb4212a
--- /dev/null
@@ -0,0 +1,71 @@
+(* 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
index db576c8..bd4d05a 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
 (* 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
  *
  * 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_template
 open Cocanwiki_ok
 open Cocanwiki_date
+open Cocanwiki_server_settings
 
 (* Maximum level of redirection. *)
 let max_redirect = 4
 
 (* 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
 
   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' =
   (* 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 "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
     (* 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 "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
 
     q#template t
   in
 
diff --git a/scripts/stats.ml b/scripts/stats.ml
new file mode 100644 (file)
index 0000000..e92d182
--- /dev/null
@@ -0,0 +1,76 @@
+(* 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
diff --git a/scripts/stats_top.ml b/scripts/stats_top.ml
new file mode 100644 (file)
index 0000000..48ddea9
--- /dev/null
@@ -0,0 +1,49 @@
+(* 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
index 0e43274..f65c494 100644 (file)
@@ -66,7 +66,9 @@
 <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="/_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>
 ::end::
 ::if(can_manage_users)::
 <li> <a href="/_users">Users</a> </li>
diff --git a/templates/stats.html b/templates/stats.html
new file mode 100644 (file)
index 0000000..9c78456
--- /dev/null
@@ -0,0 +1,47 @@
+<!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&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>
+
+</noframes>
+</frameset>
+
+</html>
\ No newline at end of file
diff --git a/templates/stats_top.html b/templates/stats_top.html
new file mode 100644 (file)
index 0000000..4b7d420
--- /dev/null
@@ -0,0 +1,16 @@
+<!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