API:Iwlinks - MediaWiki (original) (raw)
| This page is part of the MediaWiki Action API documentation. |
|---|
| MediaWiki version: | ≥ 1.17 |
|---|
GET request to list interwiki links from a given page.
| The following documentation is the output of Special:ApiHelp/query+iwlinks, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org). |
|---|
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
Returns all interwiki links from the given pages.
Specific parameters:
iwprop
Which additional properties to get for each interwiki link:
url
Adds the full URL.
Values (separate with | or alternative): url
iwprefix
Only return interwiki links with this prefix.
iwtitle
Interwiki link to search for. Must be used with iwprefix.
iwdir
The direction in which to list.
One of the following values: ascending, descending
Default: ascending
iwlimit
How many interwiki links to return.
Type: integer or max
The value must be between 1 and 500.
Default: 10
iwcontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
iwurl
Deprecated.
Whether to get the full URL (cannot be used with iwprop).
Type: boolean (details)
{
"query": {
"pages": [
{
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"iwlinks": [
{
"prefix": "b",
"title": "Introduction_to_Astrophysics/Albert_Einstein"
},
{
"prefix": "c",
"title": "Special:Search/Albert_Einstein"
},
{
"prefix": "commons",
"title": "Special:Search/Albert_Einstein"
},
...
]
}
]
}
}
#!/usr/bin/python3
""" python/get_iwlinks.py
MediaWiki API Demos
Demo of `Iwlinks` module: Get the interwiki links from a given page.
MIT License"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = { "action": "query", "format": "json", "prop": "iwlinks", "titles": "Albert Einstein" }
R = S.get(url=URL, params=PARAMS) DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items(): print(v["iwlinks"])
"query", "format" => "json", "prop" => "iwlinks", "titles" => "Albert Einstein" ]; url=url = url=endPoint . "?" . http_build_query( $params ); ch=curlinit(ch = curl_init( ch=curlinit(url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); output=curlexec(output = curl_exec( output=curlexec(ch ); curl_close( $ch ); result=jsondecode(result = json_decode( result=jsondecode(output, true ); foreach( result["query"]["pages"]asresult["query"]["pages"] as result["query"]["pages"]ask => $v ) { var_dump( $v["iwlinks"] ); } /* get_iwlinks.js MediaWiki API Demos Demo of `Iwlinks` module: Get the interwiki links from a given page. MIT License */ var url = "https://en.wikipedia.org/w/api.php"; var params = { action: "query", format: "json", prop: "iwlinks", titles: "Albert Einstein" }; url = url + "?origin=*"; Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];}); fetch(url) .then(function(response){return response.json();}) .then(function(response) { var pages = response.query.pages; for (var p in pages) { console.log(pages[p].iwlinks); } }) .catch(function(error){console.log(error);}); /* get_iwlinks.js MediaWiki API Demos Demo of `Iwlinks` module: Get the interwiki links from a given page. MIT License */ var params = { action: 'query', format: 'json', prop: 'iwlinks', titles: 'Albert Einstein' }, api = new mw.Api(); api.get( params ).done( function ( data ) { var pages = data.query.pages, p; for ( p in pages ) { console.log( pages[ p ].iwlinks ); } } ); | Code | Info | | --------------- | ------------------------------------------------- | | invalidparammix | The title parameter may only be used with prefix. | * v1.24: * Introduced `iwprop`, `url` * Deprecated `iwurl` * v1.19: Introduced `iwdir` * v1.18: Introduced `iwprefix`, `iwtitle` * [API:Alllinks](/wiki/Special:MyLanguage/API:Alllinks "Special:MyLanguage/API:Alllinks")[ ](/wiki/API:Alllinks "API:Alllinks") \- Lists links to a namespace. * [API:Links](/wiki/Special:MyLanguage/API:Links "Special:MyLanguage/API:Links")[ ](/wiki/API:Links "API:Links") \- Gets links embedded on a page. * [API:Backlinks](/wiki/Special:MyLanguage/API:Backlinks "Special:MyLanguage/API:Backlinks")[ ](/wiki/API:Backlinks "API:Backlinks") \- Lists pages which link to a certain page. * [API:Linkshere](/wiki/Special:MyLanguage/API:Linkshere "Special:MyLanguage/API:Linkshere")[ ](/wiki/API:Linkshere "API:Linkshere") \- Finds all pages that link to a given page