godidier
godidier

Reputation: 1001

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?

Upvotes: 3

Views: 1276

Answers (2)

godidier
godidier

Reputation: 1001

A curl request on the Special:Export page might also help, by setting the offset parameter to something like '2016-12-20T00:00:00Z'

curl -d "" 'https://en.wikipedia.org/w/index.php?title=Special:Export&pages=Stack_Overflow&offset=2016-12-20T00:00:00Z&limit=1&action=submit' 

Upvotes: 0

Termininja
Termininja

Reputation: 7036

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.

Upvotes: 5

Related Questions