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 (check-sxml-for-error xml
)
9 (find-nodes-by-name "edit" xml
)))
12 (error 'media-wiki-error
14 :message
"Couldnt find edit results"))
15 (unless (string-equal "success" (sxml-attribute-value "result" alist
))
16 (error 'media-wiki-error
17 :message
(format nil
"Failed to Edit ~A : ~A "
24 (summary "cl-mediawiki:create-page")
26 "Creates a new wiki page
27 If override is true, replace the existing page with the text passed in (if the page already exists)
29 (let* ((tokens (get-action-tokens title
))
33 (token ,(edit-token tokens
))
35 (basetimestamp ,(timestamp tokens
))
43 (parse-api-response-to-sxml (make-api-request parameters
:method
:post
)))))
45 (defun add-new-page-section (title section-title section-text
&key no-create
)
46 "Creates a new == section-title == at the bottom of the page. followed by the specified text"
47 (let* ((tokens (get-action-tokens title
))
51 (token ,(edit-token tokens
))
54 (summary ,section-title
)
55 (basetimestamp ,(timestamp tokens
))
58 (text ,section-text
)))
62 (parse-api-response-to-sxml
63 (make-api-request parameters
:method
:post
)))
66 (defun append-text-to-page
69 (summary "cl-mediawiki:append-text-to-page"))
70 "appends the text the the end of the page (will create the page if neccessary, unless no-create is passed)"
71 (let* ((tokens (get-action-tokens title
))
75 (token ,(edit-token tokens
))
78 (basetimestamp ,(timestamp tokens
))
85 (parse-api-response-to-sxml
86 (make-api-request parameters
:method
:post
)))
89 (defun prepend-text-to-page
91 (summary "cl-mediawiki:prepend-text-to-page")
93 "Adds the text to the beginning of the page named title
94 (will create the page if neccessary unless no-create is true)"
95 (let* ((tokens (get-action-tokens title
))
99 (token ,(edit-token tokens
))
102 (basetimestamp ,(timestamp tokens
))
105 (prependtext ,text
)))
109 (parse-api-response-to-sxml
110 (make-api-request parameters
:method
:post
)))
113 (defun set-page-content
114 (title text
&key no-create
115 (summary "cl-mediawiki:set-page-content"))
116 "sets the text of a wiki page 'title' to the specified 'text',
118 title: The wiki page to set the content of
119 text: The new content that the wiki page should have
120 no-create:, do not create the wiki page if it does not exist
121 summary: The comment associated with changing the page content
123 (let* ((tokens (get-action-tokens title
))
127 (token ,(edit-token tokens
))
130 (basetimestamp ,(timestamp tokens
))
137 (parse-api-response-to-sxml
138 (make-api-request parameters
:method
:post
)))
142 (defun regex-replace-all (regex target-page replacement
&key default-content
(summary "cl-mediawiki:regex-replace-all"))
143 "Does a regex find/replace on the target page. If the page is empty, will set to default content if provided
144 Works by calling get-content then regex-replacing on the content, then calling set-content "
145 (let ((content (get-page-content target-page
)))
146 (set-page-content target-page
148 (cl-ppcre:regex-replace-all regex content replacement
)
150 :no-create
(null default-content
)
156 ;; Copyright (c) 2008 Accelerated Data Works, Russ Tyndall
158 ;; Permission is hereby granted, free of charge, to any person
159 ;; obtaining a copy of this software and associated documentation files
160 ;; (the "Software"), to deal in the Software without restriction,
161 ;; including without limitation the rights to use, copy, modify, merge,
162 ;; publish, distribute, sublicense, and/or sell copies of the Software,
163 ;; and to permit persons to whom the Software is furnished to do so,
164 ;; subject to the following conditions:
166 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
167 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
168 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
169 ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
170 ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
171 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
172 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.