API:Duplicatefiles
Appearance
From mediawiki.org
Languages:
This page is part of the MediaWiki Action API documentation.
MediaWiki Action API |
---|
Basics |
Authentication |
Accounts and Users |
Page Operations |
|
Search |
Developer Utilities |
Tutorials |
v · d · e |
GET request to get a list of duplicates of the given file.
MediaWiki version:
≥ 1.14
API documentation
[edit ] The following documentation is the output of Special:ApiHelp/query+duplicatefiles , automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
prop=duplicatefiles (df)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
List all files that are duplicates of the given files based on hash values.
Specific parameters:
Other general parameters are available.
- dflimit
How many duplicate files to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- dfcontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
- dfdir
The direction in which to list.
- One of the following values: ascending, descending
- Default: ascending
- dflocalonly
Look only for files in the local repository.
- Type: boolean (details)
Examples:
- Look for duplicates of File:Albert Einstein Head.jpg.
- api.php?action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles [open in sandbox]
- Look for duplicates of all files.
- api.php?action=query&generator=allimages&prop=duplicatefiles [open in sandbox]
Example
[edit ]GET request
[edit ]List duplicates of two images.
api.php?action=query&titles=Image:1995.jpg|Image:Welcome.gif&prop=duplicatefiles [try in ApiSandbox]
Response
[edit ]{ "batchcomplete":"", "query":{ "normalized":[ { "from":"Image:1995.jpg", "to":"File:1995.jpg" }, { "from":"Image:Welcome.gif", "to":"File:Welcome.gif" } ] ... } } } }
Sample code
[edit ]Python
[edit ]#!/usr/bin/python3 """ duplicate_files.py MediaWiki API Demos Demo of `Duplicatefiles` module: List duplicates of the given files. MIT License """ import requests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "titles": "Image:1995.jpg|Image:Welcome.gif", "prop": "duplicatefiles", "format": "json" } R = S.get(url=URL, params=PARAMS) DATA = R.json() print(DATA)
PHP
[edit ]<?php /* duplicate_files.php MediaWiki API Demos Demo of `Duplicatefiles` module: List duplicates of the given files. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "titles" => "Image:1995.jpg|Image:Welcome.gif", "prop" => "duplicatefiles", "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 ); echo( $output );
JavaScript
[edit ]/* duplicate_files.js MediaWiki API Demos Demo of `Duplicatefiles` module: List duplicates of the given files. MIT License */ varurl="https://en.wikipedia.org/w/api.php"; varparams={ action:"query", titles:"Image:1995.jpg|Image:Welcome.gif", prop:"duplicatefiles", format:"json" }; request.get({url:url,qs:params},function(error,res,body){ if(error){ return; } console.log(body); });
MediaWiki JS
[edit ]/* duplicate_files.js MediaWiki API Demos Demo of `Duplicatefiles` module: List duplicates of the given files. MIT License */ varparams={ action:"query", titles:"Image:1995.jpg|Image:Welcome.gif", prop:"duplicatefiles", format:"json" }, api=newmw.Api(); api.get(params).done(function(data){ console.log(data); });
Parameter history
[edit ]- v1.20: Introduced
dfdir
,dflocalonly
See also
[edit ]- API:Fileinfo - to supersede this
prop
in future versions of the MediaWiki Action API. - API:Stashimageinfo - retrieves information about stashed images.
- API:Images - retrieves all images embedded on a page.
- API:Info - retrieves basic information about a list of pages.
- API:Imageusage - finds all pages that use the given image or images.
- API:Imageinfo - retrieves information about an image file or files.