API:Langlinks
Appearance
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.11 |
GET request to get a list of all language links from the provided pages to other languages.
API documentation
[edit]
Example
[edit]GET request
[edit]Get a list of language links that a given page has.
Response
[edit]{
"continue": {
"llcontinue": "736|ay",
"continue": "||"
},
"query": {
"pages": {
"736": {
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"langlinks": [
{
"lang": "ab",
"*": "\u0410\u043b\u0431\u0435\u0440\u0442 \u0415\u0438\u043d\u0448\u0442\u0435\u0438\u043d"
},
{
"lang": "af",
"*": "Albert Einstein"
},
{
"lang": "als",
"*": "Albert Einstein"
},
...
]
}
}
}
}
Sample code
[edit]Python
[edit]#!/usr/bin/python3
"""
langlinks.py
MediaWiki API Demos
Demo of `Langlinks` module: Get a list of language links that a given page has
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "Albert Einstein",
"prop": "langlinks",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
[edit]<?php
/*
langlinks.php
MediaWiki API Demos
Demo of `Langlinks` module: Get a list of language links that a given page has
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "Albert Einstein",
"prop" => "langlinks",
"format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
var_dump( $result );
JavaScript
[edit]/*
langlinks.js
MediaWiki API Demos
Demo of `Langlinks` module: Get a list of language links that a given page has
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "Albert Einstein",
prop: "langlinks",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {console.log(response);})
.catch(function(error){console.log(error);});
MediaWiki JS
[edit]/*
langlinks.js
MediaWiki API Demos
Demo of `Langlinks` module: Get a list of language links that a given page has
MIT License
*/
var params = {
action: 'query',
titles: 'Albert Einstein',
prop: 'langlinks',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Possible errors
[edit]Code | Info |
---|---|
invalidparammix | The title parameter may only be used with lang. |
Parameter history
[edit]- v1.23: Introduced
llprop
,url
,langname
,autonym
,llinlanguagecode
- v1.23: Deprecated
llurl
- v1.19: Introduced
lldir
- v1.18: Introduced
lllang
,lltitle
- v1.17: Introduced
llurl
- v1.13: Introduced
lllimit
,llcontinue
See also
[edit]- API:Links - Returns all links from the given pages.
- API:Langbacklinks - Find all pages that link to the given language link.