69 $prop = array_fill_keys( $params[
'prop'],
true );
70 $fld_sha1 = isset( $prop[
'sha1'] );
71 $fld_timestamp = isset( $prop[
'timestamp'] );
72 $fld_user = isset( $prop[
'user'] );
73 $fld_size = isset( $prop[
'size'] );
74 $fld_dimensions = isset( $prop[
'dimensions'] );
75 $fld_description = isset( $prop[
'description'] ) || isset( $prop[
'parseddescription'] );
76 $fld_parseddescription = isset( $prop[
'parseddescription'] );
77 $fld_mime = isset( $prop[
'mime'] );
78 $fld_mediatype = isset( $prop[
'mediatype'] );
79 $fld_metadata = isset( $prop[
'metadata'] );
80 $fld_bitdepth = isset( $prop[
'bitdepth'] );
81 $fld_archivename = isset( $prop[
'archivename'] );
83 if ( $fld_description && !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
84 $this->
dieWithError(
'apierror-cantview-deleted-description',
'permissiondenied' );
86 if ( $fld_metadata && !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
87 $this->
dieWithError(
'apierror-cantview-deleted-metadata',
'permissiondenied' );
95 if ( $params[
'continue'] !==
null ) {
96 $cont = explode(
'|', $params[
'continue'] );
98 $op = $params[
'dir'] ==
'descending' ?
'<' :
'>';
99 $cont_from = $db->addQuotes( $cont[0] );
100 $cont_timestamp = $db->addQuotes( $db->timestamp( $cont[1] ) );
101 $cont_id = (int)$cont[2];
103 $this->
addWhere(
"fa_name $op $cont_from OR " .
104 "(fa_name = $cont_from AND " .
105 "(fa_timestamp $op $cont_timestamp OR " .
106 "(fa_timestamp = $cont_timestamp AND " .
107 "fa_id $op= $cont_id )))"
112 $dir = ( $params[
'dir'] ==
'descending' ?
'older' :
'newer' );
116 if ( isset( $params[
'prefix'] ) ) {
117 $this->
addWhere(
'fa_name' . $db->buildLike(
118 $this->titlePartToKey( $params[
'prefix'],
NS_FILE ),
119 $db->anyString() ) );
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,
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 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_FILE, $user );
196 $file[
'id'] = (int)$row->fa_id;
197 $file[
'name'] = $row->fa_name;
201 if ( $fld_description &&
202 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
204 if ( isset( $prop[
'parseddescription'] ) ) {
205 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
206 $file[
'description'] = $descriptions[$row->fa_id];
208 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
212 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user )
214 $file[
'userid'] = (int)$row->fa_user;
215 $file[
'user'] = $row->fa_user_text;
217 if ( $fld_sha1 && $canViewFile ) {
218 $file[
'sha1'] = Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
220 if ( $fld_timestamp ) {
223 if ( ( $fld_size || $fld_dimensions ) && $canViewFile ) {
224 $file[
'size'] = $row->fa_size;
227 if ( $pageCount !==
false ) {
228 $file[
'pagecount'] = $pageCount;
231 $file[
'height'] = $row->fa_height;
232 $file[
'width'] = $row->fa_width;
234 if ( $fld_mediatype && $canViewFile ) {
235 $file[
'mediatype'] = $row->fa_media_type;
237 if ( $fld_metadata && $canViewFile ) {
239 $file[
'metadata'] = $row->fa_metadata
243 if ( $fld_bitdepth && $canViewFile ) {
244 $file[
'bitdepth'] = $row->fa_bits;
246 if ( $fld_mime && $canViewFile ) {
247 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
249 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
250 $file[
'archivename'] = $row->fa_archive_name;
253 if ( $row->fa_deleted & File::DELETED_FILE ) {
254 $file[
'filehidden'] =
true;
256 if ( $row->fa_deleted & File::DELETED_COMMENT ) {
257 $file[
'commenthidden'] =
true;
259 if ( $row->fa_deleted & File::DELETED_USER ) {
260 $file[
'userhidden'] =
true;
262 if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
264 $file[
'suppressed'] =
true;
270 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
276 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );