Search code examples
mediawiki-api

Get current oldid of a Mediawiki-hosted page


In Wikipedia (and other Mediawiki servers), each page has history, and each point in history is identified with its oldid.

How to retrieve the current oldid (current version) of http://server/wiki/Article?

With the Mediawiki API, preferably retrieving only that.
For intergration in a bash script.


Solution

  • The info operation of the Mediawiki API gives it, among other information:

    HTTP request:

    http://en.wikipedia.org/w/api.php?action=query&prop=info&format=xml&titles=Main%20Page
    

    HTTP response:

    <?xml version="1.0"?>
    <api>
      <query>
        <pages>
          <page pageid="15580374" ns="0" title="Main Page" contentmodel="wikitext"
            pagelanguage="en" touched="2014-01-21T08:00:12Z" lastrevid="574690625"
            counter="" length="6391" />
        </pages>
      </query>
    </api>
    

    The part you want is lastrevid.