--- /dev/null
+(* 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
--- /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>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 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>
+
+</body>
+</html>
\ No newline at end of file