Merge "Update documentation of file backend classes"
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
index 81c9faf..86cba83 100644 (file)
@@ -34,8 +34,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
        private static $transformCount = 0;
 
        public function __construct( $query, $moduleName, $prefix = 'ii' ) {
-               // We allow a subclass to override the prefix, to create a related API module.
-               // Some other parts of MediaWiki construct this with a null $prefix, which used to be ignored when this only took two arguments
+               // We allow a subclass to override the prefix, to create a related API
+               // module. Some other parts of MediaWiki construct this with a null
+               // $prefix, which used to be ignored when this only took two arguments
                if ( is_null( $prefix ) ) {
                        $prefix = 'ii';
                }
@@ -53,6 +54,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        'version' => $params['metadataversion'],
                        'language' => $params['extmetadatalanguage'],
                        'multilang' => $params['extmetadatamultilang'],
+                       'extmetadatafilter' => $params['extmetadatafilter'],
                );
 
                $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
@@ -175,7 +177,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                /** @var $oldie File */
                                foreach ( $oldies as $oldie ) {
                                        if ( ++$count > $params['limit'] ) {
-                                               // We've reached the extra one which shows that there are additional pages to be had. Stop here...
+                                               // We've reached the extra one which shows that there are
+                                               // additional pages to be had. Stop here...
                                                // Only set a query-continue if there was only one title
                                                if ( count( $pageIds[NS_FILE] ) == 1 ) {
                                                        $this->setContinueEnumParameter( 'start',
@@ -267,6 +270,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                if ( !$h ) {
                        $this->setWarning( 'Could not create thumbnail because ' .
                                $image->getName() . ' does not have an associated image handler' );
+
                        return $thumbParams;
                }
 
@@ -278,13 +282,15 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        // handlers.
                        $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
                                . '. Using only width and height' );
+
                        return $thumbParams;
                }
 
                if ( isset( $paramList['width'] ) ) {
                        if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
                                $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
-                                       . "in favor of width value derived from {$p}urlwidth/{$p}urlheight ({$thumbParams['width']})" );
+                                       . "in favor of width value derived from {$p}urlwidth/{$p}urlheight "
+                                       . "({$thumbParams['width']})" );
                        }
                }
 
@@ -304,7 +310,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
         * @param array $prop of properties to get (in the keys)
         * @param $result ApiResult object
         * @param array $thumbParams containing 'width' and 'height' items, or null
-        * @param string|array $metadataOpts Options for metadata fetching.
+        * @param array|bool|string $metadataOpts Options for metadata fetching.
         *   This is an array consisting of the keys:
         *    'version': The metadata version for the metadata option
         *    'language': The language for extmetadata property
@@ -319,6 +325,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                'version' => $metadataOpts ?: 'latest',
                                'language' => $wgContLang,
                                'multilang' => false,
+                               'extmetadatafilter' => array(),
                        );
                }
                $version = $metadataOpts['version'];
@@ -389,7 +396,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
                $uploadwarning = isset( $prop['uploadwarning'] );
 
                if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
-                               && $file->isDeleted( File::DELETED_FILE ) ) {
+                       && $file->isDeleted( File::DELETED_FILE )
+               ) {
                        $vals['filehidden'] = '';
 
                        //Early return, tidier than indenting all following things one level
@@ -448,6 +456,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        $format->setSingleLanguage( !$metadataOpts['multilang'] );
                        $format->getContext()->setLanguage( $metadataOpts['language'] );
                        $extmetaArray = $format->fetchExtendedMetadata( $file );
+                       if ( $metadataOpts['extmetadatafilter'] ) {
+                               $extmetaArray = array_intersect_key(
+                                       $extmetaArray, array_flip( $metadataOpts['extmetadatafilter'] )
+                               );
+                       }
                        $vals['extmetadata'] = $extmetaArray;
                }
 
@@ -505,6 +518,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        }
                }
                $result->setIndexedTagName( $retval, 'metadata' );
+
                return $retval;
        }
 
@@ -521,11 +535,13 @@ class ApiQueryImageInfo extends ApiQueryBase {
                if ( $start === null ) {
                        $start = $img->getTimestamp();
                }
+
                return $img->getOriginalTitle()->getDBkey() . '|' . $start;
        }
 
        public function getAllowedParams() {
                global $wgContLang;
+
                return array(
                        'prop' => array(
                                ApiBase::PARAM_ISMULTI => true,
@@ -565,6 +581,10 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                ApiBase::PARAM_TYPE => 'boolean',
                                ApiBase::PARAM_DFLT => false,
                        ),
+                       'extmetadatafilter' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ),
                        'urlparam' => array(
                                ApiBase::PARAM_DFLT => '',
                                ApiBase::PARAM_TYPE => 'string',
@@ -599,18 +619,22 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        'comment' =>        ' comment       - Comment on the version',
                        'parsedcomment' =>  ' parsedcomment - Parse the comment on the version',
                        'url' =>            ' url           - Gives URL to the image and the description page',
-                       'size' =>           ' size          - Adds the size of the image in bytes and the height, width and page count (if applicable)',
-                       'dimensions' =>     ' dimensions    - Alias for size', // For backwards compatibility with Allimages
+                       'size' =>           ' size          - Adds the size of the image in bytes ' .
+                               'and the height, width and page count (if applicable)',
+                       'dimensions' =>     ' dimensions    - Alias for size', // B/C with Allimages
                        'sha1' =>           ' sha1          - Adds SHA-1 hash for the image',
                        'mime' =>           ' mime          - Adds MIME type of the image',
                        'thumbmime' =>      ' thumbmime     - Adds MIME type of the image thumbnail' .
                                ' (requires url and param ' . $modulePrefix . 'urlwidth)',
                        'mediatype' =>      ' mediatype     - Adds the media type of the image',
                        'metadata' =>       ' metadata      - Lists Exif metadata for the version of the image',
-                       'extmetadata' =>    ' extmetadata   - Lists formatted metadata combined from multiple sources. Results are HTML formatted.',
-                       'archivename' =>    ' archivename   - Adds the file name of the archive version for non-latest versions',
+                       'extmetadata' =>    ' extmetadata   - Lists formatted metadata combined ' .
+                               'from multiple sources. Results are HTML formatted.',
+                       'archivename' =>    ' archivename   - Adds the file name of the archive ' .
+                               'version for non-latest versions',
                        'bitdepth' =>       ' bitdepth      - Adds the bit depth of the version',
-                       'uploadwarning' =>  ' uploadwarning - Used by the Special:Upload page to get information about an existing file. Not intended for use outside MediaWiki core',
+                       'uploadwarning' =>  ' uploadwarning - Used by the Special:Upload page to ' .
+                               'get information about an existing file. Not intended for use outside MediaWiki core',
                );
        }
 
@@ -634,24 +658,34 @@ class ApiQueryImageInfo extends ApiQueryBase {
         */
        public function getParamDescription() {
                $p = $this->getModulePrefix();
+
                return array(
                        'prop' => self::getPropertyDescriptions( array(), $p ),
-                       'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
+                       'urlwidth' => array(
+                               "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
                                'For performance reasons if this option is used, ' .
-                                       'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.' ),
+                                       'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.'
+                       ),
                        'urlheight' => "Similar to {$p}urlwidth.",
                        'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
                                "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
                        'limit' => 'How many image revisions to return per image',
                        'start' => 'Timestamp to start listing from',
                        'end' => 'Timestamp to stop listing at',
-                       'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
-                                               "Defaults to '1' for backwards compatibility" ),
-                       'extmetadatalanguage' => array( 'What language to fetch extmetadata in. This affects both which',
-                                               'translation to fetch, if multiple are available, as well as how things',
-                                               'like numbers and various values are formatted.' ),
-                       'extmetadatamultilang' => 'If translations for extmetadata property are available, fetch all of them.',
-                       'continue' => 'If the query response includes a continue value, use it here to get another page of results',
+                       'metadataversion'
+                               => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
+                               "Defaults to '1' for backwards compatibility" ),
+                       'extmetadatalanguage' => array(
+                               'What language to fetch extmetadata in. This affects both which',
+                               'translation to fetch, if multiple are available, as well as how things',
+                               'like numbers and various values are formatted.'
+                       ),
+                       'extmetadatamultilang'
+                               =>'If translations for extmetadata property are available, fetch all of them.',
+                       'extmetadatafilter'
+                               => "If specified and non-empty, only these keys will be returned for {$p}prop=extmetadata",
+                       'continue' => 'If the query response includes a continue value, ' .
+                               'use it here to get another page of results',
                        'localonly' => 'Look only for files in the local repository',
                );
        }
@@ -773,6 +807,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                )
                        ),
                );
+
                return array_diff_key( $props, array_flip( $filter ) );
        }
 
@@ -786,6 +821,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
        public function getPossibleErrors() {
                $p = $this->getModulePrefix();
+
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'code' => "{$p}urlwidth", 'info' => "{$p}urlheight cannot be used without {$p}urlwidth" ),
                        array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ),
@@ -796,7 +832,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
        public function getExamples() {
                return array(
                        'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
-                       'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&iiend=20071231235959&iiprop=timestamp|user|url',
+                       'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
+                               'iiend=20071231235959&iiprop=timestamp|user|url',
                );
        }