Jump to content

API:Alltransclusions

From mediawiki.org
This page is a translated version of the page API:Alltransclusions and the translation is 69% complete.
เวอร์ชันมีเดียวิกิ:
1.21

GET request to list all existing and non-existing transclusions .

This module can be used as a generator .

API documentation

list=alltransclusions (at)

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

List all transclusions (pages embedded using {{x}}), including non-existing.

Specific parameters:
Other general parameters are available.
atcontinue

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

atfrom

The title of the transclusion to start enumerating from.

atto

The title of the transclusion to stop enumerating at.

atprefix

Search for all transcluded titles that begin with this value.

atunique

Only show distinct transcluded titles. Cannot be used with atprop=ids.

When used as a generator, yields target pages instead of source pages.

Type: boolean (details)
atprop

Which pieces of information to include:

ids
Adds the page ID of the transcluding page (cannot be used with atunique).
title
Adds the title of the transclusion.
Values (separate with | or alternative): ids, title
Default: title
atnamespace

The namespace to enumerate.

One of the following values: -1, -2, 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
Default: 10
atlimit

How many total items to return.

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

The direction in which to list.

One of the following values: ascending, descending
Default: ascending
Examples:
List transcluded titles, including missing ones, with page IDs they are from, starting at B.
api.php?action=query&list=alltransclusions&atfrom=B&atprop=ids|title [open in sandbox]
List unique transcluded titles.
api.php?action=query&list=alltransclusions&atunique=&atfrom=B [open in sandbox]
Gets all transcluded titles, marking the missing ones.
api.php?action=query&generator=alltransclusions&gatunique=&gatfrom=B [open in sandbox]
Gets pages containing the transclusions.
api.php?action=query&generator=alltransclusions&gatfrom=B [open in sandbox]


ตัวอย่าง

GET request

Get three unique pages in the main namespace which contain transclusions.

Response

{
    "batchcomplete": "",
    "continue": {
        "atcontinue": "!Hero_(album)",
        "continue": "-||"
    },
    "query": {
        "alltransclusions": [
            {
                "ns": 0,
                "title": "!!Destroy-Oh-Boy!!"
            },
            {
                "ns": 0,
                "title": "!Action Pact!"
            },
            {
                "ns": 0,
                "title": "!Arriba!"
            }
        ]
    }
}

รหัสตัวอย่าง

Python

#!/usr/bin/python3

"""
    get_alltransclusions.py

    MediaWiki API Demos
    Demo of `Alltransclusions` module: Get three unique pages in the main
    namespace which contain transclusions.

    MIT License
"""

import requests

S = requests.Session()

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

PARAMS = {
    "action": "query",
    "format": "json",
    "list": "alltransclusions",
    "atunique": "1",
    "atnamespace": "0",
    "atlimit": "3"
}

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

TRANSCLUSIONS = DATA["query"]["alltransclusions"]

for t in TRANSCLUSIONS:
    print(t["title"])

PHP

<?php
/*
    get_alltransclusions.php

    MediaWiki API Demos
    Demo of `Alltransclusions` module: Get three unique pages in the main namespace which contain transclusions.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "list" => "alltransclusions",
    "atunique" => "1",
    "atnamespace" => "0",
    "atlimit" => "3"
];

$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"]["alltransclusions"] as $k => $v ) {
    echo( $v["title"] . "\n" );
}

JavaScript

/*
    get_alltransclusions.js

    MediaWiki API Demos
    Demo of `Alltransclusions` module: Get three unique pages in the main namespace which contain transclusions.

    MIT License
*/

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

var params = {
    action: "query",
    format: "json",
    list: "alltransclusions",
    atunique: "1",
    atnamespace: "0",
    atlimit: "3"
};

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 transclusions = response.query.alltransclusions;
        for (var t in transclusions) {
            console.log(transclusions[t].title);
        }
    })
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	get_alltransclusions.js

	MediaWiki API Demos
	Demo of `Alltransclusions` module: Get three unique pages
	in the main namespace which contain transclusions.

	MIT License
*/

var params = {
		action: 'query',
		format: 'json',
		list: 'alltransclusions',
		atunique: '1',
		atnamespace: '0',
		atlimit: '3'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var transclusions = data.query.alltransclusions,
		t;
	for ( t in transclusions ) {
		console.log( transclusions[ t ].title );
	}
} );

ข้อบกพร่อง (error) ที่อาจเกิด

รหัส (Code) ข้อมูล (Info)
unknown_atnamespace Unrecognized value for parameter atnamespace: value.

Results from enumerating a non-existent namespace.

บันทึกเพิ่มเติม

ดูเพิ่ม