Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 76 lines (63 sloc) 3.348 kB
e20b495 @vsedach Added article deletion/undeletion
authored
1 (in-package #:cliki2)
2 (in-readtable cliki2)
3
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
4 (defun output-undo-button (revision)
e20b495 @vsedach Added article deletion/undeletion
authored
5 (unless (youre-banned?)
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
6 #H[<input type="hidden" name="undo-revision" value="${ (revision-date revision) }" />
35ec483 @vsedach Made article transactions atomic and consistent
authored
7 (<input type="submit" name="undo" value="undo" class="undo" />)]))
e20b495 @vsedach Added article deletion/undeletion
authored
8
9fe84e7 @vsedach Added links to various pages to make revision comparisons easier.
authored
9 (defun output-compare-link (old new text)
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
10 #H[(<a class="internal" href="$(#/site/compare-revisions?article={ (parent-title new) }&old={ (revision-date old) }&diff={ (revision-date new) })">${text}</a>)])
9fe84e7 @vsedach Added links to various pages to make revision comparisons easier.
authored
11
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
12 (defpage /site/history () (article)
13 (let ((article-obj (find-article article :error t)))
8e5e040 @vsedach Added ATOM feed links to history pages
authored
14 (setf *title* #?'History of article: "${ (article-title article-obj) }"'
f97eed8 @vsedach Added a backlink index to pages
authored
15 *header* #?[<link rel="alternate" type="application/atom+xml" title="article changes" href="$(#/site/feed/article.atom?title={ (article-title article-obj) })">]
16 *footer* (article-footer (latest-revision article-obj)))
e20b495 @vsedach Added article deletion/undeletion
authored
17
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
18 #H[<h1>History of article ] (pprint-article-link article) #H[</h1>
8e5e040 @vsedach Added ATOM feed links to history pages
authored
19 <a class="internal" href="$(#/site/feed/article.atom?title={ (article-title article-obj) })">ATOM feed</a>
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
20 <form method="post" action="$(#/site/history-with-undo)">
21 <input type="hidden" name="article" value="${ article }" />
e20b495 @vsedach Added article deletion/undeletion
authored
22 <input type="submit" value="Compare selected versions" />
23 <table id="pagehistory">]
24
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
25 (loop for rhead on (revisions article-obj)
e20b495 @vsedach Added article deletion/undeletion
authored
26 for revision = (car rhead)
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
27 for author = (author-name revision)
28 for first = t then nil do
e20b495 @vsedach Added article deletion/undeletion
authored
29 (flet ((radio (x)
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
30 #H[<td><input type="radio" name="${x}" value="${ (revision-date revision) }" /></td>]))
e20b495 @vsedach Added article deletion/undeletion
authored
31 #H[<tr><td>]
32 (awhen (cadr rhead)
9fe84e7 @vsedach Added links to various pages to make revision comparisons easier.
authored
33 (output-compare-link it revision "prev"))
e20b495 @vsedach Added article deletion/undeletion
authored
34 #H[</td>]
35 (radio "old") (radio "diff")
36 #H[<td>] (pprint-revision-link revision)
717ba38 @vsedach Escaped HTML for titles
authored
37 #H[ ${ (account-link author) } (<em>${ (escape-for-html (summary revision)) }</em>) ]
e20b495 @vsedach Added article deletion/undeletion
authored
38 (when first
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
39 (output-undo-button revision))
e20b495 @vsedach Added article deletion/undeletion
authored
40 #H[</td></tr>]))
41
42 #H[</table>
43 <input type="submit" value="Compare selected versions" />
f97eed8 @vsedach Added a backlink index to pages
authored
44 </form>]))
e20b495 @vsedach Added article deletion/undeletion
authored
45
46 ;;; undo
47
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
48 (defpage /site/not-latest "Revision not the latest" (article)
e20b495 @vsedach Added article deletion/undeletion
authored
49 #H[Can't undo this revision because it is not the latest.
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
50 <a href="$(#/site/history?article={article})">Go back to history page</a>.])
e20b495 @vsedach Added article deletion/undeletion
authored
51
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
52 (defun undo-latest-revision (article)
53 (let ((revision (first (revisions article)))
54 (restored-revision (second (revisions article))))
55 (when restored-revision
56 (add-revision
57 article (revision-content restored-revision)
088d90e @vsedach Removed all the deleted article crap. To delete an article, just dele…
authored
58 #?"undid last revision by ${ (author-name revision) }"))))
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
59
60 (defun undo-revision (article-title revision-date)
61 (let ((revision (find-revision article-title revision-date))
62 (article-object (find-article article-title)))
63 (if (eq revision (latest-revision article-object))
64 (progn (unless (youre-banned?)
65 (undo-latest-revision article-object))
66 (article-link article-title))
67 #/site/not-latest?article={article-title})))
68
69 (defhandler /site/history-with-undo (article old diff undo undo-revision)
e20b495 @vsedach Added article deletion/undeletion
authored
70 (if undo
1556535 @vsedach Removed bknr.datastore and used file storage for persistence instead.
authored
71 (undo-revision article undo-revision)
72 #/site/compare-revisions?article={article}&old={old}&diff={diff}))
73
74 (defhandler /site/undo (article undo-revision)
75 (undo-revision article undo-revision))
Something went wrong with that request. Please try again.