Common Lisp Package: NET.ACCELERATION.CL-MEDIAWIKI

This package provides a client to the mediawiki API, which is used by Wikipedia among others. Exported functions fairly closely mirror the command structure of the API, which is summarized here: http://en.wikipedia.org/w/api.php Usage example: ;; setup to use only Wikipedia CL-USER> (setf cl-mediawiki:*mediawiki* (cl-mediawiki:with-mediawiki ("http://en.wikipedia.org/w") cl-mediawiki:*mediawiki*)) ;; get content of article titled Pigment CL-USER> (cl-mediawiki:get-page-content "Pigment") ;; get the revids and sizes of its last 10 revisions CL-USER> (cl-mediawiki:get-revisions "Pigment" :rvprop "ids|user|size" :rvlimit 10) Further documentation is in README.mediawiki.

README:

FUNCTION

Public

ADD-NEW-PAGE-SECTION (TITLE SECTION-TITLE SECTION-TEXT &KEY NO-CREATE)

Creates a new == section-title == at the bottom of the page. followed by the specified text

APPEND-TEXT-TO-PAGE (TITLE TEXT &KEY NO-CREATE (SUMMARY cl-mediawiki:append-text-to-page))

appends the text the the end of the page (will create the page if neccessary, unless no-create is passed)

CREATE-PAGE (TITLE TEXT &KEY (SUMMARY cl-mediawiki:create-page) (OVERRIDE NIL))

Creates a new wiki page If override is true, replace the existing page with the text passed in (if the page already exists)

FIND-PAGE-SECTION (PAGE-TITLE SECTION-NAME)

searches the the given page for the given section name. returns nil or (number name anchor rvsection)

GET-ACTION-TOKENS (TITLES &KEY (INTOKEN EDIT) EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS)

Gets the tokens necessary for perform edits. Parameters: titles - the title of the page we wish to edit intoken - which tokens do we want (out of :edit :move :delete :block :unblock or a list of those) Examples: (get-action-tokens "Physics") (get-action-tokens "Physics" :intoken '(:edit :move :delete)) (get-action-tokens '("Main Page" "User:Russ") :intoken '(:move :edit :delete :protect)) Returns: a token bag (or list of them if you asked for multiple pages)

GET-IMAGE-INFO (TITLES &KEY IIURLHEIGHT IIURLWIDTH IIEND IISTART IILIMIT (IIPROP timestamp|user|comment|url|size|sha1|mime|metadata|archivename) EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS)

Gets the info for a given image (or file) as an alist Parameters: titles - the title of the image we wish to retrieve the info of iiprop - Which properties to get Possible values (separate with '|'): timestamp, user, comment, url, size, sha1, mime, metadata, archivename. Default is all. iilimit - How many image revisions to return (1 by default) iistart - Timestamp to start listing from. Use this to continue a previous query. iiend - Timestamp to stop listing at iiurlwidth - If iiprop=url is set, a URL to an image scaled to this width will be returned as well. Old versions of images can't be scaled iiurlheight - Similar to iiurlwidth Example: (get-image-info "Image:Albert Einstein Head.jpg" :iiprop "user|comment") Returns: a list of alists of attributes about the requested revisions of the image, and a continuation if there is one.

GET-PAGE-CONTENT (TITLES &KEY RVSECTION EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS)

Get the content for a given page. Does not accept revid. To get the content of older pages, use get-revisions with the rvprop content tag. Parameters: titles - the title of the page rvsection - only retrieve the content of this section (a number indicating which section, not the section name) Examples: (get-page-content "Physics") Returns: a string with the given page content

GET-PAGE-INFO (TITLES &KEY EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS)

Gets the info for a given page as an alist Parameters: titles - the title of the page we wish to retrieve the info of Returns: an alist of attributes about the page

GET-REVISIONS (TITLES &KEY PAGEIDS REVIDS PROP LIST META GENERATOR REDIRECTS INDEXPAGEIDS EXPORT EXPORTNOWRAP (RVPROP ids|flags|timestamp|user|comment|size) (RVLIMIT 550) RVSTARTID RVENDID RVSTART RVEND RVDIR RVUSER RVEXCLUDEUSER RVCONTINUE RVDIFFTO)

Gets the revisions of a page. Parameters: titles - the title of the page we wish to retrieve the info of rvprop: - Which properties to get for each revision Possible values (separate with '|'): ids, flags, timestamp, user, comment, size, content. Default is all except content. rvcontinue: - When more results are available, use this to continue (This is different from the returned continuation.) rvlimit: - The maximum number of revisions to return (enum) rvstartid: - Revision ID to start listing from. (enum) rvendid: - Revision ID to stop listing at. (enum) rvstart: - Timestamp to start listing from. (enum) rvend: - Timestamp to end listing at. (enum) rvdir: - Direction to list in. (enum) Possible values: older, newer. Default: older rvuser: - Only list revisions made by this user rvexcludeuser: - Do not list revisions made by this user rvdiffto: - Revision ID to diff each revision to. Possible values (an id, "prev", "next" or "cur"). Examples: (get-revisions "Pigment" :rvprop "ids|user|size" :rvlimit 10) (get-revisions "Physics" :rvlimit 10) Returns: list of revisions as alists and (if there is one) a continuation, which is the rvstart id to pass in the next call to get more results.

GET-REVISIONS-RESULT (&REST ARGS)

Like get-revisions, but returns a query-result object

LIST-PAGE-SECTIONS (PAGE-TITLE)

lists sections in a page, returns list of (number name anchor rvsection) rvsection is suitable to for the :rvsection param of get-page-content

PAGES-THAT-EMBED (EITITLE &KEY EILIMIT EIFILTERREDIR EINAMESPACE EICONTINUE EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS TITLES)

List pages that embed a given template or other page Parameters: eititle - Title to search. If null, titles= parameter will be used instead, but will be obsolete soon. eicontinue - When more results are available, use this to continue. einamespace - The namespace to enumerate. Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103 eifilterredir - How to filter for redirects One value: all, redirects, nonredirects Default: all eilimit - How many total pages to return. No more than 500 (5000 for bots) allowed. Default: 10 Examples: (pages-that-embed "Template:Client") Returns: a list of pagetitles and a continuation (if there is one)

PREPEND-TEXT-TO-PAGE (TITLE TEXT &KEY (SUMMARY cl-mediawiki:prepend-text-to-page) NO-CREATE)

Adds the text to the beginning of the page named title (will create the page if neccessary unless no-create is true)

RECENT-CHANGES (&KEY TITLES PAGEIDS REVIDS PROP LIST META GENERATOR REDIRECTS INDEXPAGEIDS EXPORT EXPORTNOWRAP RCSTART RCEND RCDIR RCNAMESPACE (RCPROP user|comment|title|timestamp|ids) RCSHOW RCLIMIT RCTYPE)

Enumerates the recent changes Parameters: rcstart - The timestamp to start enumerating from. rcend - The timestamp to end enumerating. rcdir - In which direction to enumerate. One value: newer, older Default: older rcnamespace - Filter log entries to only this namespace(s) Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103 rctitles - Filter log entries to only these page titles rcprop - Include additional pieces of information Values (separate with '|'): user, comment, flags, timestamp, title, ids, sizes, redirect, patrolled Default: title|timestamp|ids rcshow - Show only items that meet this criteria. For example, to see only minor edits done by logged-in users, set show=minor|!anon Values (separate with '|'): minor, !minor, bot, !bot, anon, !anon, redirect, !redirect, patrolled, !patrolled rclimit - How many total changes to return. No more than 500 (5000 for bots) allowed. Default: 10 rctype - Which types of changes to show. Values (separate with '|'): edit, new, log Returns:

REGEX-REPLACE-ALL (REGEX TARGET-PAGE REPLACEMENT &KEY DEFAULT-CONTENT (SUMMARY cl-mediawiki:regex-replace-all))

Does a regex find/replace on the target page. If the page is empty, will set to default content if provided Works by calling get-content then regex-replacing on the content, then calling set-content

SET-PAGE-CONTENT (TITLE TEXT &KEY NO-CREATE (SUMMARY cl-mediawiki:set-page-content))

sets the text of a wiki page 'title' to the specified 'text', title: The wiki page to set the content of text: The new content that the wiki page should have no-create:, do not create the wiki page if it does not exist summary: The comment associated with changing the page content

SET-SECTION-CONTENT (TITLE RVSECTION TEXT &KEY (SUMMARY cl-mediawiki:set-section-content))

Sets the text of section 'rvsection' on page 'title' to 'text'. 'text' MUST contain the section title markup!

UPLOAD (PATH &KEY (FILENAME (FILE-NAMESTRING PATH)) (COMMENT uploaded via cl-mediawiki) (TEXT ) WATCH IGNOREWARNINGS &AUX (PATH (TRUENAME PATH)))

uploads a file from a local path. returns 2 values: 1. string for the filename according to mediawiki (eg: Foo.png) 2. string for the wikimarkup to link to the file (eg: [[File:Foo.png]])

USER-CONTRIBS (UCUSER &KEY UCSHOW (UCPROP comment|title|timestamp|ids) UCNAMESPACE UCDIR UCUSERPREFIX UCEND UCSTART UCLIMIT EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP REVIDS PAGEIDS TITLES)

Get all edits by a user Parameters: uclimit - The maximum number of contributions to return. No more than 500 (5000 for bots) allowed. Default: 10 ucstart - The start timestamp to return from. ucend - The end timestamp to return to. ucuser - The user to retrieve contributions for. ucuserprefix - Retrieve contibutions for all users whose names begin with this value. Overrides ucuser. ucdir - The direction to search (older or newer). One value: newer, older Default: older ucnamespace - Only list contributions in these namespaces Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103 ucprop - Include additional pieces of information Values (separate with '|'): ids, title, timestamp, comment, flags Default: ids|title|timestamp|flags|comment ucshow - Show only items that meet this criteria, e.g. non minor edits only: show=!minor Values (separate with '|'): minor, !minor

Undocumented

LOGIN (LGNAME LGPASSWORD &KEY LGDOMAIN)

Private

%LOGIN (LGNAME LGPASSWORD &KEY LGDOMAIN LGTOKEN)

This module is used to login and get the authentication tokens. In the event of a successful log-in, a cookie will be attached to your session. In the event of a failed log-in, you will not be able to attempt another log-in through this method for 5 seconds. This is to prevent password guessing by automated password crackers. This module only accepts POST requests. Parameters: lgname - User Name lgpassword - Password lgdomain - Domain (optional) lgtoken - Login token obtained in first request Example: api.php?action=login&lgname=user&lgpassword=password

%PARSE-TEXT-SECTIONS (TEXT &KEY)

parses the given text and lists sections in that content. returns list of (number name anchor rvsection)

CHECK-API-RESPONSE (XML NAME DATUM)

Checks for the expected 'success' message in the node matching the name parameter signals match-errors assertion-errors and media-wiki-errors, printing datum in error messages. returns values: 1. the xml response 2. the alist of node attributes for the node we checked for success

CHECK-EDIT-RESPONSE (DATUM XML)

Checks for the expected 'success' message signals match-errors assertion-errors and media-wiki-errors, printing datum in error messages.

CHECK-SXML-FOR-ERROR (XML)

search the response for <api><error attribs></api>

ENSURE-LIST (X)

just ensure that you have alist

FIND-NODES-BY-NAME (NAME TREE)

find all sxml nodes with a given name

FIND-TREE (PRED TREE)

find a tree based on a predicate

GET-PAGE-CONTENT-BY-REVID (REVIDS &KEY RVSECTION EXPORTNOWRAP EXPORT INDEXPAGEIDS REDIRECTS GENERATOR META LIST PROP PAGEIDS TITLES)

Get the content for a given revid Parameters: revids - the revision id of the page rvsection - only retrieve the content of this section (a number indicating which section, not the section name) Examples: (get-page-content 446445813) Returns: a string with the given page content

GET-REVISIONS-AND-CLOSURE (&REST ARGS)

Like get-revisions, but also returns a closure for a follow-up query. This closure can be called outside of a with-mediawiki form. Example: (multiple-value-list (with-mediawiki ("http://en.wikipedia.org/w") (get-revisions-and-closure "Pigment" :rvlimit 3))) (multiple-value-list (funcall (elt * 2))) (multiple-value-list (funcall (elt * 2))) etc..

LIST-CATEGORY-MEMBERS (CMTITLE &KEY CMENDSORTKEY CMSTARTSORTKEY CMEND CMSTART CMDIR CMSORT CMLIMIT CMCONTINUE CMNAMESPACE CMPROP REQUESTID MAXAGE SMAXAGE MAXLAG VERSION TITLES PAGEIDS REVIDS PROP LIST META GENERATOR REDIRECTS INDEXPAGEIDS EXPORT EXPORTNOWRAP)

List all pages in a given category. Parameters: cmtitle - Which category to enumerate (required). Must include Category: prefix cmprop - What pieces of information to include Values (separate with '|'): ids, title, sortkey, timestamp Default: ids|title cmnamespace - Only include pages in these namespaces Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101 cmcontinue - For large categories, give the value retured from previous query cmlimit - The maximum number of pages to return. No more than 500 (5000 for bots) allowed. Default: 10 cmsort - Property to sort by. One value: sortkey, timestamp,Default: sortkey cmdir - In which direction to sort. One value: asc, desc Default: asc cmstart - Timestamp to start listing from. Can only be used with cmsort=timestamp cmend - Timestamp to end listing at. Can only be used with cmsort=timestamp cmstartsortkey - Sortkey to start listing from. Can only be used with cmsort=sortkey cmendsortkey - Sortkey to end listing at. Can only be used with cmsort=sortkey Examples: Get first 10 pages in [[Category:Physics]]: (list-category-members "Category:Physics") Get page info about first 10 pages in [[Category:Physics]]: (list-category-members "Category:Physics" :prop 'info) Returns a list of alists, each representing a CategoryMember alist keys are: :title :ns :pageid

MAKE-API-REQUEST (API-PARAMS &KEY (BASIC-AUTHORIZATION (AUTH *MEDIAWIKI*)) (FORCE-SSL NIL FORCE-SSL-P) (METHOD GET))

Calls the media wiki api providing the specified parameters

MAKE-PARAMETERS (PARAMS)

Takes a list of bindings (:key :val) and prepares them for transit by converting them to strings (if either the pair is nil or the value is nil, we drop that param)

MAP-SXML-TREE (FN TREE)

Do a depth first traversal of some set of trees calling fn on every non-nil element.

SYMBOLIZE-STRING (STR &OPTIONAL (PACKAGE KEYWORD))

Turns a string into a happy symbol ex: ''foo bar_bast'' -> FOO-BAR-BAST

Undocumented

CONVERT-SXML-ATTRIBS-TO-ALIST (SXML-ATTRIBS)

PARSE-API-RESPONSE-TO-SXML (CONTENT)

SXML-ATTRIBUTE-VALUE (KEY ALIST)

MACRO

Public

Undocumented

WITH-MEDIAWIKI ((OBJ) &BODY BODY)

Private

APPENDF (PLACE &REST LISTS &ENVIRONMENT ENV)

Modify-macro for APPEND. Appends LISTS to the place designated by the first argument.

DEFINE-PROXY (NAME &KEY CORE REQ BASED-ON PROPS DOC (PROCESSOR 'IDENTITY) (METHOD GET))

Defines a function with NAME with REQ required parameters. The symbols in the BASED-ON and PROPS lists are concatenated with pairs from the CORE list and passed to the MAKE-PARAMETERS function.

GENERIC-FUNCTION

Public

Undocumented

GET-MORE-RESULTS (QR &KEY (AT-LEAST 0) (PAUSE 1))

HAS-MORE-RESULTS-P (QR)

Private

Undocumented

CODE (CONDITION)

SETFCODE (NEW-VALUE CONDITION)

DELETE-TOKEN (TOKEN-BAG)

EDIT-TOKEN (TOKEN-BAG)

GET-MORE-RESULTS-ONCE (QR)

MESSAGE (CONDITION)

SETFMESSAGE (NEW-VALUE CONDITION)

MOVE-TOKEN (TOKEN-BAG)

OBJ (CONDITION)

SETFOBJ (NEW-VALUE CONDITION)

SLOT-ACCESSOR

Public

Undocumented

RESULTS (OBJECT)

SETFRESULTS (NEW-VALUE OBJECT)

Private

PAGE-ATTRIBUTES (OBJECT)

An alist of page attributes returned by the api

SETFPAGE-ATTRIBUTES (NEW-VALUE OBJECT)

An alist of page attributes returned by the api

TOKENS (OBJECT)

either a single token, or an alist mapping type to value

SETFTOKENS (NEW-VALUE OBJECT)

either a single token, or an alist mapping type to value

Undocumented

AUTH (OBJECT)

SETFAUTH (NEW-VALUE OBJECT)

TIMESTAMP (OBJECT)

SETFTIMESTAMP (NEW-VALUE OBJECT)

URL (OBJECT)

SETFURL (NEW-VALUE OBJECT)

VARIABLE

Public

*DEFAULT-EXTERNAL-FORMAT*

sets as the drakma default coding system

*MEDIAWIKI*

the current instance of media wiki we are dealing with (mostly for use with with-mediawiki)

Private

+DEFAULT-QUERY-PARAMS+

The parameters that are available for any action=query api call

CLASS

Public

QUERY-RESULT

Accumulating result to a get-revisions-result query. Use has-more-results-p to check if there are more results available. Use get-more-results to get them through one or more queries.

Undocumented

MEDIAWIKI

Private

Undocumented

TOKEN-BAG

CONDITION

Private

Undocumented

MEDIA-WIKI-ERROR