API:Exturlusage
![]() | This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.11 |
GET request to list pages that link to a certain URL, like Special:Linksearch.
API documentation
[edit]
Example
[edit]GET request
[edit]Get a list of pages linking to slashdot.org
Response
[edit]{
"batchcomplete": "",
"continue": {
"eucontinue": "http://org.slashdot./|169423",
"continue": "-||"
},
"query": {
"exturlusage": [
{
"pageid": 533948,
"ns": 2,
"title": "User:Peter Ellis",
"url": "http://slashdot.org"
},
{
"pageid": 3274,
"ns": 2,
"title": "User:Alexdb",
"url": "http://slashdot.org/"
},
{
"pageid": 36471,
"ns": 2,
"title": "User:Joao",
"url": "http://slashdot.org/"
}
...
]
}
}
Sample code
[edit]Python
[edit]#!/usr/bin/python3
"""
get_exturlusage.py
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "exturlusage",
"euquery": "slashdot.org"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
EXTURLS = DATA["query"]["exturlusage"]
for exturl in EXTURLS:
print("Page " + exturl["title"] + " has " + exturl["url"] + " url.")
PHP
[edit]<?php
/*
get_exturlusage.php
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "exturlusage",
"euquery" => "slashdot.org"
];
$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 );
foreach( $result["query"]["exturlusage"] as $k => $v ) {
echo( "Page " . $v["title"] . " has " . $v["url"] . " url. \n" );
}
JavaScript
[edit]/*
get_exturlusage.js
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "exturlusage",
euquery: "slashdot.org"
};
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 exturls = response.query.exturlusage;
for (var exturl in exturls) {
console.log("Page " + exturls[exturl].title + " has " + exturls[exturl].url + " url.");
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
[edit]/*
get_exturlusage.js
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'exturlusage',
euquery: 'slashdot.org'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var exturls = data.query.exturlusage,
exturl;
for ( exturl in exturls ) {
console.log( 'Page ' + exturls[ exturl ].title + ' has ' + exturls[ exturl ].url + ' url.' );
}
} );
Possible errors
[edit]Code | Info |
---|---|
unknown_euprotocol | Wrong property for protocol parameter (use value from the list of supported protocols) |
badcontinue | Invalid continue param. You should pass the original value returned by the previous query. |
Parameter history
[edit]- v1.21: Introduced
euexpandurl
See also
[edit]- API:Backlinks - lists links to a given page.
- API:Links - retrieves links on a given page or pages.
- API:Iwlinks - Find interwiki links on a given page (i.e, meta pages, special pages).
- API:Extlinks - Find all external links on a given page.
- API:Langlinks - Get a list of language links from the given page. Language links represent translations.
- API:Langbacklinks - Get a list of pages that contains a given language link.