43 private $commentStore;
46 private $commentFormatter;
60 parent::__construct( $query, $moduleName,
'fa' );
61 $this->commentStore = $commentStore;
62 $this->commentFormatter = $commentFormatter;
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' );
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'] ) ) {
113 $this->
addWhere(
'fa_name' . $db->buildLike(
114 $this->titlePartToKey( $params[
'prefix'],
NS_FILE ),
115 $db->anyString() ) );
118 $sha1Set = isset( $params[
'sha1'] );
119 $sha1base36Set = isset( $params[
'sha1base36'] );
120 if ( $sha1Set || $sha1base36Set ) {
123 $sha1 = strtolower( $params[
'sha1'] );
127 $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
128 } elseif ( $sha1base36Set ) {
129 $sha1 = strtolower( $params[
'sha1base36'] );
131 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
137 if ( !$this->
getAuthority()->isAllowed(
'deletedtext' ) ) {
139 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
145 $this->
addWhere( $this->
getDB()->bitAnd(
'fa_deleted', $bitmask ) .
" != $bitmask" );
150 $limit = $params[
'limit'];
152 $sort = ( $params[
'dir'] ==
'descending' ?
' DESC' :
'' );
155 'fa_timestamp' . $sort,
162 $formattedDescriptions = [];
164 if ( $fld_parseddescription ) {
166 foreach (
$res as $row ) {
167 $desc = $this->commentStore->getComment(
'fa_description', $row )->text;
168 $descriptions[$row->fa_id] = $desc;
169 $commentItems[$row->fa_id] = (
new CommentItem( $desc ) )
172 $formattedDescriptions = $this->commentFormatter->createBatch()
173 ->comments( $commentItems )
179 foreach (
$res as $row ) {
180 if ( ++$count > $limit ) {
184 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
189 $canViewFile = RevisionRecord::userCanBitfield( $row->fa_deleted,
File::DELETED_FILE, $user );
192 $file[
'id'] = (int)$row->fa_id;
193 $file[
'name'] = $row->fa_name;
197 if ( $fld_description &&
200 if ( isset( $prop[
'parseddescription'] ) ) {
201 $file[
'parseddescription'] = $formattedDescriptions[$row->fa_id];
202 $file[
'description'] = $descriptions[$row->fa_id];
204 $file[
'description'] = $this->commentStore->getComment(
'fa_description', $row )->text;
210 $file[
'userid'] = (int)$row->fa_user;
211 $file[
'user'] = $row->fa_user_text;
213 if ( $fld_sha1 && $canViewFile ) {
214 $file[
'sha1'] = Wikimedia\base_convert( $row->fa_sha1, 36, 16, 40 );
216 if ( $fld_timestamp ) {
219 if ( ( $fld_size || $fld_dimensions ) && $canViewFile ) {
220 $file[
'size'] = $row->fa_size;
223 if ( $pageCount !==
false ) {
224 $file[
'pagecount'] = $pageCount;
227 $file[
'height'] = $row->fa_height;
228 $file[
'width'] = $row->fa_width;
230 if ( $fld_mediatype && $canViewFile ) {
231 $file[
'mediatype'] = $row->fa_media_type;
233 if ( $fld_metadata && $canViewFile ) {
235 $file[
'metadata'] = $row->fa_metadata
239 if ( $fld_bitdepth && $canViewFile ) {
240 $file[
'bitdepth'] = $row->fa_bits;
242 if ( $fld_mime && $canViewFile ) {
243 $file[
'mime'] =
"$row->fa_major_mime/$row->fa_minor_mime";
245 if ( $fld_archivename && $row->fa_archive_name !==
null ) {
246 $file[
'archivename'] = $row->fa_archive_name;
250 $file[
'filehidden'] =
true;
253 $file[
'commenthidden'] =
true;
256 $file[
'userhidden'] =
true;
260 $file[
'suppressed'] =
true;
266 'continue',
"$row->fa_name|$row->fa_timestamp|$row->fa_id"
272 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'fa' );
281 ParamValidator::PARAM_DEFAULT =>
'ascending',
282 ParamValidator::PARAM_TYPE => [
288 'sha1base36' =>
null,
290 ParamValidator::PARAM_DEFAULT =>
'timestamp',
291 ParamValidator::PARAM_ISMULTI =>
true,
292 ParamValidator::PARAM_TYPE => [
309 ParamValidator::PARAM_DEFAULT => 10,
310 ParamValidator::PARAM_TYPE =>
'limit',
311 IntegerDef::PARAM_MIN => 1,
323 'action=query&list=filearchive'
324 =>
'apihelp-query+filearchive-example-simple',
329 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Filearchive';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
This is a base class for all Query modules.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
validateSha1Base36Hash( $hash)
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Query module to enumerate all deleted files.
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, CommentFormatter $commentFormatter)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static processMetaData( $metadata, $result)
This is the main query class.
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.
Represents a page (or page fragment) title within MediaWiki.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.