MediaWiki API


https://www.mediawiki.org/wiki/API:Main_page

Configuration
Set endpoint to the API entry point. An example for Wikimedia wikis:
USING: formatting mediawiki.api namespaces ; : wikimedia-url ( lang family -- str ) "https://%s.%s.org/w/api.php" sprintf ; "en" "wikipedia" wikimedia-url endpoint set-global


For Wikimedia wikis, also provide contact information in contact so that wiki operators can contact you in case of malfunction, including username or email, and possibly the task name:
USING: mediawiki.api namespaces ; "BotName/Task1 (email@address.tld)" contact set-global


OAuth login with an owner-only consumer:
USING: mediawiki.api namespaces ; "consumer-token" "consumer-secret" "access-token" "access-secret" <oauth-login> oauth-login set-global


Login with username and password:
USING: mediawiki.api namespaces ; "username" "password" <password-login> password-login set-global


If both login methods are given, OAuth is preferred. If none are given, you're not logged in.

If you use several wikis simultaneously, you might want to save your cookies (if you use the password login method) and your csrf-token. You also should invalidate your csrf-token before using an action that requires a csrf token in a wiki for the first time:
USING: mediawiki.api namespaces ; f csrf-token set-global


Usage
Main entry point:
api-call ( params -- assoc )


Query the API:
query ( params -- seq )

page-content ( title -- content )


Actions that require a csrf token:
token-call ( params -- assoc )

edit-page ( title text summary params -- assoc )

move-page ( from to reason params -- assoc )

email ( target subject text -- assoc )


Sometimes you need to loop over a non-query API call:
call-continue ( params quot1: ( params -- obj assoc ) quot2: ( ... -- ... ) -- seq )