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';
}
'version' => $params['metadataversion'],
'language' => $params['extmetadatalanguage'],
'multilang' => $params['extmetadatamultilang'],
+ 'extmetadatafilter' => $params['extmetadatafilter'],
);
$pageIds = $this->getPageSet()->getAllTitlesByNamespace();
/** @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',
if ( !$h ) {
$this->setWarning( 'Could not create thumbnail because ' .
$image->getName() . ' does not have an associated image handler' );
+
return $thumbParams;
}
// 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']})" );
}
}
* @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
'version' => $metadataOpts ?: 'latest',
'language' => $wgContLang,
'multilang' => false,
+ 'extmetadatafilter' => array(),
);
}
$version = $metadataOpts['version'];
$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
$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;
}
}
}
$result->setIndexedTagName( $retval, 'metadata' );
+
return $retval;
}
if ( $start === null ) {
$start = $img->getTimestamp();
}
+
return $img->getOriginalTitle()->getDBkey() . '|' . $start;
}
public function getAllowedParams() {
global $wgContLang;
+
return array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
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',
'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',
);
}
*/
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',
);
}
)
),
);
+
return array_diff_key( $props, array_flip( $filter ) );
}
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" ),
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',
);
}