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 );
103 $this->
addTables( $fileQuery[
'tables'] );
104 $this->
addFields( $fileQuery[
'fields'] );
107 $ascendingOrder =
true;
108 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
109 $ascendingOrder =
false;
112 if ( $params[
'sort'] ==
'name' ) {
114 $disallowed = [
'start',
'end',
'user' ];
115 foreach ( $disallowed as $pname ) {
116 if ( isset( $params[$pname] ) ) {
119 'apierror-invalidparammix-mustusewith',
121 "{$prefix}sort=timestamp"
127 if ( $params[
'filterbots'] !=
'all' ) {
130 'apierror-invalidparammix-mustusewith',
131 "{$prefix}filterbots",
132 "{$prefix}sort=timestamp"
139 if ( $params[
'continue'] !==
null ) {
141 $op = $ascendingOrder ?
'>=' :
'<=';
142 $this->
addWhere( $db->expr(
'img_name', $op, $cont[0] ) );
148 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
150 if ( isset( $params[
'prefix'] ) ) {
161 $disallowed = [
'from',
'to',
'prefix' ];
162 foreach ( $disallowed as $pname ) {
163 if ( isset( $params[$pname] ) ) {
166 'apierror-invalidparammix-mustusewith',
174 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
178 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
185 $ascendingOrder ?
'newer' :
'older',
190 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', null, null );
192 if ( $params[
'continue'] !==
null ) {
194 $op = ( $ascendingOrder ?
'>=' :
'<=' );
195 $this->
addWhere( $db->buildComparison( $op, [
196 'img_timestamp' => $db->timestamp( $cont[0] ),
197 'img_name' => $cont[1],
202 if ( $params[
'user'] !==
null ) {
203 if ( isset( $fileQuery[
'fields'][
'img_user_text'] ) ) {
204 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
207 $this->
addWhereFld(
'img_user_text', $params[
'user'] );
211 if ( $params[
'filterbots'] !=
'all' ) {
216 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
217 'ug_user = actor_user',
218 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
221 $groupCond =
$params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
222 $this->
addWhere(
"ug_group IS $groupCond" );
227 if ( isset( $params[
'minsize'] ) ) {
228 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
231 if ( isset( $params[
'maxsize'] ) ) {
232 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
236 if ( isset( $params[
'sha1'] ) ) {
237 $sha1 = strtolower( $params[
'sha1'] );
241 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
242 } elseif ( isset( $params[
'sha1base36'] ) ) {
243 $sha1 = strtolower( $params[
'sha1base36'] );
245 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
252 if ( $params[
'mime'] !==
null ) {
258 foreach ( $params[
'mime'] as $mime ) {
259 [ $major, $minor ] = File::splitMime( $mime );
261 $db->expr(
'img_major_mime',
'=', $major )
262 ->and(
'img_minor_mime',
'=', $minor );
264 if ( count( $mimeConds ) > 0 ) {
265 $this->
addWhere( $db->orExpr( $mimeConds ) );
276 $res = $this->
select( __METHOD__ );
281 foreach ( $res as $row ) {
282 if ( ++$count > $limit ) {
285 if ( $params[
'sort'] ==
'name' ) {
293 if ( $resultPageSet ===
null ) {
294 $file = $repo->newFileFromRow( $row );
296 [
'name' => $row->img_name ];
299 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
301 if ( $params[
'sort'] ==
'name' ) {
313 if ( $resultPageSet ===
null ) {
314 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
316 $resultPageSet->populateFromTitles( $titles );
324 ParamValidator::PARAM_DEFAULT =>
'name',
325 ParamValidator::PARAM_TYPE => [
331 ParamValidator::PARAM_DEFAULT =>
'ascending',
332 ParamValidator::PARAM_TYPE => [
347 ParamValidator::PARAM_TYPE =>
'timestamp'
350 ParamValidator::PARAM_TYPE =>
'timestamp'
354 ParamValidator::PARAM_DEFAULT =>
'timestamp|url',
355 ParamValidator::PARAM_ISMULTI =>
true,
362 ParamValidator::PARAM_TYPE =>
'integer',
365 ParamValidator::PARAM_TYPE =>
'integer',
368 'sha1base36' =>
null,
370 ParamValidator::PARAM_TYPE =>
'user',
371 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
374 ParamValidator::PARAM_DEFAULT =>
'all',
375 ParamValidator::PARAM_TYPE => [
382 ParamValidator::PARAM_ISMULTI =>
true,
385 ParamValidator::PARAM_DEFAULT => 10,
386 ParamValidator::PARAM_TYPE =>
'limit',
387 IntegerDef::PARAM_MIN => 1,
400 private const PROPERTY_FILTER = [
'archivename',
'thumbmime',
'uploadwarning' ];
405 'action=query&list=allimages&aifrom=B'
406 =>
'apihelp-query+allimages-example-b',
407 'action=query&list=allimages&aiprop=user|timestamp|url&' .
408 'aisort=timestamp&aidir=older'
409 =>
'apihelp-query+allimages-example-recent',
410 'action=query&list=allimages&aimime=image/png|image/gif'
411 =>
'apihelp-query+allimages-example-mimetypes',
412 'action=query&generator=allimages&gailimit=4&' .
413 'gaifrom=T&prop=imageinfo'
414 =>
'apihelp-query+allimages-example-generator',
420 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allimages';
425class_alias( ApiQueryAllImages::class,
'ApiQueryAllImages' );
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()