From: Ricordisamoa Date: Mon, 29 Dec 2014 10:53:37 +0000 (+0100) Subject: Allow querying for multiple MIME types in the allimages API X-Git-Tag: 1.31.0-rc.0~12843^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=c9fc0430ff0a10916787ca5fa9df5051426238fb;p=lhc%2Fweb%2Fwiklou.git Allow querying for multiple MIME types in the allimages API The 'aimime' parameter can now be a pipe-separated list of MIME types. Also tweaked the English apihelp and added an example for the new functionality. Bug: T78690 Change-Id: I775ecae53c81eccb0a898081715d48589b53af15 --- diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 77dc55b5d6..065a5d7073 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -161,6 +161,8 @@ production. * (T76052) list=tags can now indicate whether a tag is defined. * (T75522) list=prefixsearch now supports continuation * (T78737) action=expandtemplates can now return page properties. +* (T78690) list=allimages now accepts multiple pipe-separated values + for the 'aimime' parameter. === Action API internal changes in 1.25 === * ApiHelp has been rewritten to support i18n and paginated HTML output. diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index 20e9f5e509..6c962cdfbe 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -232,10 +232,25 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { $this->dieUsage( 'MIME search disabled in Miser Mode', 'mimesearchdisabled' ); } - list( $major, $minor ) = File::splitMime( $params['mime'] ); - - $this->addWhereFld( 'img_major_mime', $major ); - $this->addWhereFld( 'img_minor_mime', $minor ); + $mimeConds = array(); + foreach ( $params['mime'] as $mime ) { + list( $major, $minor ) = File::splitMime( $mime ); + $mimeConds[] = $db->makeList( + array( + 'img_major_mime' => $major, + 'img_minor_mime' => $minor, + ), + LIST_AND + ); + } + // safeguard against internal_api_error_DBQueryError + if ( count( $mimeConds ) > 0 ) { + $this->addWhere( $db->makeList( $mimeConds, LIST_OR ) ); + } else { + // no MIME types, no files + $this->getResult()->addValue( 'query', $this->getModuleName(), array() ); + return; + } } $limit = $params['limit']; @@ -359,6 +374,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { ), 'mime' => array( ApiBase::PARAM_DFLT => null, + ApiBase::PARAM_ISMULTI => true, ), 'limit' => array( ApiBase::PARAM_DFLT => 10, @@ -385,6 +401,8 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { 'action=query&list=allimages&aiprop=user|timestamp|url&' . 'aisort=timestamp&aidir=older' => 'apihelp-query+allimages-example-recent', + 'action=query&list=allimages&aimime=image/png|image/gif' + => 'apihelp-query+allimages-example-mimetypes', 'action=query&generator=allimages&gailimit=4&' . 'gaifrom=T&prop=imageinfo' => 'apihelp-query+allimages-example-generator', diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 61de86cf69..92864248fa 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -365,10 +365,11 @@ "apihelp-query+allimages-param-sha1base36": "SHA1 hash of image in base 36 (used in MediaWiki).", "apihelp-query+allimages-param-user": "Only return files uploaded by this user. Can only be used with $1sort=timestamp. Cannot be used together with $1filterbots.", "apihelp-query+allimages-param-filterbots": "How to filter files uploaded by bots. Can only be used with $1sort=timestamp. Cannot be used together with $1user.", - "apihelp-query+allimages-param-mime": "What MIME type to search for. e.g. image/jpeg.", + "apihelp-query+allimages-param-mime": "What MIME types to search for, e.g. image/jpeg.", "apihelp-query+allimages-param-limit": "How many images in total to return.", "apihelp-query+allimages-example-B": "Show a list of files starting at the letter \"B\"", "apihelp-query+allimages-example-recent": "Show a list of recently uploaded files similar to [[Special:NewFiles]]", + "apihelp-query+allimages-example-mimetypes": "Show a list of files with MIME type image/png or image/gif", "apihelp-query+allimages-example-generator": "Show info about 4 files starting at the letter \"T\"", "apihelp-query+alllinks-description": "Enumerate all links that point to a given namespace.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index c2696d111e..19ec6cb892 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -339,6 +339,7 @@ "apihelp-query+allimages-param-limit": "{{doc-apihelp-param|query+allimages|limit}}", "apihelp-query+allimages-example-B": "{{doc-apihelp-example|query+allimages}}", "apihelp-query+allimages-example-recent": "{{doc-apihelp-example|query+allimages}}", + "apihelp-query+allimages-example-mimetypes": "{{doc-apihelp-example|query+allimages}}", "apihelp-query+allimages-example-generator": "{{doc-apihelp-example|query+allimages}}", "apihelp-query+alllinks-description": "{{doc-apihelp-description|query+alllinks}}", "apihelp-query+alllinks-param-from": "{{doc-apihelp-param|query+alllinks|from}}",