51 $prop = array_fill_keys( $params[
'prop'],
true );
52 $fld_sha1 = isset( $prop[
'sha1'] );
53 $fld_timestamp = isset( $prop[
'timestamp'] );
54 $fld_user = isset( $prop[
'user'] );
55 $fld_size = isset( $prop[
'size'] );
56 $fld_dimensions = isset( $prop[
'dimensions'] );
57 $fld_description = isset( $prop[
'description'] ) || isset( $prop[
'parseddescription'] );
58 $fld_parseddescription = isset( $prop[
'parseddescription'] );
59 $fld_mime = isset( $prop[
'mime'] );
60 $fld_mediatype = isset( $prop[
'mediatype'] );
61 $fld_metadata = isset( $prop[
'metadata'] );
62 $fld_bitdepth = isset( $prop[
'bitdepth'] );
63 $fld_archivename = isset( $prop[
'archivename'] );
65 if ( $fld_description && !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
66 $this->
dieWithError(
'apierror-cantview-deleted-description',
'permissiondenied' );
68 if ( $fld_metadata && !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
69 $this->
dieWithError(
'apierror-cantview-deleted-metadata',
'permissiondenied' );
77 if ( $params[
'continue'] !==
null ) {
79 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
80 $this->
addWhere( $db->buildComparison( $op, [
81 'fa_name' => $cont[0],
82 'fa_timestamp' => $db->timestamp( $cont[1] ),
88 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
92 if ( isset( $params[
'prefix'] ) ) {
102 $sha1Set = isset( $params[
'sha1'] );
103 $sha1base36Set = isset( $params[
'sha1base36'] );
104 if ( $sha1Set || $sha1base36Set ) {
107 $sha1 = strtolower( $params[
'sha1'] );
111 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
112 } elseif ( $sha1base36Set ) {
113 $sha1 = strtolower( $params[
'sha1base36'] );
115 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
121 if ( !$this->
getAuthority()->isAllowed(
'deletedtext' ) ) {
122 $bitmask = File::DELETED_FILE;
123 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
124 $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
129 $this->
addWhere( $this->
getDB()->bitAnd(
'fa_deleted', $bitmask ) .
" != $bitmask" );
134 $limit = $params[
'limit'];
136 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
139 'fa_timestamp' . $sort,
143 $res = $this->
select( __METHOD__ );
146 $formattedDescriptions = [];
148 if ( $fld_parseddescription ) {
150 foreach ( $res as $row ) {
151 $desc = $this->commentStore->getComment(
'fa_description', $row )->text;
152 $descriptions[$row->fa_id] = $desc;
153 $commentItems[$row->fa_id] = (
new CommentItem( $desc ) )
156 $formattedDescriptions = $this->commentFormatter->createBatch()
157 ->comments( $commentItems )
163 foreach ( $res as $row ) {
164 if ( ++$count > $limit ) {
168 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
173 $exists = $row->fa_archive_name !==
'';
174 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_FILE, $user );
177 $file[
'id'] = (int)$row->fa_id;
178 $file[
'name'] = $row->fa_name;
182 if ( $fld_description &&
183 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
185 if ( isset( $prop[
'parseddescription'] ) ) {
186 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
187 $file[
'description'] = $descriptions[$row->fa_id];
189 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
193 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user )
195 $file[
'userid'] = (int)$row->fa_user;
196 $file[
'user'] = $row->fa_user_text;
199 $file[
'filemissing'] =
true;
201 if ( $fld_sha1 && $canViewFile && $exists ) {
202 $file[
'sha1'] = \Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
204 if ( $fld_timestamp ) {
205 $file[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->fa_timestamp );
207 if ( ( $fld_size || $fld_dimensions ) && $canViewFile && $exists ) {
208 $file[
'size'] = $row->fa_size;
211 if ( $pageCount !==
false ) {
212 $file[
'pagecount'] = $pageCount;
215 $file[
'height'] = $row->fa_height;
216 $file[
'width'] = $row->fa_width;
218 if ( $fld_mediatype && $canViewFile && $exists ) {
219 $file[
'mediatype'] = $row->fa_media_type;
221 if ( $fld_metadata && $canViewFile && $exists ) {
223 $file[
'metadata'] = $row->fa_metadata
227 if ( $fld_bitdepth && $canViewFile && $exists ) {
228 $file[
'bitdepth'] = $row->fa_bits;
230 if ( $fld_mime && $canViewFile && $exists ) {
231 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
233 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
234 $file[
'archivename'] = $row->fa_archive_name;
237 if ( $row->fa_deleted & File::DELETED_FILE ) {
238 $file[
'filehidden'] =
true;
240 if ( $row->fa_deleted & File::DELETED_COMMENT ) {
241 $file[
'commenthidden'] =
true;
243 if ( $row->fa_deleted & File::DELETED_USER ) {
244 $file[
'userhidden'] =
true;
246 if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
248 $file[
'suppressed'] =
true;
251 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $file );
254 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
260 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );