$scale = $this->getScale( $params );
- $metadataOpts = array(
+ $opts = array(
'version' => $params['metadataversion'],
'language' => $params['extmetadatalanguage'],
'multilang' => $params['extmetadatamultilang'],
'extmetadatafilter' => $params['extmetadatafilter'],
+ 'revdelUser' => $this->getUser(),
);
$pageIds = $this->getPageSet()->getAllTitlesByNamespace();
}
}
- $result = $this->getResult();
- //search only inside the local repo
+ $user = $this->getUser();
+ $findTitles = array_map( function ( $title ) use ( $user ) {
+ return array(
+ 'title' => $title,
+ 'private' => $user,
+ );
+ }, $titles );
+
if ( $params['localonly'] ) {
- $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $titles );
+ $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
} else {
- $images = RepoGroup::singleton()->findFiles( $titles );
+ $images = RepoGroup::singleton()->findFiles( $findTitles );
}
+
+ $result = $this->getResult();
foreach ( $titles as $title ) {
$pageId = $pageIds[NS_FILE][$title];
$start = $title === $fromTitle ? $fromTimestamp : $params['start'];
$fit = $this->addPageSubItem( $pageId,
self::getInfo( $img, $prop, $result,
- $finalThumbParams, $metadataOpts
+ $finalThumbParams, $opts
)
);
if ( !$fit ) {
$fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
$this->addPageSubItem( $pageId,
self::getInfo( $oldie, $prop, $result,
- $finalThumbParams, $metadataOpts
+ $finalThumbParams, $opts
)
);
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 array|bool|string $metadataOpts Options for metadata fetching.
+ * @param array|bool|string $opts Options for data 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
+ * 'revdelUser': User to use when checking whether to show revision-deleted fields.
* @return Array: result array
*/
- static function getInfo( $file, $prop, $result, $thumbParams = null, $metadataOpts = false ) {
+ static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
global $wgContLang;
- if ( !$metadataOpts || is_string( $metadataOpts ) ) {
- $metadataOpts = array(
- 'version' => $metadataOpts ?: 'latest',
+ $anyHidden = false;
+
+ if ( !$opts || is_string( $opts ) ) {
+ $opts = array(
+ 'version' => $opts ?: 'latest',
'language' => $wgContLang,
'multilang' => false,
'extmetadatafilter' => array(),
+ 'revdelUser' => null,
);
}
- $version = $metadataOpts['version'];
+ $version = $opts['version'];
$vals = array();
// Timestamp is shown even if the file is revdelete'd in interface
// so do same here.
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
}
+ // Handle external callers who don't pass revdelUser
+ if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
+ $revdelUser = $opts['revdelUser'];
+ $canShowField = function ( $field ) use ( $file, $revdelUser ) {
+ return $file->userCan( $field, $revdelUser );
+ };
+ } else {
+ $canShowField = function ( $field ) use ( $file ) {
+ return !$file->isDeleted( $field );
+ };
+ }
+
$user = isset( $prop['user'] );
$userid = isset( $prop['userid'] );
if ( $user || $userid ) {
if ( $file->isDeleted( File::DELETED_USER ) ) {
$vals['userhidden'] = '';
- } else {
+ $anyHidden = true;
+ }
+ if ( $canShowField( File::DELETED_USER ) ) {
if ( $user ) {
$vals['user'] = $file->getUser();
}
if ( $pcomment || $comment ) {
if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
$vals['commenthidden'] = '';
- } else {
+ $anyHidden = true;
+ }
+ if ( $canShowField( File::DELETED_COMMENT ) ) {
if ( $pcomment ) {
$vals['parsedcomment'] = Linker::formatComment(
- $file->getDescription(), $file->getTitle() );
+ $file->getDescription( File::RAW ), $file->getTitle() );
}
if ( $comment ) {
- $vals['comment'] = $file->getDescription();
+ $vals['comment'] = $file->getDescription( File::RAW );
}
}
}
+ $canonicaltitle = isset( $prop['canonicaltitle'] );
$url = isset( $prop['url'] );
$sha1 = isset( $prop['sha1'] );
$meta = isset( $prop['metadata'] );
$extmetadata = isset( $prop['extmetadata'] );
+ $commonmeta = isset( $prop['commonmetadata'] );
$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 )
- ) {
+ if ( $uploadwarning ) {
+ $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
+ }
+
+ if ( $file->isDeleted( File::DELETED_FILE ) ) {
$vals['filehidden'] = '';
+ $anyHidden = true;
+ }
+
+ if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
+ $vals['suppressed'] = true;
+ }
+ if ( !$canShowField( File::DELETED_FILE ) ) {
//Early return, tidier than indenting all following things one level
return $vals;
}
+ if ( $canonicaltitle ) {
+ $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
+ }
+
if ( $url ) {
if ( !is_null( $thumbParams ) ) {
$mto = $file->transform( $thumbParams );
}
$vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
}
+ if ( $commonmeta ) {
+ $metaArray = $file->getCommonMetaArray();
+ $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : array();
+ }
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'] );
+ $format->setSingleLanguage( !$opts['multilang'] );
+ $format->getContext()->setLanguage( $opts['language'] );
$extmetaArray = $format->fetchExtendedMetadata( $file );
- if ( $metadataOpts['extmetadatafilter'] ) {
+ if ( $opts['extmetadatafilter'] ) {
$extmetaArray = array_intersect_key(
- $extmetaArray, array_flip( $metadataOpts['extmetadatafilter'] )
+ $extmetaArray, array_flip( $opts['extmetadatafilter'] )
);
}
$vals['extmetadata'] = $extmetaArray;
$vals['bitdepth'] = $file->getBitDepth();
}
- if ( $uploadwarning ) {
- $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
- }
-
return $vals;
}
}
public function getCacheMode( $params ) {
+ if ( $this->userCanSeeRevDel() ) {
+ return 'private';
+ }
+
return 'public';
}
'userid' => ' userid - Add the user ID that uploaded the image version',
'comment' => ' comment - Comment on the version',
'parsedcomment' => ' parsedcomment - Parse the comment on the version',
+ 'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
'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)',
' (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',
+ 'commonmetadata' => ' commonmetadata - Lists file format generic 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 ' .
ApiBase::PROP_NULLABLE => true
)
),
+ 'canonicaltitle' => array(
+ 'canonicaltitle' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
'url' => array(
'filehidden' => 'boolean',
'thumburl' => array(