OSDN Git Service

start
[hmh/wiki.git] / lib.ml
1 (defun authorize (proj)
2         (setvar 'uid (remote-user))
3         (sql "select a.UID,Login,Name,case when b.UID notNull then '1' else '' end from Member a left join Admin b where a.UID=:uid"
4                 :bind ':uid uid
5                 :answer '(UID Login Name Admin))
6
7         (sql "select PID,PublicProj from Project where Proj=:proj"
8                 :bind ':proj proj
9                 :answer '(PID Public))
10         (if (emptyp PID)
11                         (sql "select PID,Proj,PublicProj from Project where Proj='Main'"
12                                 :answer '(PID Proj Public))
13         )
14         (if (not-emptyp Public)
15                         (setvar 'Reader "1")
16         )
17         (if (not-emptyp UID)
18                         (progn
19                                 (if (not-emptyp Public)
20                                                 (setvar 'Reader "1"
21                                                                 'Writer "1")
22                                         (sql "select Reader,Writer from ProjectMember where PID=:pid and UID=:uid"
23                                                 :bind (list ':pid PID ':uid UID)
24                                                 :answer '(Reader Writer))
25                                 )
26                         )
27         )
28         (set-wikivar 'UID 'Login 'Name 'Admin 'PID 'Public 'Reader 'Writer)
29 )
30
31 (defun wiki-page (pid page)
32         (if Reader
33                 (let (wid date title text)
34                         (sql "select a.WID,a.Title,a.WikiText,b.Date from Wiki a,WikiIndex b using(WID) where b.PID=:pid and b.Page=:page"
35                                 :bind (list ':pid pid ':page page)
36                                 :answer '(wid title text date))
37                         (if (and        (emptyp wid)
38                                                 (regex "^-special-" page))
39                                         (sql "select a.WID,a.Title,a.WikiText,b.Date from Wiki a,WikiIndex b using(WID),Project c using(PID) where c.Proj='Main' and b.Page=:page"
40                                                 :bind (list ':page page)
41                                                 :answer '(wid title text date))
42                         )
43
44                         (if (and (emptyp wid) Edit)
45                                         (setvar 'title page
46                                                         'text (concat "=" page "=\n"))
47                         )
48                         (list date title text)
49                 )
50         )
51 )
52
53 (defun wiki-save (page title text)
54         (let (iid wid date uid nwid)
55                 (sql "begin")
56                 (sql "select IID,WID,Date,UID from WikiIndex where PID=:pid and Page=:page"
57                         :bind (list ':pid PID ':page Page)
58                         :answer '(iid wid date uid))
59                 (if (and        (not-emptyp wid)
60                                         (> date (- (now) 10800))
61                                         (= uid UID))
62                                 (progn  (sql "update Wiki set Title=:title,WikiText=:text where WID=:wid"
63                                                         :bind (list ':title title ':text text ':wid wid))
64                                                 (sql "update WikiIndex set IP=:ip,Date=:date where IID=:iid"
65                                                         :bind (list ':ip (remote-ip) ':date (now) ':iid iid))
66                                 )
67                         (sql "insert into Wiki(Title,WikiText) values(:title,:text)"
68                                 :bind (list ':title title ':text text))
69                         (setvar 'nwid (rowid))
70                         (if (emptyp iid)
71                                         (sql "insert into WikiIndex(PID,Page,UID,IP,Date,WID) values(:pid,:page,:uid,:ip,:date,:wid)"
72                                                 :bind (list ':pid PID ':page page ':uid UID ':ip (remote-ip) ':date (now) ':wid nwid))
73                                 (sql "insert into BackupIndex(PID,Page,UID,IP,Date,WID) select PID,Page,UID,IP,Date,WID from WikiIndex where IID=:iid"
74                                         :bind ':iid iid)
75                                 (sql "update WikiIndex set UID=:uid,IP=:ip,Date=:date,WID=:wid where IID=:iid"
76                                         :bind (list ':uid UID ':ip (remote-ip) ':date (now) ':wid nwid ':iid iid))
77                         )
78                 )
79                 (sql "end")
80         )
81 )
82
83 (defun wiki-page-index (cat vpage vtitle)
84         ($sqlite3 'database
85                 (if (null cat)
86                                 (progn
87                                         (sql "select a.Page,b.Title from WikiIndex a,Wiki b using(WID) where a.PID=:pid and a.Page not like 'special-%' order by a.Page"
88                                                 :bind ':pid PID
89                                                 :@answer (list vpage vtitle))
90                                 )
91                         (if (emptyp cat)
92                                         (sql "select a.Page,b.Title from WikiIndex a,Wiki b using(WID) where a.PID=:pid and a.IID not in (select IID from WikiCategory where PID=:pid) and a.Page not like 'special-%' order by a.Page"
93                                                 :bind (list ':pid PID)
94                                                 :@answer (list vpage vtitle))
95                                 (sql "select a.Page,b.Title from CategoryList c,WikiCategory d using(CID),WikiIndex a using(IID),Wiki b using(WID) where a.PID=:pid and c.CName=:cat and a.Page not like 'special-%'  order by a.Page"
96                                         :bind (list ':pid PID ':cat cat)
97                                         :@answer (list vpage vtitle))
98                         )
99                 )
100         )
101 )
102
103 (defun wiki-page-index-special (vpage vtitle)
104         ($sqlite3 'database
105                 (sql "select a.Page,b.Title from WikiIndex a,Wiki b using(WID) where a.PID=:pid and a.Page like 'special-%' order by a.Page"
106                         :bind ':pid PID
107                         :@answer (list vpage vtitle))
108         )
109 )
110
111 (defun wiki-category-index (vname)
112         ($sqlite3 'database
113                 (sql "select CName from CategoryList where PID=:pid order by CName"
114                         :bind ':pid PID
115                         :@answer (list vname))
116         )
117 )
118
119 (defun wiki-add-category (name)
120         (if (not-emptyp name)
121                         ($sqlite3 'database
122                                 (sql "insert into CategoryList(PID,CName) values(:pid,:cat)"
123                                         :bind (list ':pid PID ':cat name))
124                         )
125         )
126 )