58 parent::__construct( $query, $moduleName,
'fa' );
59 $this->commentStore = $commentStore;
60 $this->commentFormatter = $commentFormatter;
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 ) {
97 $op =
$params[
'dir'] ==
'descending' ?
'<=' :
'>=';
98 $this->
addWhere( $db->buildComparison( $op, [
99 'fa_name' => $cont[0],
100 'fa_timestamp' => $db->timestamp( $cont[1] ),
106 $dir = (
$params[
'dir'] ==
'descending' ?
'older' :
'newer' );
110 if ( isset(
$params[
'prefix'] ) ) {
120 $sha1Set = isset(
$params[
'sha1'] );
121 $sha1base36Set = isset(
$params[
'sha1base36'] );
122 if ( $sha1Set || $sha1base36Set ) {
125 $sha1 = strtolower(
$params[
'sha1'] );
129 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
130 } elseif ( $sha1base36Set ) {
131 $sha1 = strtolower(
$params[
'sha1base36'] );
133 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
139 if ( !$this->
getAuthority()->isAllowed(
'deletedtext' ) ) {
140 $bitmask = File::DELETED_FILE;
141 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
142 $bitmask = File::DELETED_FILE | File::DELETED_RESTRICTED;
147 $this->
addWhere( $this->
getDB()->bitAnd(
'fa_deleted', $bitmask ) .
" != $bitmask" );
154 $sort = (
$params[
'dir'] ==
'descending' ?
' DESC' :
'' );
157 'fa_timestamp' . $sort,
161 $res = $this->
select( __METHOD__ );
164 $formattedDescriptions = [];
166 if ( $fld_parseddescription ) {
168 foreach ( $res as $row ) {
169 $desc = $this->commentStore->getComment(
'fa_description', $row )->text;
170 $descriptions[$row->fa_id] = $desc;
171 $commentItems[$row->fa_id] = (
new CommentItem( $desc ) )
174 $formattedDescriptions = $this->commentFormatter->createBatch()
175 ->comments( $commentItems )
181 foreach ( $res as $row ) {
182 if ( ++$count > $limit ) {
186 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
191 $exists = $row->fa_archive_name !==
'';
192 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_FILE, $user );
195 $file[
'id'] = (int)$row->fa_id;
196 $file[
'name'] = $row->fa_name;
197 $title = Title::makeTitle(
NS_FILE, $row->fa_name );
200 if ( $fld_description &&
201 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
203 if ( isset( $prop[
'parseddescription'] ) ) {
204 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
205 $file[
'description'] = $descriptions[$row->fa_id];
207 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
211 RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user )
213 $file[
'userid'] = (int)$row->fa_user;
214 $file[
'user'] = $row->fa_user_text;
217 $file[
'filemissing'] =
true;
219 if ( $fld_sha1 && $canViewFile && $exists ) {
220 $file[
'sha1'] = \Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
222 if ( $fld_timestamp ) {
223 $file[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->fa_timestamp );
225 if ( ( $fld_size || $fld_dimensions ) && $canViewFile && $exists ) {
226 $file[
'size'] = $row->fa_size;
229 if ( $pageCount !==
false ) {
230 $file[
'pagecount'] = $pageCount;
233 $file[
'height'] = $row->fa_height;
234 $file[
'width'] = $row->fa_width;
236 if ( $fld_mediatype && $canViewFile && $exists ) {
237 $file[
'mediatype'] = $row->fa_media_type;
239 if ( $fld_metadata && $canViewFile && $exists ) {
241 $file[
'metadata'] = $row->fa_metadata
245 if ( $fld_bitdepth && $canViewFile && $exists ) {
246 $file[
'bitdepth'] = $row->fa_bits;
248 if ( $fld_mime && $canViewFile && $exists ) {
249 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
251 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
252 $file[
'archivename'] = $row->fa_archive_name;
255 if ( $row->fa_deleted & File::DELETED_FILE ) {
256 $file[
'filehidden'] =
true;
258 if ( $row->fa_deleted & File::DELETED_COMMENT ) {
259 $file[
'commenthidden'] =
true;
261 if ( $row->fa_deleted & File::DELETED_USER ) {
262 $file[
'userhidden'] =
true;
264 if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
266 $file[
'suppressed'] =
true;
269 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $file );
272 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
278 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );
287 ParamValidator::PARAM_DEFAULT =>
'ascending',
288 ParamValidator::PARAM_TYPE => [
294 'sha1base36' =>
null,
296 ParamValidator::PARAM_DEFAULT =>
'timestamp',
297 ParamValidator::PARAM_ISMULTI =>
true,
298 ParamValidator::PARAM_TYPE => [
315 ParamValidator::PARAM_DEFAULT => 10,
316 ParamValidator::PARAM_TYPE =>
'limit',
317 IntegerDef::PARAM_MIN => 1,
329 'action=query&list=filearchive'
330 =>
'apihelp-query+filearchive-example-simple',
335 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Filearchive';
340class_alias( ApiQueryFilearchive::class,
'ApiQueryFilearchive' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
Deleted file in the 'filearchive' table.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archivedfile object.
static newFromRow( $row)
Loads a file object from the filearchive table.
Implements some public methods and some protected utility functions which are required by multiple ch...