56 $prop = array_fill_keys( $params[
'prop'],
true );
57 $fld_sha1 = isset( $prop[
'sha1'] );
58 $fld_timestamp = isset( $prop[
'timestamp'] );
59 $fld_user = isset( $prop[
'user'] );
60 $fld_size = isset( $prop[
'size'] );
61 $fld_dimensions = isset( $prop[
'dimensions'] );
62 $fld_description = isset( $prop[
'description'] ) || isset( $prop[
'parseddescription'] );
63 $fld_parseddescription = isset( $prop[
'parseddescription'] );
64 $fld_mime = isset( $prop[
'mime'] );
65 $fld_mediatype = isset( $prop[
'mediatype'] );
66 $fld_metadata = isset( $prop[
'metadata'] );
67 $fld_bitdepth = isset( $prop[
'bitdepth'] );
68 $fld_archivename = isset( $prop[
'archivename'] );
70 if ( $fld_description && !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
71 $this->
dieWithError(
'apierror-cantview-deleted-description',
'permissiondenied' );
73 if ( $fld_metadata && !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
74 $this->
dieWithError(
'apierror-cantview-deleted-metadata',
'permissiondenied' );
82 if ( $params[
'continue'] !==
null ) {
84 $op = $params[
'dir'] ==
'descending' ?
'<=' :
'>=';
85 $this->
addWhere( $db->buildComparison( $op, [
86 'fa_name' => $cont[0],
87 'fa_timestamp' => $db->timestamp( $cont[1] ),
93 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
97 if ( isset( $params[
'prefix'] ) ) {
107 $sha1Set = isset( $params[
'sha1'] );
108 $sha1base36Set = isset( $params[
'sha1base36'] );
109 if ( $sha1Set || $sha1base36Set ) {
112 $sha1 = strtolower( $params[
'sha1'] );
116 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
117 } elseif ( $sha1base36Set ) {
118 $sha1 = strtolower( $params[
'sha1base36'] );
120 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
126 if ( !$this->
getAuthority()->isAllowed(
'deletedtext' ) ) {
127 $bitmask = File::DELETED_FILE;
128 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
129 $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
134 $this->
addWhere( $this->
getDB()->bitAnd(
'fa_deleted', $bitmask ) .
" != $bitmask" );
139 $limit = $params[
'limit'];
141 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
144 'fa_timestamp' . $sort,
148 $res = $this->
select( __METHOD__ );
151 $formattedDescriptions = [];
153 if ( $fld_parseddescription ) {
155 foreach ( $res as $row ) {
156 $desc = $this->commentStore->getComment(
'fa_description', $row )->text;
157 $descriptions[$row->fa_id] = $desc;
158 $commentItems[$row->fa_id] = (
new CommentItem( $desc ) )
161 $formattedDescriptions = $this->commentFormatter->createBatch()
162 ->comments( $commentItems )
168 foreach ( $res as $row ) {
169 if ( ++$count > $limit ) {
173 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
178 $exists = $row->fa_archive_name !==
'';
179 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_FILE, $user );
182 $file[
'id'] = (int)$row->fa_id;
183 $file[
'name'] = $row->fa_name;
187 if ( $fld_description &&
188 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
190 if ( isset( $prop[
'parseddescription'] ) ) {
191 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
192 $file[
'description'] = $descriptions[$row->fa_id];
194 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
198 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user )
200 $file[
'userid'] = (int)$row->fa_user;
201 $file[
'user'] = $row->fa_user_text;
204 $file[
'filemissing'] =
true;
206 if ( $fld_sha1 && $canViewFile && $exists ) {
207 $file[
'sha1'] = \Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
209 if ( $fld_timestamp ) {
210 $file[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->fa_timestamp );
212 if ( ( $fld_size || $fld_dimensions ) && $canViewFile && $exists ) {
213 $file[
'size'] = $row->fa_size;
216 if ( $pageCount !==
false ) {
217 $file[
'pagecount'] = $pageCount;
220 $file[
'height'] = $row->fa_height;
221 $file[
'width'] = $row->fa_width;
223 if ( $fld_mediatype && $canViewFile && $exists ) {
224 $file[
'mediatype'] = $row->fa_media_type;
226 if ( $fld_metadata && $canViewFile && $exists ) {
228 $file[
'metadata'] = $row->fa_metadata
232 if ( $fld_bitdepth && $canViewFile && $exists ) {
233 $file[
'bitdepth'] = $row->fa_bits;
235 if ( $fld_mime && $canViewFile && $exists ) {
236 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
238 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
239 $file[
'archivename'] = $row->fa_archive_name;
242 if ( $row->fa_deleted & File::DELETED_FILE ) {
243 $file[
'filehidden'] =
true;
245 if ( $row->fa_deleted & File::DELETED_COMMENT ) {
246 $file[
'commenthidden'] =
true;
248 if ( $row->fa_deleted & File::DELETED_USER ) {
249 $file[
'userhidden'] =
true;
251 if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
253 $file[
'suppressed'] =
true;
256 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $file );
259 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
265 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );