removed dependency on cl-interpol and some other libraries that I was
[cl-mediawiki.git] / src / query.lisp
blob8e64dbcc8c646118a46b84a4fd626c820c38bf7c
1 (in-package :cl-mediawiki)
3 (defun get-page-content (title)
4 (let ((parameters
5 (make-parameters
6 `((action query)
7 (prop revisions)
8 (rvprop content)
9 (titles ,title)))))
10 (flet ((page-content (?title sxml)
11 "Accepts sxml and pulls out the page content from it"
12 (declare (ignorable ?title)) ;; supress compiler noise
13 (unify:match (`("api"
15 ("query"
17 ("pages"
19 ("page" ,#t(list ("title" ?title) &rest _)
20 ("revisions"
21 NIL
22 ("rev" NIL ?content))))))
23 sxml)
24 content
25 )))
26 (page-content
27 title
28 (parse-api-response-to-sxml (make-api-request parameters))))
31 (defclass token-bag ()
32 ((timestamp :accessor timestamp :initarg :timestamp :initform nil)
33 (tokens :accessor tokens :initarg :tokens :initform nil
34 :documentation "either a single token, or an
35 alist mapping type to value" )))
37 (defmethod print-object ((token-bag token-bag) stream)
38 (with-accessors ((timestamp timestamp)
39 (tokens tokens)) token-bag
40 (format stream "#<Token-bag ~a ~a>" timestamp tokens)))
42 (defmethod edit-token ((token-bag token-bag))
43 (cdr (assoc :edit (tokens token-bag))))
45 (defmethod move-token ((token-bag token-bag))
46 (cdr (assoc :move (tokens token-bag))))
48 (defmethod delete-token ((token-bag token-bag))
49 (cdr (assoc :delete (tokens token-bag) )))
51 (defun get-action-tokens (title &optional (tokens '(:edit)))
52 "Returns a token bag which is how you get permission to perform
53 edit/move/delete changes
55 tokens, set of : :move :delete :edit"
56 (let* (;; put pipes between the downcased tokens
57 (token-string (format nil "~{~(~a~)~^|~}" tokens))
58 (parameters
59 (make-parameters
60 `((action query)
61 (prop info)
62 (intoken ,token-string)
63 (titles ,title)))
65 (flet ((bind-token-&-ts (?title sxml)
66 "Accepts sxml and pulls out the page content from it"
67 (declare (ignorable ?title)) ;; supress compiler noise
68 (unify:match (`("api"
69 NIL
70 ("query"
71 NIL
72 ("pages"
73 NIL
74 ("page" ,#T(list &rest ?alist)))))
75 sxml)
77 (make-instance
78 'token-bag
79 :tokens
80 (loop for token in tokens
81 collecting
82 (cons token
83 (attribute-value (format nil "~atoken" token) alist)))
84 :timestamp (attribute-value "touched" alist))
85 )))
86 (bind-token-&-ts
87 title
88 (parse-api-response-to-sxml (make-api-request parameters))))