Search code examples
wikipediawikipedia-apimediawiki-api

How to retrieve history version of Wikipedia article by given date?


Is there a way to use MediaWiki API or any other tool to automatically retrieve a previous version of a Wikipedia article using an approximate date (without knowing the 'oldid' value)?

For example how can I retrieve the history version of Stack Overflow article from 20 December 2016 by using "December 2016", "20 December 2016" or a date around this day as parameter?


Solution

  • You can do this by using MediaWiki API with action query and property revisions. To get the first revision of the Stack Overflow made after 00:00:00 on 20 December 2016 you can use this:

    https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Stack%20Overflow&rvlimit=1&rvprop=content&rvdir=newer&rvstart=2016-12-20T00:00:00Z
    

    where rvlimit is the number of history versions to be returned, rvdir=newer means the results (if rvlimit > 1) to be listed in order from oldest to newest, and rvstart is the time after which the page history versions are taken.