API:Alltransclusions

From mediawiki.org
MediaWiki version:
1.21

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

This module can be used as a generator .

API documentation[edit]


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]

Example[edit]

GET request[edit]

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


Response[edit]

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

Sample code[edit]

Python[edit]

#!/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[edit]

<?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[edit]

/*
    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[edit]

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

Possible errors[edit]

Code Info
unknown_atnamespace Unrecognized value for parameter atnamespace: value.

Results from enumerating a non-existent namespace.

Additional notes[edit]

See also[edit]