removed dependency on cl-interpol and some other libraries that I was
[cl-mediawiki.git] / src / edit.lisp
blob3bc1503654dfcdf9d35c9c44a101e9b225760673
1 (in-package :cl-mediawiki)
3 (defun check-edit-response (title xml)
4 "Checks for the expected 'success' message
5 signals match-errors assertion-errors and media-wiki-errors
7 (match-response-with-error-reporting
8 (`("api"
9 NIL
10 ("edit"
11 #T(list &rest ?alist)))
12 xml)
13 (assert (string-equal "success" (attribute-value "result" alist))
14 (alist) "Failed to create page: '~a' ~a ~a ~%~%~A" title (attribute-value "result" alist) (string-equal "success "(attribute-value "result" alist)) alist)
19 (defun create-page
20 (title text &key
21 (summary "cl-mediawiki:create-page")
22 (override nil))
23 "Creates a new wiki page
24 If override is true, replace the existing page with the text passed in
26 (let* ((tokens (get-action-tokens title))
27 (parameters
28 (make-parameters
29 `((action edit)
30 (token ,(edit-token tokens))
31 (title ,title)
32 (basetimestamp ,(timestamp tokens))
33 ,(when (not override)
34 '(createonly true))
35 (summary ,summary)
36 (text ,text)))
38 (check-edit-response
39 title
40 (parse-api-response-to-sxml (make-api-request parameters :method :post))))
44 (defun add-new-page-section (title section-title section-text &key no-create)
45 "Creates a new == section-title == at the bottom of the page. followed by the specified text"
46 (let* ((tokens (get-action-tokens title))
47 (parameters
48 (make-parameters
49 `((action edit)
50 (token ,(edit-token tokens))
51 (title ,title)
52 (section new)
53 (summary ,section-title)
54 (basetimestamp ,(timestamp tokens))
55 ,(when no-create
56 '(nocreate T))
57 (text ,section-text)))
59 (check-edit-response
60 title
61 (parse-api-response-to-sxml
62 (make-api-request parameters :method :post)))
65 (defun append-text-to-page
66 (title text &key
67 no-create
68 (summary "cl-mediawiki:append-text-to-page"))
69 "appends the text the the end of the page (will create the page if neccessary)"
70 (let* ((tokens (get-action-tokens title))
71 (parameters
72 (make-parameters
73 `((action edit)
74 (token ,(edit-token tokens))
75 (title ,title)
76 (summary ,summary)
77 (basetimestamp ,(timestamp tokens))
78 ,(when no-create
79 '(nocreate T))
80 (appendtext ,text)))
82 (check-edit-response
83 title
84 (parse-api-response-to-sxml
85 (make-api-request parameters :method :post)))
88 (defun prepend-text-to-page
89 (title text &key
90 (summary "cl-mediawiki:prepend-text-to-page")
91 no-create)
92 "Adds the text to the beginning of the page
93 (will create the page if neccessary unless no-create is true)"
94 (let* ((tokens (get-action-tokens title))
95 (parameters
96 (make-parameters
97 `((action edit)
98 (token ,(edit-token tokens))
99 (title ,title)
100 (summary ,summary)
101 (basetimestamp ,(timestamp tokens))
102 ,(when no-create
103 '(nocreate T))
104 (prependtext ,text)))
106 (check-edit-response
107 title
108 (parse-api-response-to-sxml
109 (make-api-request parameters :method :post)))
112 (defun set-page-content
113 (title text &key no-create
114 (summary "cl-mediawiki:set-page-content"))
115 "sets the text of a wiki page to the specified text"
116 (let* ((tokens (get-action-tokens title))
117 (parameters
118 (make-parameters
119 `((action edit)
120 (token ,(edit-token tokens))
121 (title ,title)
122 (summary ,summary)
123 (basetimestamp ,(timestamp tokens))
124 ,(when no-create
125 '(nocreate T))
126 (text ,text)))
128 (check-edit-response
129 title
130 (parse-api-response-to-sxml
131 (make-api-request parameters :method :post)))