mediawiki-api

With the Mediawiki API, how can we fetch a version of a Wikipedia page other than the latest?


The MediaWiki API can be used to fetch Wikipedia pages. In the docs, they only show how to fetch the latest version of a page. However, I know that Wikipedia stores every version of every page. Is there a way to access those other versions through the MediaWiki API?


Solution

  • Suppose we are going to retrieve https://www.mediawiki.org/w/index.php?title=Project:Sandbox&oldid=5585818 .

    One can retrieve older versions:

    1. as wikitext format using:
      1. prop=revisions + (rvstart/rvend or rvstartid/rvendid parameters): https://www.mediawiki.org/w/api.php?action=query&prop=revisions&titles=Project:Sandbox&rvslots=*&rvprop=content&rvstartid=5585818&rvlimit=1
      2. index.php + (action=raw and oldid parameters): https://www.mediawiki.org/w/index.php?title=Project:Sandbox&oldid=5585818&action=raw
    2. as HTML using:
      1. action=parse together with oldid parameter: https://www.mediawiki.org/w/api.php?action=parse&oldid=5585818&prop=text
      2. index.php + action=render. (action=parse API is preferred over this method): https://www.mediawiki.org/w/index.php?title=Project:Sandbox&oldid=5585818&acton=render