71 $prop = array_fill_keys( $params[
'prop'],
true );
72 $fld_sha1 = isset( $prop[
'sha1'] );
73 $fld_timestamp = isset( $prop[
'timestamp'] );
74 $fld_user = isset( $prop[
'user'] );
75 $fld_size = isset( $prop[
'size'] );
76 $fld_dimensions = isset( $prop[
'dimensions'] );
77 $fld_description = isset( $prop[
'description'] ) || isset( $prop[
'parseddescription'] );
78 $fld_parseddescription = isset( $prop[
'parseddescription'] );
79 $fld_mime = isset( $prop[
'mime'] );
80 $fld_mediatype = isset( $prop[
'mediatype'] );
81 $fld_metadata = isset( $prop[
'metadata'] );
82 $fld_bitdepth = isset( $prop[
'bitdepth'] );
83 $fld_archivename = isset( $prop[
'archivename'] );
85 if ( $fld_description && !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
86 $this->
dieWithError(
'apierror-cantview-deleted-description',
'permissiondenied' );
88 if ( $fld_metadata && !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
89 $this->
dieWithError(
'apierror-cantview-deleted-metadata',
'permissiondenied' );
92 $fileQuery = ArchivedFile::getQueryInfo();
97 if ( $params[
'continue'] !==
null ) {
99 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
100 $this->
addWhere( $db->buildComparison( $op, [
101 'fa_name' => $cont[0],
102 'fa_timestamp' => $db->timestamp( $cont[1] ),
108 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
112 if ( isset( $params[
'prefix'] ) ) {
122 $sha1Set = isset( $params[
'sha1'] );
123 $sha1base36Set = isset( $params[
'sha1base36'] );
124 if ( $sha1Set || $sha1base36Set ) {
127 $sha1 = strtolower( $params[
'sha1'] );
131 $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
132 } elseif ( $sha1base36Set ) {
133 $sha1 = strtolower( $params[
'sha1base36'] );
135 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
141 if ( !$this->
getAuthority()->isAllowed(
'deletedtext' ) ) {
142 $bitmask = File::DELETED_FILE;
143 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
144 $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
149 $this->
addWhere( $this->
getDB()->bitAnd(
'fa_deleted', $bitmask ) .
" != $bitmask" );
154 $limit = $params[
'limit'];
156 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
159 'fa_timestamp' . $sort,
163 $res = $this->
select( __METHOD__ );
166 $formattedDescriptions = [];
168 if ( $fld_parseddescription ) {
170 foreach ( $res as $row ) {
171 $desc = $this->commentStore->getComment(
'fa_description', $row )->text;
172 $descriptions[$row->fa_id] = $desc;
173 $commentItems[$row->fa_id] = (
new CommentItem( $desc ) )
176 $formattedDescriptions = $this->commentFormatter->createBatch()
177 ->comments( $commentItems )
183 foreach ( $res as $row ) {
184 if ( ++$count > $limit ) {
188 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
193 $exists = $row->fa_archive_name !==
'';
194 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_FILE, $user );
197 $file[
'id'] = (int)$row->fa_id;
198 $file[
'name'] = $row->fa_name;
199 $title = Title::makeTitle(
NS_FILE, $row->fa_name );
202 if ( $fld_description &&
203 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
205 if ( isset( $prop[
'parseddescription'] ) ) {
206 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
207 $file[
'description'] = $descriptions[$row->fa_id];
209 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
213 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user )
215 $file[
'userid'] = (int)$row->fa_user;
216 $file[
'user'] = $row->fa_user_text;
219 $file[
'filemissing'] =
true;
221 if ( $fld_sha1 && $canViewFile && $exists ) {
222 $file[
'sha1'] = Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
224 if ( $fld_timestamp ) {
227 if ( ( $fld_size || $fld_dimensions ) && $canViewFile && $exists ) {
228 $file[
'size'] = $row->fa_size;
230 $pageCount = ArchivedFile::newFromRow( $row )->pageCount();
231 if ( $pageCount !==
false ) {
232 $file[
'pagecount'] = $pageCount;
235 $file[
'height'] = $row->fa_height;
236 $file[
'width'] = $row->fa_width;
238 if ( $fld_mediatype && $canViewFile && $exists ) {
239 $file[
'mediatype'] = $row->fa_media_type;
241 if ( $fld_metadata && $canViewFile && $exists ) {
242 $metadataArray = ArchivedFile::newFromRow( $row )->getMetadataArray();
243 $file[
'metadata'] = $row->fa_metadata
247 if ( $fld_bitdepth && $canViewFile && $exists ) {
248 $file[
'bitdepth'] = $row->fa_bits;
250 if ( $fld_mime && $canViewFile && $exists ) {
251 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
253 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
254 $file[
'archivename'] = $row->fa_archive_name;
257 if ( $row->fa_deleted & File::DELETED_FILE ) {
258 $file[
'filehidden'] =
true;
260 if ( $row->fa_deleted & File::DELETED_COMMENT ) {
261 $file[
'commenthidden'] =
true;
263 if ( $row->fa_deleted & File::DELETED_USER ) {
264 $file[
'userhidden'] =
true;
266 if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
268 $file[
'suppressed'] =
true;
274 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
280 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );