API:Fileusage/ja: Difference between revisions
Appearance
Content deleted Content added
Updating to match new version of source page |
Updating to match new version of source page |
||
| Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
{{API}} |
{{API}} |
||
{{MW 1.24|and after}} |
|||
{{API-head |
|||
| ⚫ | |||
|version=1.24 |
|||
|prefix=fu |
|||
|rrights=None |
|||
|postonly=No |
|||
| ⚫ | |||
|generator=yes |
|||
|query=yes |
|||
| ⚫ | |||
| ⚫ | |||
== |
== API documentation == |
||
| ⚫ | |||
*{{ApiParam|fuprop|description=Which properties to get.|default=<code>pageid{{!}}title{{!}}redirect</code>}} |
|||
| ⚫ | |||
**{{ApiParam|pageid|description=Get the page id of each page.}} |
|||
| ⚫ | |||
**{{ApiParam|title|description=Get the title of each page.}} |
|||
**{{ApiParam|redirect|description=Flag whether the page is a redirect.}} |
|||
*{{ApiParam|funamespace|description=Only include pages in these namespaces.}} |
|||
*{{ApiParam|fushow|description=Show only items that meet these criteria.}} |
|||
**{{ApiParam|redirect|description=Only show redirects.}} |
|||
**{{ApiParam|!redirect|description=Only show non-redirects.}} |
|||
*{{ApiParam|fulimit|description=The number of results to return.|maxallowed=500|default=10}} |
|||
*{{ApiParam|fucontinue|description=When more results are available, use this to continue.}} |
|||
== 例 == |
== 例 == |
||
=== GET request === |
|||
{{ApiEx |
{{ApiEx |
||
| desc=Get a list of pages using |
| desc=Get a list of pages using a given file. |
||
| p1=action=query |
| p1=action=query |
||
| p2=titles=File:Example.jpg |
| p2=titles=File:Example.jpg |
||
| p3=prop=fileusage |
| p3=prop=fileusage |
||
| p4=format=json |
|||
| result=<source lang="javascript">{ |
|||
| ⚫ | |||
=== Response === |
|||
<div style="width:60%;"> |
|||
<syntaxhighlight lang="json"> |
|||
{ |
|||
"continue": { |
|||
"fucontinue": "4635245", |
|||
"continue": "||" |
|||
}, |
|||
"query": { |
"query": { |
||
"pages": { |
"pages": { |
||
| Line 38: | Line 35: | ||
"title": "File:Example.jpg", |
"title": "File:Example.jpg", |
||
"fileusage": [ |
"fileusage": [ |
||
{ |
|||
"pageid": 57741, |
|||
"ns": 1, |
|||
"title": "Talk:Ebola virus" |
|||
}, |
|||
{ |
|||
"pageid": 85076, |
|||
"ns": 1, |
|||
"title": "Talk:Case sensitivity" |
|||
}, |
|||
{ |
|||
"pageid": 165974, |
|||
"ns": 1, |
|||
"title": "Talk:Asia" |
|||
}, |
|||
{ |
|||
"pageid": 243414, |
|||
"ns": 5, |
|||
"title": "Wikipedia talk:Alternative text for images" |
|||
}, |
|||
{ |
|||
"pageid": 256889, |
|||
"ns": 4, |
|||
"title": "Wikipedia:Manual of Style/Images" |
|||
}, |
|||
{ |
|||
"pageid": 428971, |
|||
"ns": 3, |
|||
"title": "User talk:Centrx" |
|||
}, |
|||
{ |
{ |
||
"pageid": 447341, |
"pageid": 447341, |
||
| Line 79: | Line 46: | ||
}, |
}, |
||
{ |
{ |
||
"pageid": |
"pageid": 554270, |
||
"ns": |
"ns": 13, |
||
"title": " |
"title": "Help talk:Pictures" |
||
}, |
}, |
||
... |
|||
"pageid": 728041, |
|||
"ns": 10, |
|||
"title": "Template:Infobox video game" |
|||
} |
|||
] |
] |
||
} |
} |
||
} |
} |
||
} |
} |
||
} |
|||
}</source>}} |
|||
</syntaxhighlight> |
|||
</div> |
|||
=== Sample code === |
|||
{{:{{translatable}}/Sample code 1}} |
|||
== 起こりうるエラー == |
== 起こりうるエラー == |
||
{| class="wikitable |
{| class="wikitable" |
||
|+ |
|||
! |
!コード |
||
!情報 |
|||
|- |
|- |
||
| |
|fushow |
||
|Incorrect parameter - mutually exclusive values may not be supplied. |
|||
|} |
|} |
||
== Additional notes == |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
== See also == |
|||
[[Category:MediaWiki API{{#translation:}}]] |
|||
* {{ll|API:Allfileusages}} - List all file usages, including non-existing. |
|||
Revision as of 13:45, 18 February 2020
| このページは MediaWiki 操作 API の説明文書の一部です。 |
| MediaWiki バージョン: | ≧ 1.24 |
GET request to find all pages that use the given files.
API documentation
prop=fileusage (fu)
Find all pages that use the given files. Specific parameters: Other general parameters are available.
Examples:
|
例
GET request
Get a list of pages using a given file.
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.
See also
- API:allfileusages - List all file usages, including non-existing.