Largest pages.
authorrich <rich>
Tue, 21 Sep 2004 17:07:57 +0000 (17:07 +0000)
committerrich <rich>
Tue, 21 Sep 2004 17:07:57 +0000 (17:07 +0000)
MANIFEST
scripts/.depend
scripts/Makefile
scripts/largest_pages.ml [new file with mode: 0644]
templates/largest_pages.html [new file with mode: 0644]
templates/page.html

index c9f2e7a..26b2b46 100644 (file)
--- 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
index 85606ed..ca05094 100644 (file)
@@ -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 
index 041205e..0a0be74 100644 (file)
@@ -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 (file)
index 0000000..7f1c53a
--- /dev/null
@@ -0,0 +1,75 @@
+(* COCANWIKI - a wiki written in Objective CAML.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * 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 (file)
index 0000000..8745c16
--- /dev/null
@@ -0,0 +1,62 @@
+<!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>Largest pages</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>
+
+<h1>Largest pages</h1>
+
+<table class="top_table">
+<tr>
+<th> Page </th>
+<th> Size<sup>1</sup> </th>
+<th> Typical download time<sup>2</sup> </th>
+</tr>
+::table(pages)::
+<tr>
+<td> <a href="/::page_html_tag::">::title_html::</a> </td>
+<td class="number"> ::size_html:: </td>
+<td class="number"> ::download_time_html:: </td>
+</tr>
+::end::
+</table>
+
+<p>
+<sup>1</sup> Size does not include images.
+</p>
+
+<p>
+<sup>2</sup> Typical download time based on a 56 kbps modem
+user and includes the overhead of opening a connection and
+rendering the page.
+</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>
+
+</body>
+</html>
\ No newline at end of file
index 6d7e0ec..91d8735 100644 (file)
@@ -63,6 +63,7 @@
 <li> <a href="/::page_html_tag::/history">Versions of this page</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="/::page_html_tag::/editcss">Edit stylesheet for this page</a> </li>
 <li> <a href="/_bin/edit_sitemenu.cmo">Edit site menu</a> </li>
 ::end::