+ (* Count the number of changes. *)
+ let sth = dbh#prepare_cached
+ "select count(*)::int4 from pages where hostid = ?" in
+ sth#execute [Some hostid];
+ let count = sth#fetch1int () in
+
+ (* Get the offset and limit specified, and adjust them so that we will
+ * be displaying some changes.
+ *)
+ let offset =
+ try Int32.of_string (q#param "offset") with Not_found -> default_offset in
+ let limit =
+ try Int32.of_string (q#param "limit") with Not_found -> default_limit in
+
+ let limit =
+ if limit < 1 then 1
+ else if limit > max_limit then max_limit
+ else limit in
+ let offset =
+ if offset < 0 then 0
+ else if offset >= count then max 0 (count - limit)
+ else offset in
+
+ template#set "offset" (Int32.to_string offset);
+ template#set "last" (Int32.to_string (min (offset + limit) count - 1));
+ template#set "limit" (Int32.to_string limit);
+ template#set "count" (Int32.to_string count);
+
+ template#conditional "has_next" (offset + limit < count);
+ template#set "next_offset" (Int32.to_string (offset + limit));
+ template#conditional "has_prev" (offset > 0);
+ template#set "prev_offset" (Int32.to_string (max 0 (offset - limit)));
+
+ (* Get the actual changes. *)