API:Alltransclusions/ja

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Alltransclusions and the translation is 75% complete.
Other languages:
English • ‎Türkçe • ‎polski • ‎русский • ‎বাংলা • ‎日本語
MediaWiki バージョン: 1.21

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

This module can be used as a generator .

APIの説明文書


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.

Parameters:
atcontinue

When more results are available, use this to continue.

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: -2, -1, 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, 828, 829, 1198, 1199, 2300, 2301, 2302, 2303, 2600, 5500, 5501
Default: 10
atlimit

How many total items to return.

No more than 500 (5,000 for bots) allowed.
Type: integer or max
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 リクエスト

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

レスポンス

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

起こりうるエラー

コード 情報
unknown_atnamespace Unrecognized value for parameter atnamespace: value.

Results from enumerating a non-existent namespace.

追加的な注記

関連項目

  • API:Templates - ページに参照読み込みされているすべてのページ群の一覧を取得します。