Search code examples
javamediawikimediawiki-api

Determine article path of a MediaWiki installation


How can I reliable determine the article path ($wgArticlePath) of a wiki using MediaWiki when I only know the domain of the wiki?

I made some research but only found ways to find that out in own installations, not installation I have no control of.

Methods I came up with so far but doesn't always seem to work:

  • Requesting the website of the root domain and going through the links but I don't know which links go to a wiki. In some cases the URL also only links to the subdomain, not the homepage (which would include the article path) so I would also need to request the homepages of each wiki.
  • Using api.php but I didn't find a way. It also seems as this URL can be modified.
  • Using the page Special:Version but that would require that I already know the article path. I could only verify it.

Solution

  • You can get the article path from the API, using action=query&meta=siteinfo. The article path is included in a bunch of properties called “general”. An example from English Wikipedia, querying for the general properties only:

    https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=general
    

    In this case, you will find: "articlepath": "/wiki/$1"

    If you do not even know the path to the API, you can parse the markup of the starting page (or any page), and look for a <link rel="EditURI"> tag in the header. You will find this on any default installation of a fairly recent MediaWiki version (though it would obviously be perfectly possible to remove this tag through the use of some extension).