Jump to content

API:Links hierher

From mediawiki.org
This page is a translated version of the page API:Linkshere and the translation is 100% complete.
MediaWiki Version:
1.24

GET-Abfrage um alle Seiten zu finden, die auf die angegebenen Seiten verlinken.

API-Dokumentation

prop=linkshere (lh)

(main | query | linkshere)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Find all pages that link to the given pages.

Specific parameters:
Other general parameters are available.
lhprop

Which properties to get:

pageid
Page ID of each page.
title
Title of each page.
redirect
Flag if the page is a redirect.
Values (separate with | or alternative): pageid, redirect, title
Default: pageid|title|redirect
lhnamespace

Only include pages in these namespaces.

Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 486, 487, 710, 711, 828, 829, 1198, 1199, 2600, 5500, 5501
To specify all values, use *.
lhshow

Show only items that meet these criteria:

redirect
Only show redirects.
!redirect
Only show non-redirects.
Values (separate with | or alternative): !redirect, redirect
lhlimit

How many to return.

Type: integer or max
The value must be between 1 and 500.
Default: 10
lhcontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.


Beispiel

GET-Abfrage

Erhalte eine Liste von Seiten, die auf die Hauptseite verlinken.

Antwort

{
    "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"
                    },
                    ...
                ]
            }
        }
    }
}

Beispielcode

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 );
} );

Mögliche Fehler

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

Zusätzliche Anmerkungen

  • Dieses Modul kann als generator benutzt werden.

Siehe auch

  • API:Links - Gibt alle Links von den angegebenen Seiten aus.