Retrieve a list of all Wikipedia languages programmatically

徘徊边缘 提交于 2019-12-05 06:59:30

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!