MediaWiki version:
1.24

GET request to find all pages that link to the given pages.

API documentation


Special:ApiHelp/query+linkshere

Example

GET request

Get a list of pages linking to the Main Page.

Response

{
    "continue": {
        "lhcontinue": "1868",
        "continue": "||"
    },
    "query": {
        "pages": {
            "15580374": {
                "pageid": 15580374,
                "ns": 0,
                "title": "Main Page",
                "linkshere": [
                    {
                        "pageid": 354,
                        "ns": 1,
                        "title": "Talk:Algeria"
                    },
                    {
                        "pageid": 672,
                        "ns": 1,
                        "title": "Talk:Arc de Triomphe"
                    },
                    ...
                ]
            }
        }
    }
}

Sample code

Python

#!/usr/bin/python3

"""
    linkshere.py
    MediaWiki API Demos
    Demo of `Linkshere` module: Get a list of pages linking to a given page
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "query",
    "titles": "Main Page",
    "prop": "linkshere",
    "format": "json"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)

PHP

<?php

/*
    linkshere.php
    MediaWiki API Demos
    Demo of `Linkshere` module: Get a list of pages linking to a given page
    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "titles" => "Main Page",
    "prop" => "linkshere",
    "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

/*
    linkshere.js
    MediaWiki API Demos
    Demo of `Linkshere` module: Get a list of pages linking to a given page
    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    titles: "Main Page",
    prop: "linkshere",
    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

/*
	linkshere.js
	MediaWiki API Demos
	Demo of `Linkshere` module: Get a list of pages linking to a given page
	MIT License
*/

var params = {
		action: 'query',
		titles: 'Main Page',
		prop: 'linkshere',
		format: 'json'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	console.log( data );
} );

Possible errors

Code Info
show Incorrect parameter - mutually exclusive values may not be supplied.

Additional notes

  • This module can be used as a generator.

See also

  • API:Links - Returns all links from the given pages.
This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.