Allow querying for multiple MIME types in the allimages API
authorRicordisamoa <ricordisamoa@openmailbox.org>
Mon, 29 Dec 2014 10:53:37 +0000 (11:53 +0100)
committerRicordisamoa <ricordisamoa@openmailbox.org>
Mon, 29 Dec 2014 21:57:29 +0000 (22:57 +0100)
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

RELEASE-NOTES-1.25
includes/api/ApiQueryAllImages.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json

index 77dc55b..065a5d7 100644 (file)
@@ -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.
index 20e9f5e..6c962cd 100644 (file)
@@ -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',
index 61de86c..9286424 100644 (file)
        "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. <kbd>image/jpeg</kbd>.",
        "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 <kbd>image/png</kbd> or <kbd>image/gif</kbd>",
        "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.",
index c2696d1..19ec6cb 100644 (file)
        "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}}",