Retrieve a list of all Wikipedia languages programmatically
Asked Answered
S

3

8

I need to retrieve a list of all existing languages for a certain wiki project. For example, all Wikivoyage or all Wikipedia languages, just like on their landing pages.

I prefer to do this via MediaWiki API, if it's possible.

Thanks for your time.

Statvolt answered 9/11, 2015 at 12:6 Comment(0)
B
8

Approach 3: Using an API in the Wikimedia wiki farm and Extension:Sitematrix

https://commons.wikimedia.org/w/api.php?action=sitematrix&smtype=language

While this will return all wikis, the matrix knows about, it is easily filtered client side by code [as of now, one of: wiki (Wikipedia), wiktionary, wikibooks, wikinews, wikiquote, wikisource, wikiversity, wikivoyage] and by its closed state. One request with just some response body overhead but since it's easily cached and compresses well, not that serve.

Barbarese answered 14/11, 2015 at 18:15 Comment(2)
This seems like a solution to my problem. I'll need some time to test and give a feedback.Statvolt
If you are using a loosy-typed language, make sure to test the closed property against undefined or using .hasOwnProperty(), as an empty string will possibly evaluate to false.Barbarese
L
7

Approach 1: Using an API in the Wikimedia wiki farm

To get all interwiki prefixes that a wiki knows of, use the meta module of the MediaWiki API, and query any project for siprop=interwikimap:

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

You will get a large array of objects like this:

{
    "prefix": "aa",
    "local": "",
    "language": "Qaf\u00e1r af",
    "url": "https://aa.wikipedia.org/wiki/$1",
    "protorel": ""
}

protorel tells you if the url is protocol relative or not (i.e. starting with //. For the WikiMedia wikis, they will start with https. The $1 in the URL is, as you would have imagined, a placeholder for the title.

To get only the wikis in the same wikifarm (e.g. Wikimedia wikis), add sifilteriw=local to your query:

https://sv.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local

To fetch the names in you langue use siinlanguagecode, like this (all Wikimedia wikis, with their Swedish names, retrieved from arabic Wikipedia, but could have been any endpoint in the wiki farm):

https://ar.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local&siinlanguagecode=sv

From here you would have to filter out e.g. the Wikipedias yourself.

Approach 2: Using Wikistats at wmflabs

A list already filtered by type of project is available at http://wikistats.wmflabs.org (csv), where you can filter out Wikipedia, Wikiversity, etc. The csv file is updated on daily basis, but the tool is experimental, and might not be there forever.

In either approach, Wikimedia Incubator wikis will not show up.

Liguria answered 9/11, 2015 at 12:14 Comment(3)
Is there a way to return the current status of the languages? I get this list en.wiktionary.org/w/… but many projects has been closed.Statvolt
You can check for each project if it's closed, using meta=siteinfo: ang.wikiquote.org/w/… But I don't think you can filter the list from the start (I might be wrong)Liguria
Thanks for your answers. I will leave this question open, maybe someone wil come with some solution.Statvolt
F
3

Subtract closed.dblist from wikipedia.dblist (other lists), then remove wiki from the end and replace _ with -.

Fictile answered 12/11, 2015 at 6:43 Comment(1)
Unfortunately this hasn't worked properly in all cases since phabricator.wikimedia.org/T11823 (September 2015) - be_x_oldwiki has the canonical domain be-tarask.wikipedia.org - I did set up a redirect from the old domain though. I expect we'll have more of these cases in future.Montanez

© 2022 - 2024 — McMap. All rights reserved.