From a8464d1556a200c7afc908c0418bbd1b38007d3b Mon Sep 17 00:00:00 2001 From: rich Date: Tue, 21 Sep 2004 17:07:57 +0000 Subject: [PATCH 1/1] Largest pages. --- MANIFEST | 2 ++ scripts/.depend | 2 ++ scripts/Makefile | 3 +- scripts/largest_pages.ml | 75 ++++++++++++++++++++++++++++++++++++++++++++ templates/largest_pages.html | 62 ++++++++++++++++++++++++++++++++++++ templates/page.html | 1 + 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 scripts/largest_pages.ml create mode 100644 templates/largest_pages.html diff --git a/MANIFEST b/MANIFEST index c9f2e7a..26b2b46 100644 --- a/MANIFEST +++ b/MANIFEST @@ -93,6 +93,7 @@ scripts/history.ml scripts/hoststyle.ml scripts/image.ml scripts/images.ml +scripts/largest_pages.ml scripts/login.ml scripts/login_form.ml scripts/logout.ml @@ -148,6 +149,7 @@ templates/files.html templates/forgot_password_form.html templates/history.html templates/images.html +templates/largest_pages.html templates/login_form.html templates/ok_error.html templates/page.html diff --git a/scripts/.depend b/scripts/.depend index 85606ed..ca05094 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -90,6 +90,8 @@ image.cmo: cgi_expires.cmo cocanwiki.cmo image.cmx: cgi_expires.cmx cocanwiki.cmx images.cmo: cocanwiki.cmo cocanwiki_template.cmi images.cmx: cocanwiki.cmx cocanwiki_template.cmx +largest_pages.cmo: cocanwiki.cmo cocanwiki_template.cmi +largest_pages.cmx: cocanwiki.cmx cocanwiki_template.cmx login.cmo: cocanwiki.cmo cocanwiki_ok.cmo login.cmx: cocanwiki.cmx cocanwiki_ok.cmx login_form.cmo: cocanwiki.cmo cocanwiki_strings.cmo cocanwiki_template.cmi diff --git a/scripts/Makefile b/scripts/Makefile index 041205e..0a0be74 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,5 +1,5 @@ # Makefile for COCANWIKI. -# $Id: Makefile,v 1.16 2004/09/21 15:55:48 rich Exp $ +# $Id: Makefile,v 1.17 2004/09/21 17:07:58 rich Exp $ include ../Makefile.config @@ -54,6 +54,7 @@ OBJS := 00-TEMPLATE.cmo \ hoststyle.cmo \ image.cmo \ images.cmo \ + largest_pages.cmo \ login.cmo \ login_form.cmo \ logout.cmo \ diff --git a/scripts/largest_pages.ml b/scripts/largest_pages.ml new file mode 100644 index 0000000..7f1c53a --- /dev/null +++ b/scripts/largest_pages.ml @@ -0,0 +1,75 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: largest_pages.ml,v 1.1 2004/09/21 17:07:58 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 + +let limit = 50 +let modem_speed = 56000 / 10 (* 56kbps modem. *) +let overhead = 2 (* Number of seconds to open connection + render page. *) + +let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = + let template = get_template dbh hostid "largest_pages.html" in + + (* Grab the pages from the database, ordered by size. + * NB. At the moment we count the size of the markup, which is only an + * approximation of the final size of the page. Also, we are not taking + * into account images. + *) + let sth = + dbh#prepare_cached + "select p.id, p.url, p.title, sum (length (c.content)) + from pages p, contents c + where p.hostid = ? and p.url is not null and p.redirect is null + and c.pageid = p.id group by 1, 2, 3 order by 4 desc" in + sth#execute [`Int hostid]; + + let table = + sth#map + (function [`Int pageid; `String page; `String title; `Int size] -> + let download_time = overhead + size / modem_speed in (* seconds *) + let download_time = + if download_time <= 4 then "<= 4 s" + else if download_time < 60 then sprintf "%d s" download_time + else sprintf "%d m %d s" (download_time / 60) (download_time mod 60) + in + + let size = + if size < 4096 then sprintf "%d bytes" size + else sprintf "%d K" (size / 1024) in + + [ "pageid", Template.VarString (string_of_int pageid); + "page", Template.VarString page; + "title", Template.VarString title; + "size", Template.VarString size; + "download_time", Template.VarString download_time ] + | _ -> assert false) in + template#table "pages" table; + + q#template template + +let () = + register_script ~restrict:[CanManageUsers] run diff --git a/templates/largest_pages.html b/templates/largest_pages.html new file mode 100644 index 0000000..8745c16 --- /dev/null +++ b/templates/largest_pages.html @@ -0,0 +1,62 @@ + + + +Largest pages + + + + + +

Largest pages

+ + + + + + + +::table(pages):: + + + + + +::end:: +
Page Size1 Typical download time2
::title_html:: ::size_html:: ::download_time_html::
+ +

+1 Size does not include images. +

+ +

+2 Typical download time based on a 56 kbps modem +user and includes the overhead of opening a connection and +rendering the page. +

+ + + + + + + + + \ No newline at end of file diff --git a/templates/page.html b/templates/page.html index 6d7e0ec..91d8735 100644 --- a/templates/page.html +++ b/templates/page.html @@ -63,6 +63,7 @@
  • Versions of this page
  • Images
  • Files
  • +
  • Largest pages
  • Edit stylesheet for this page
  • Edit site menu
  • ::end:: -- 1.8.3.1