File: page_revisions.ml

package info (click to toggle)
nurpawiki 1.2.3-10
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 1,400 kB
  • ctags: 1,581
  • sloc: ml: 2,869; sh: 119; makefile: 54
file content (65 lines) | stat: -rw-r--r-- 1,927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(* Copyright (c) 2006-2008 Janne Hellsten <jjhellst@gmail.com> *)

(* 
 * 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.
 * If not, see <http://www.gnu.org/licenses/>. 
 *)

open Eliom_content.Html5.F

open Eliom_parameter
open Eliom_service

open Lwt
open ExtList
open ExtString

open Services
open Types

module Db = Database

let revision_table page_descr =
  lwt revisions = Db.query_page_revisions page_descr in

  let page_link descr (rev:int) = 
    a ~service:wiki_view_page [pcdata ("Revision "^(string_of_int rev))]
      (descr, (None, (Some rev, None))) in

  let rows =
    List.map 
      (fun r ->
         tr [td [page_link page_descr r.pr_revision];
             td [pcdata r.pr_created];
             td [pcdata (Option.default "" r.pr_owner_login)]])
      revisions in

  return
    [table @@
       (tr [th [pcdata "Revision"]; th [pcdata "When"]; th [pcdata "Changed by"]]) ::
       rows]


let view_page_revisions page_descr =
  Session.with_guest_login
    (fun cur_user ->
       revision_table page_descr >>= fun revisions ->
       return
         (Html_util.html_stub
            (Html_util.navbar_html ~cur_user
               (h1 [pcdata (page_descr ^ " Revisions")] :: revisions))))

(* /page_revisions?page_id=<id> *)
let _ =
  Eliom_registration.Html5.register page_revisions_page
    (fun page_descr () ->
       view_page_revisions page_descr)