API:Fileusage/ru
Appearance
Эта страница является частью документации по API действий MediaWiki. |
Версия MediaWiki: | ≥ 1.24 |
Запрос GET, чтобы найти все страницы, использующих указанные файлы.
API documentation
Пример
GET request
Получить список страниц использующих данный файл.
Response
{
"continue": {
"fucontinue": "4635245",
"continue": "||"
},
"query": {
"pages": {
"586539": {
"pageid": 586539,
"ns": 6,
"title": "File:Example.jpg",
"fileusage": [
{
"pageid": 447341,
"ns": 5,
"title": "Wikipedia talk:Extended image syntax"
},
{
"pageid": 499974,
"ns": 4,
"title": "Wikipedia:Tutorial/Formatting"
},
{
"pageid": 554270,
"ns": 13,
"title": "Help talk:Pictures"
},
...
]
}
}
}
}
Sample code
Python
#!/usr/bin/python3
"""
get_file_usage.py
MediaWiki API Demos
Demo of `Fileusage` module: Get a list of pages using a given file.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "File:Example.jpg",
"prop": "fileusage",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
get_file_usage.php
MediaWiki API Demos
Demo of `Fileusage` module: Get a list of pages using a given file.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "File:Example.jpg",
"prop" => "fileusage",
"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
/*
get_file_usage.js
MediaWiki API Demos
Demo of `Fileusage` module: Get a list of pages using a given file.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "File:Example.jpg",
prop: "fileusage",
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
/*
get_file_usage.js
MediaWiki API Demos
Demo of `Fileusage` module: Get a list of pages using a given file.
MIT License
*/
var params = {
action: 'query',
titles: 'File:Example.jpg',
prop: 'fileusage',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Возможные ошибки
Код | Информация |
---|---|
fushow | Incorrect parameter - mutually exclusive values may not be supplied. |
Additional notes
- This module can be used as a generator.
См. также
- API:Globalusage - List all file usages on wikis other than the one where the file is stored.
- API:Allfileusages - List all file usages, including non-existing.