MediaWiki REST API docs
  Home | Discuss | Fork this notebook on PAWS


Exploring page history

The MediaWiki REST API lets you build apps and scripts that interact with any MediaWiki-based wiki. In this tutorial, we'll use the REST API page history endpoints to explore the history of articles on English Wikipedia.


A wiki page's history is divided into a sequence of revisions. A revision can be any change to the content of a page: an anonymous editor correcting a typo, an admin reverting vandalism, a bot fixing a citation link. The history API lets you browse through a page's history in segments of 20 revisions.

To see the most recent revisions to a page, we'll make a request to the page history endpoint, including the page title in the path. The page history endpoint returns the latest revision segment, starting with the most recent revision. Each revision object includes the revision id, which you can use to get more information about the revision to compare revisions. Revision IDs do not increase sequentially, so you may see an older revision with a higher revision ID than a newer revision.

In this example, we'll explore the history of the Agapanthus article on English Wikipedia. The delta gives us a sense of the size of the change.

The page history endpoint also provides older, newer, and latest properties to make it easy to scroll through revisions.

To look further back in the history of the page, we can use the older property to fetch the next 20 oldest revisions. The response is non-inclusive; it doesn't include the revision specified in the URL.

We can continue exploring using the URLs provided by the older, newer, and latest properties.

From here, we can use the newer URL to scroll forward in the page's history, or by requesting the page history without an older_than or newer_than parameter, return to the most recent revisions. The page history endpoint can only return up to 20 revisions, so you cannot use both the older_than and newer_than parameters in the same request.

If the API does not return an older property, there are no older revisions left to return. Following the same pattern, the absence of a newer URL indicates that there are no newer revisions available.

Revision details

In exploring the history of the Agapanthus page, we can see an addition of 256 bytes on 2017-02-07 with the revision ID 764138197. To understand why an edit was made and by whom, we can use the revision ID to make a request to the revision endpoint.

Filtering page history

Some revisions are tagged to indicate the type of edit. The page history endpoint supports filtering by edit type, allowing you to request, for example, only edits made by bots or only edits made by anonymous users. See the endpoint reference for the complete list of supported filters.

To see the most recent edits made by bots, call the page history endpoint with the filter parameter set to bot.

You can pair the filter parameter with the older_than or newer_than parameter to explore page history by revision type. Due to differences in caching infrastructure, the number of revisions returned by the page history filters may not match the statistics returns by the page history counts endpoint.

Comparing revisions

When exploring a page's history, you can use the delta to understand the impact of the edit in relation to the previous edit. You can also compare any two revisions line by line using the compare revisions endpoint. The compare revision endpoint takes two revision IDs as path parameters; you can use the page history endpoint to select revision IDs.

To compare two revisions, supply the revision IDs in the endpoint path. The API returns the differences between the two revisions as a structured JSON object designed to help construct a visual representation of the diff.

You should now be able to use the REST API history endpoints to explore page history on Wikipedia. You can also use these endpoints with any Wikimedia project.

To fork, edit, and re-run this Jupyter Notebook, download the source, and upload to PAWS using your Wikimedia account.

For more information about these endpoints, see the API reference. To share your feedback on this tutorial, post a comment to the REST API discussion page.


This tutorial is licensed under the Creative Commons Attribution-ShareAlike License.