MediaWiki API

Uploaded image

The MediaWiki web API is a web service that provides convenient access to wiki features, data, and meta-data over HTTP. - mediawiki.org

Clients request particular "actions" by specifying an action parameter, mainly action=query to get information.

# Other Mediawiki API's

It was known as the MediaWiki API, but there are now other web APIs available that connect to MediaWiki such as RESTBase and the Wikidata Query Service.

In particular when dealing with images - we have tow places they can be stored - on Wikipedia where you would use the Wikipedia API to access them, or the Wikimedia Commons API to access the newer archive of all media used across Wikipedia Sites.

See also the Mediawiki Graphoid Service for rendering client side interactive graphs from json using vega.github.io

# Experiment

You can experiment with the Mediawiki API over at the Mediawiki API Sandobox wikipedia.org

* API SandBox - wikipedia.org * API Tutorial - mediawiki.org

Or read about detail of individual API calls such as Imageinfo at mediawiki.org

REST API for MediaWiki

  • Exposes things MediaWiki has in the database or otherwise understands
  • does not include semantic stuff like "definition of a word in Wiktionary" or even "lead paragraph of an article"
  • usage: send HTTP requests (GET or POST) to the api.php URL, receive XML or JSON or other formats. You'll usually want JSON or XML.
  • w:en:JSON and w:en:XML and w:en:Representational state transfer (RESTful)

There are other things that also get casually called the MediaWiki API, like the internal interfaces that extensions and special pages can hook into. We're not talking about that right now, just the web API.

* __Entry point__: https://en.wikipedia.org/w/api.php or any other MediaWiki * __Versioning__ - how non-WMF wikis might have different version of MediaWiki and thus the API https works too! * __Parameters__ - are passed in query string. Not passing any will give you the help page with the autogenerated documentation.

Follow along by using w:en:Special:ApiSandbox – you will mostly use the query Action.

Things you'll definitely need

  • prop=info for basic page info
  • prop=revisions for page history
  • prop=revisions&rvprop=content for page wikitext
  • action=parse for page HTML

Doing crazy stuff

  • multiple titles with titles=Foo|Bar|Baz (This will make multiple calls count as one for the purpose of rate limiting)
  • This works for pages but not revisions. Read the documentation via the Sandbox or via api.php autodocs.
  • multiple modules with &prop=images|templates&list=allpages|blocks
  • generators (kind of like UNIX pipes) with &titles=Foo&generator=links&prop=revisions

Resources

  • Autogenerated documentation: api.php with no parameters such as https://en.wikipedia.org/w/api.php, or equivalently visit Special:ApiHelp
  • Documentation on mediawiki.org: API:Main page (details about specific modules/parameters is often outdated, autogenerated docs are authoritative)
  • The API Sandbox -- example w:en:Special:ApiSandbox
  • mail:mediawiki-api -- mediawiki-api@lists.wikimedia.org
  • mediawiki-api-announce@lists.wikimedia.org - PLEASE subscribe because we tell you about breaking changes, which happen a few times every year. mail:mediawiki-api-announce
  • #mediawikiconnect IRC channel me! (Roan Kattouw)

You may actually want the dumps of all of Wikipedia so you can work with them locally - http://dumps.wikimedia.org/ or Offline Wikipedia readers such as Kiwix http://www.kiwix.org

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

Parsoid is an application which can translate back and forth, at runtime, between MediaWiki's wikitext syntax and an equivalent HTML/RDFa document model with enhanced support for automated processing and rich editing.