cl-mediawiki

API Reference

cl-mediawiki

A tool to help talk to mediawiki's api.

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.
  • Class MEDIAWIKI
    URL   Accessor: URL
    AUTH   Accessor: AUTH
    COOKIE-JAR   Accessor: COOKIE-JAR
  • Variable *MEDIAWIKI*
  • Macro WITH-MEDIAWIKI ((obj) &body body)
  • Variable *DEFAULT-EXTERNAL-FORMAT*
    :utf-8
    sets as the drakma default coding system
  • Function LOGIN (lgname lgpassword &key lgdomain)
  • Function 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
  • Function 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
  • Function FIND-PAGE-SECTION (page-title section-name)
    searches the the given page for the given section name. returns nil or (number name anchor rvsection)
  • Function 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)
  • Function 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)
  • Function 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
  • Function 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.
  • Function 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.
  • Function GET-LINKS (titles &key plcontinue (plnamespace nil) (pllimit 5000) exportnowrap export indexpageids redirects generator meta list prop revids pageids)
    Gets a list of all links on the provided pages. Parameters: titles - the title of the page we wish to retrieve the info of pllimit - How many links to return. Default: 10. No more than 500 (5000 for bots) allowed. plcontinue - When more results are available, use this to continue. plnamespace - Only list links to pages in these namespaces. (For example, set plnamespace to 0 to get only article links in Wikipedia.) Examples: ; gets 10 results (get-links "Pigment" :pllimit 10) ; gets 10 results, then gets 10 more using a continuation token (multiple-value-bind (firstresults continuation-token) (get-links "Pigment" :pllimit 10) (let ((secondresults (get-links "Pigment" :pllimit 10 :plcontinue continuation-token))) (list firstresults secondresults)))
  • Function 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:
  • Function 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
  • Function LIST-ALL-PAGES (&key titles pageids revids prop list meta generator redirects indexpageids export exportnowrap aplimit apfrom)
    List all pages. Parameters: aplimit - The maximum number of contributions to return. No more than 500 (5000 for bots) allowed. Default: 10 apfrom - Start listing at this title. The title need not exist
  • Function LIST-ALL-USERS (&key titles pageids revids prop list meta generator redirects indexpageids export exportnowrap aulimit aufrom)
    List all users. Parameters: aulimit - The maximum number of contributions to return. No more than 500 (5000 for bots) allowed. Default: 10 aufrom - Start listing at this user.
  • Function SITE-INFO (&key titles pageids revids prop list meta generator redirects indexpageids export exportnowrap)
    Returns overall site information. Parameters: none
  • Class 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.
    RESULTS   Accessor: RESULTS
    CLOSURE
  • Method HAS-MORE-RESULTS-P ((qr query-result))
    Returns nil, or the closure used for a single follow-up query
  • Method GET-MORE-RESULTS ((qr query-result) &key (at-least 0) (pause 1))
    Fetches AT-LEAST more results, re-querying every PAUSE seconds if necessary. If AT-LEAST is nil, repeats until it gets all results. Updates the query-result object with these new results. Returns the object, and the number of new items fetched.
  • Function GET-REVISIONS-RESULT (&rest args)
    Like get-revisions, but returns a query-result object
  • Function 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)
  • Function 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
  • Function 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)
  • Function 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)
  • Function 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
  • Function 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!
  • Function 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
  • Function 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]])