$scale = $this->getScale( $params );
+ $metadataOpts = array(
+ 'version' => $params['metadataversion'],
+ 'language' => $params['extmetadatalanguage'],
+ 'multilang' => $params['extmetadatamultilang'],
+ );
+
$pageIds = $this->getPageSet()->getAllTitlesByNamespace();
if ( !empty( $pageIds[NS_FILE] ) ) {
$titles = array_keys( $pageIds[NS_FILE] );
$start = $title === $fromTitle ? $fromTimestamp : $params['start'];
if ( !isset( $images[$title] ) ) {
- $result->addValue(
- array( 'query', 'pages', intval( $pageId ) ),
- 'imagerepository', ''
- );
- // The above can't fail because it doesn't increase the result size
- continue;
+ if ( isset( $prop['uploadwarning'] ) ) {
+ // Uploadwarning needs info about non-existing files
+ $images[$title] = wfLocalFile( $title );
+ } else {
+ $result->addValue(
+ array( 'query', 'pages', intval( $pageId ) ),
+ 'imagerepository', ''
+ );
+ // The above can't fail because it doesn't increase the result size
+ continue;
+ }
}
/** @var $img File */
$fit = $this->addPageSubItem( $pageId,
self::getInfo( $img, $prop, $result,
- $finalThumbParams, $params['metadataversion'] ) );
+ $finalThumbParams, $metadataOpts
+ )
+ );
if ( !$fit ) {
if ( count( $pageIds[NS_FILE] ) == 1 ) {
// See the 'the user is screwed' comment above
$fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
$this->addPageSubItem( $pageId,
self::getInfo( $oldie, $prop, $result,
- $finalThumbParams, $params['metadataversion']
+ $finalThumbParams, $metadataOpts
)
);
if ( !$fit ) {
* @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 $version Version of image metadata (for things like jpeg which have different versions).
+ * @param string|array $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
+ * 'multilang': Return all translations in extmetadata property
* @return Array: result array
*/
- static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) {
+ static function getInfo( $file, $prop, $result, $thumbParams = null, $metadataOpts = false ) {
+ global $wgContLang;
+
+ if ( !$metadataOpts || is_string( $metadataOpts ) ) {
+ $metadataOpts = array(
+ 'version' => $metadataOpts ?: 'latest',
+ 'language' => $wgContLang,
+ 'multilang' => false,
+ );
+ }
+ $version = $metadataOpts['version'];
$vals = array();
// Timestamp is shown even if the file is revdelete'd in interface
// so do same here.
$url = isset( $prop['url'] );
$sha1 = isset( $prop['sha1'] );
$meta = isset( $prop['metadata'] );
+ $extmetadata = isset( $prop['extmetadata'] );
$mime = isset( $prop['mime'] );
$mediatype = isset( $prop['mediatype'] );
$archive = isset( $prop['archivename'] );
$bitdepth = isset( $prop['bitdepth'] );
+ $uploadwarning = isset( $prop['uploadwarning'] );
if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
&& $file->isDeleted( File::DELETED_FILE ) ) {
$vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
}
+ if ( $extmetadata ) {
+ // Note, this should return an array where all the keys
+ // start with a letter, and all the values are strings.
+ // Thus there should be no issue with format=xml.
+ $format = new FormatMetadata;
+ $format->setSingleLanguage( !$metadataOpts['multilang'] );
+ $format->getContext()->setLanguage( $metadataOpts['language'] );
+ $extmetaArray = $format->fetchExtendedMetadata( $file );
+ $vals['extmetadata'] = $extmetaArray;
+ }
+
if ( $mime ) {
$vals['mime'] = $file->getMimeType();
}
$vals['bitdepth'] = $file->getBitDepth();
}
+ if ( $uploadwarning ) {
+ $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
+ }
+
return $vals;
}
}
public function getAllowedParams() {
+ global $wgContLang;
return array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_DFLT => '1',
),
+ 'extmetadatalanguage' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => $wgContLang->getCode(),
+ ),
+ 'extmetadatamultilang' => array(
+ ApiBase::PARAM_TYPE => 'boolean',
+ ApiBase::PARAM_DFLT => false,
+ ),
'urlparam' => array(
ApiBase::PARAM_DFLT => '',
ApiBase::PARAM_TYPE => 'string',
' (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',
'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',
);
}
'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',
'localonly' => 'Look only for files in the local repository',
);