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
12 (assert (string-equal "success" (sxml-attribute-value "result" alist
))
13 (alist) "Failed to create page: '~a' ~a ~a ~%~%~A" title
(sxml-attribute-value "result" alist
) (string-equal "success "(sxml-attribute-value "result" alist
)) alist
)
20 (summary "cl-mediawiki:create-page")
22 "Creates a new wiki page
23 If override is true, replace the existing page with the text passed in (if the page already exists)
25 (let* ((tokens (get-action-tokens title
))
29 (token ,(edit-token tokens
))
31 (basetimestamp ,(timestamp tokens
))
39 (parse-api-response-to-sxml (make-api-request parameters
:method
:post
))))
43 (defun add-new-page-section (title section-title section-text
&key no-create
)
44 "Creates a new == section-title == at the bottom of the page. followed by the specified text"
45 (let* ((tokens (get-action-tokens title
))
49 (token ,(edit-token tokens
))
52 (summary ,section-title
)
53 (basetimestamp ,(timestamp tokens
))
56 (text ,section-text
)))
60 (parse-api-response-to-sxml
61 (make-api-request parameters
:method
:post
)))
64 (defun append-text-to-page
67 (summary "cl-mediawiki:append-text-to-page"))
68 "appends the text the the end of the page (will create the page if neccessary, unless no-create is passed)"
69 (let* ((tokens (get-action-tokens title
))
73 (token ,(edit-token tokens
))
76 (basetimestamp ,(timestamp tokens
))
83 (parse-api-response-to-sxml
84 (make-api-request parameters
:method
:post
)))
87 (defun prepend-text-to-page
89 (summary "cl-mediawiki:prepend-text-to-page")
91 "Adds the text to the beginning of the page named title
92 (will create the page if neccessary unless no-create is true)"
93 (let* ((tokens (get-action-tokens title
))
97 (token ,(edit-token tokens
))
100 (basetimestamp ,(timestamp tokens
))
103 (prependtext ,text
)))
107 (parse-api-response-to-sxml
108 (make-api-request parameters
:method
:post
)))
111 (defun set-page-content
112 (title text
&key no-create
113 (summary "cl-mediawiki:set-page-content"))
114 "sets the text of a wiki page 'title' to the specified 'text',
116 title: The wiki page to set the content of
117 text: The new content that the wiki page should have
118 no-create:, do not create the wiki page if it does not exist
119 summary: The comment associated with changing the page content
121 (let* ((tokens (get-action-tokens title
))
125 (token ,(edit-token tokens
))
128 (basetimestamp ,(timestamp tokens
))
135 (parse-api-response-to-sxml
136 (make-api-request parameters
:method
:post
)))
139 (defun regex-replace-all (regex target-page replacement
&key default-content
(summary "cl-mediawiki:regex-replace-all"))
140 "Does a regex find/replace on the target page. If the page is empty, will set to default content if provided
141 Works by calling get-content then regex-replacing on the content, then calling set-content "
142 (let ((content (get-page-content target-page
)))
143 (set-page-content target-page
145 (cl-ppcre:regex-replace-all regex content replacement
)
147 :no-create
(null default-content
)
153 ;; Copyright (c) 2008 Accelerated Data Works, Russ Tyndall
155 ;; Permission is hereby granted, free of charge, to any person
156 ;; obtaining a copy of this software and associated documentation files
157 ;; (the "Software"), to deal in the Software without restriction,
158 ;; including without limitation the rights to use, copy, modify, merge,
159 ;; publish, distribute, sublicense, and/or sell copies of the Software,
160 ;; and to permit persons to whom the Software is furnished to do so,
161 ;; subject to the following conditions:
163 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
164 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
165 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
166 ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
167 ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
168 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
169 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.