47 parent::__construct( $query, $moduleName,
'ai' );
59 return $this->mRepo->getReplicaDB();
76 if ( $resultPageSet->isResolvingRedirects() ) {
77 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
80 $this->run( $resultPageSet );
87 private function run( $resultPageSet =
null ) {
100 $prop = array_fill_keys( $params[
'prop'],
true );
106 $fileOptions[
'force-index'] =
'fr_timestamp';
110 $this->
addTables( $fileQuery[
'tables'] );
111 $this->
addFields( $fileQuery[
'fields'] );
115 ?
'img_filerevision_id'
118 $ascendingOrder =
true;
119 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
120 $ascendingOrder =
false;
123 if ( $params[
'sort'] ==
'name' ) {
125 $disallowed = [
'start',
'end',
'user' ];
126 foreach ( $disallowed as $pname ) {
127 if ( isset( $params[$pname] ) ) {
130 'apierror-invalidparammix-mustusewith',
132 "{$prefix}sort=timestamp"
138 if ( $params[
'filterbots'] !=
'all' ) {
141 'apierror-invalidparammix-mustusewith',
142 "{$prefix}filterbots",
143 "{$prefix}sort=timestamp"
150 if ( $params[
'continue'] !==
null ) {
152 $op = $ascendingOrder ?
'>=' :
'<=';
153 $this->
addWhere( $db->expr(
'img_name', $op, $cont[0] ) );
159 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
161 if ( isset( $params[
'prefix'] ) ) {
172 $disallowed = [
'from',
'to',
'prefix' ];
173 foreach ( $disallowed as $pname ) {
174 if ( isset( $params[$pname] ) ) {
177 'apierror-invalidparammix-mustusewith',
185 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
189 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
196 $ascendingOrder ?
'newer' :
'older',
201 $this->
addWhereRange( $secondarySortField, $ascendingOrder ?
'newer' :
'older', null, null );
203 if ( $params[
'continue'] !==
null ) {
205 $op = ( $ascendingOrder ?
'>=' :
'<=' );
206 $this->
addWhere( $db->buildComparison( $op, [
207 'img_timestamp' => $db->timestamp( $cont[0] ),
208 $secondarySortField => $cont[1],
213 if ( $params[
'user'] !==
null ) {
214 if ( isset( $fileQuery[
'fields'][
'img_user_text'] ) ) {
215 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
218 $this->
addWhereFld(
'img_user_text', $params[
'user'] );
222 if ( $params[
'filterbots'] !=
'all' ) {
227 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
228 'ug_user = actor_user',
229 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
232 $groupCond =
$params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
233 $this->
addWhere(
"ug_group IS $groupCond" );
238 if ( isset( $params[
'minsize'] ) ) {
239 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
242 if ( isset( $params[
'maxsize'] ) ) {
243 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
247 if ( isset( $params[
'sha1'] ) ) {
248 $sha1 = strtolower( $params[
'sha1'] );
252 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
253 } elseif ( isset( $params[
'sha1base36'] ) ) {
254 $sha1 = strtolower( $params[
'sha1base36'] );
256 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
263 if ( $params[
'mime'] !==
null ) {
269 foreach ( $params[
'mime'] as $mime ) {
270 [ $major, $minor ] = File::splitMime( $mime );
272 $db->expr(
'img_major_mime',
'=', $major )
273 ->and(
'img_minor_mime',
'=', $minor );
275 if ( count( $mimeConds ) > 0 ) {
276 $this->
addWhere( $db->orExpr( $mimeConds ) );
287 $res = $this->
select( __METHOD__ );
292 foreach ( $res as $row ) {
293 if ( ++$count > $limit ) {
296 if ( $params[
'sort'] ==
'name' ) {
299 $secondaryValue = $row->$secondarySortField;
305 if ( $resultPageSet ===
null ) {
306 $file = $repo->newFileFromRow( $row );
308 [
'name' => $row->img_name ];
311 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
313 if ( $params[
'sort'] ==
'name' ) {
316 $secondaryValue = $row->$secondarySortField;
326 if ( $resultPageSet ===
null ) {
327 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
329 $resultPageSet->populateFromTitles( $titles );
337 ParamValidator::PARAM_DEFAULT =>
'name',
338 ParamValidator::PARAM_TYPE => [
344 ParamValidator::PARAM_DEFAULT =>
'ascending',
345 ParamValidator::PARAM_TYPE => [
360 ParamValidator::PARAM_TYPE =>
'timestamp'
363 ParamValidator::PARAM_TYPE =>
'timestamp'
367 ParamValidator::PARAM_DEFAULT =>
'timestamp|url',
368 ParamValidator::PARAM_ISMULTI =>
true,
375 ParamValidator::PARAM_TYPE =>
'integer',
378 ParamValidator::PARAM_TYPE =>
'integer',
381 'sha1base36' =>
null,
383 ParamValidator::PARAM_TYPE =>
'user',
384 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
387 ParamValidator::PARAM_DEFAULT =>
'all',
388 ParamValidator::PARAM_TYPE => [
395 ParamValidator::PARAM_ISMULTI =>
true,
398 ParamValidator::PARAM_DEFAULT => 10,
399 ParamValidator::PARAM_TYPE =>
'limit',
400 IntegerDef::PARAM_MIN => 1,
413 private const PROPERTY_FILTER = [
'archivename',
'thumbmime',
'uploadwarning' ];
418 'action=query&list=allimages&aifrom=B'
419 =>
'apihelp-query+allimages-example-b',
420 'action=query&list=allimages&aiprop=user|timestamp|url&' .
421 'aisort=timestamp&aidir=older'
422 =>
'apihelp-query+allimages-example-recent',
423 'action=query&list=allimages&aimime=image/png|image/gif'
424 =>
'apihelp-query+allimages-example-mimetypes',
425 'action=query&generator=allimages&gailimit=4&' .
426 'gaifrom=T&prop=imageinfo'
427 =>
'apihelp-query+allimages-example-generator',
433 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allimages';
438class_alias( ApiQueryAllImages::class,
'ApiQueryAllImages' );
const SCHEMA_COMPAT_READ_NEW
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()