API:Allfileusages/pt-br

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Allfileusages and the translation is 73% complete.

Other languages:
Deutsch • ‎English • ‎dansk • ‎español • ‎français • ‎polski • ‎português do Brasil • ‎română • ‎русский • ‎العربية • ‎سنڌي • ‎ไทย • ‎中文 • ‎日本語 • ‎한국어
Versão do MediaWiki: 1.22

GET request to list all file usages, including non-existing.

API documentation


list=allfileusages (af)

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

List all file usages, including non-existing.

Parameters:
afcontinue

When more results are available, use this to continue.

affrom

The title of the file to start enumerating from.

afto

The title of the file to stop enumerating at.

afprefix

Search for all file titles that begin with this value.

afunique

Only show distinct file titles. Cannot be used with afprop=ids.

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

Type: boolean (details)
afprop

Which pieces of information to include:

ids
Adds the page IDs of the using pages (cannot be used with afunique).
title
Adds the title of the file.
Values (separate with | or alternative): ids, title
Default: title
aflimit

How many total items to return.

No more than 500 (5,000 for bots) allowed.
Type: integer or max
Default: 10
afdir

The direction in which to list.

One of the following values: ascending, descending
Default: ascending

Exemplo

Solicitações abertas

Listar os 10 primeiros arquivos usados começando com a palavra "Icon"(1 dolar) e em quais endereço (ids) de paginas eles são usados

Resposta

{
    "batchcomplete": "",
    "continue": {
        "afcontinue": "Icon-C4004.jpg|7174658",
        "continue": "-||"
    },
    "query": {
        "allfileusages": [
            {
                "fromid": 12221220,
                "ns": 6,
                "title": "File:Icon"
            },
            {
                "fromid": 12274856,
                "ns": 6,
                "title": "File:Icon"
            },
            {
                "fromid": 14729339,
                "ns": 6,
                "title": "File:Icon"
            }
            ...
        ]
    }
}

Exemplo de código

Python

#!/usr/bin/python3

"""
    get_allfileusages.py

    MediaWiki API Demos
    Demo of `allfileusage` module: List all file usages, including non-existing

    MIT License
"""

import requests

S = requests.Session()

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

PARAMS = {
    "action": "query",
    "afprefix": "Icon",
    "list": "allfileusages",
    "afprop": "ids|title",
    "format": "json"
}

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

USAGES = DATA["query"]["allfileusages"]

for img in USAGES:
    print(img["title"])

PHP

<?php
/*
    get_allfileusages.php

    MediaWiki API Demos
    Demo of `allfileusage` module: List all file usages, including non-existing.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "list" => "allfileusages",
    "afprefix" => "Icon",
    "afprop" => "ids|title"
];

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

Javascript

/*
    get_allfileusages.js

    MediaWiki API Demos
    Demo of `allfileusage` module: List all file usages, including non-existing.

    MIT License
*/

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

var params = {
    action: "query",
    format: "json",
    list: "allfileusages",
    afprefix: "Icon",
    afprop: "ids|title"
};

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

MediaWiki JS

/*
	get_allfileusages.js

	MediaWiki API Demos
	Demo of `allfileusage` module: List all file usages, including non-existing.

	MIT License
*/

var params = {
		action: 'query',
		format: 'json',
		list: 'allfileusages',
		afprefix: 'Icon',
		afprop: 'ids|title'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var usages = data.query.allfileusages,
		img;
	for ( img in usages ) {
		console.log( usages[ img ].title );
	}
} );

Ver também