63 parent::__construct( $query, $moduleName,
'ai' );
65 $this->groupPermissionsLookup = $groupPermissionsLookup;
76 return $this->mRepo->getReplicaDB();
92 if ( $resultPageSet->isResolvingRedirects() ) {
93 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
96 $this->run( $resultPageSet );
103 private function run( $resultPageSet =
null ) {
111 $db = $this->
getDB();
116 $prop = array_fill_keys( $params[
'prop'],
true );
119 $this->
addTables( $fileQuery[
'tables'] );
120 $this->
addFields( $fileQuery[
'fields'] );
123 $ascendingOrder =
true;
124 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
125 $ascendingOrder =
false;
128 if ( $params[
'sort'] ==
'name' ) {
130 $disallowed = [
'start',
'end',
'user' ];
131 foreach ( $disallowed as $pname ) {
132 if ( isset( $params[$pname] ) ) {
135 'apierror-invalidparammix-mustusewith',
137 "{$prefix}sort=timestamp"
143 if ( $params[
'filterbots'] !=
'all' ) {
146 'apierror-invalidparammix-mustusewith',
147 "{$prefix}filterbots",
148 "{$prefix}sort=timestamp"
155 if ( $params[
'continue'] !==
null ) {
157 $op = $ascendingOrder ?
'>=' :
'<=';
158 $this->
addWhere( $db->expr(
'img_name', $op, $cont[0] ) );
164 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
166 if ( isset( $params[
'prefix'] ) ) {
177 $disallowed = [
'from',
'to',
'prefix' ];
178 foreach ( $disallowed as $pname ) {
179 if ( isset( $params[$pname] ) ) {
182 'apierror-invalidparammix-mustusewith',
190 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
194 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
201 $ascendingOrder ?
'newer' :
'older',
206 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', null, null );
208 if ( $params[
'continue'] !==
null ) {
210 $op = ( $ascendingOrder ?
'>=' :
'<=' );
211 $this->
addWhere( $db->buildComparison( $op, [
212 'img_timestamp' => $db->timestamp( $cont[0] ),
213 'img_name' => $cont[1],
218 if ( $params[
'user'] !==
null ) {
219 if ( isset( $fileQuery[
'fields'][
'img_user_text'] ) ) {
220 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
223 $this->
addWhereFld(
'img_user_text', $params[
'user'] );
227 if ( $params[
'filterbots'] !=
'all' ) {
232 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
233 'ug_user = actor_user',
234 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
237 $groupCond =
$params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
238 $this->
addWhere(
"ug_group IS $groupCond" );
243 if ( isset( $params[
'minsize'] ) ) {
244 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
247 if ( isset( $params[
'maxsize'] ) ) {
248 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
252 if ( isset( $params[
'sha1'] ) ) {
253 $sha1 = strtolower( $params[
'sha1'] );
257 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
258 } elseif ( isset( $params[
'sha1base36'] ) ) {
259 $sha1 = strtolower( $params[
'sha1base36'] );
261 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
268 if ( $params[
'mime'] !==
null ) {
274 foreach ( $params[
'mime'] as $mime ) {
275 [ $major, $minor ] = File::splitMime( $mime );
277 $db->expr(
'img_major_mime',
'=', $major )
278 ->and(
'img_minor_mime',
'=', $minor );
280 if ( count( $mimeConds ) > 0 ) {
281 $this->
addWhere( $db->orExpr( $mimeConds ) );
292 $res = $this->
select( __METHOD__ );
297 foreach ( $res as $row ) {
298 if ( ++$count > $limit ) {
301 if ( $params[
'sort'] ==
'name' ) {
309 if ( $resultPageSet ===
null ) {
310 $file = $repo->newFileFromRow( $row );
311 $info = array_merge( [
'name' => $row->img_name ],
315 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
317 if ( $params[
'sort'] ==
'name' ) {
325 $titles[] = Title::makeTitle(
NS_FILE, $row->img_name );
329 if ( $resultPageSet ===
null ) {
330 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
332 $resultPageSet->populateFromTitles( $titles );
339 ParamValidator::PARAM_DEFAULT =>
'name',
340 ParamValidator::PARAM_TYPE => [
346 ParamValidator::PARAM_DEFAULT =>
'ascending',
347 ParamValidator::PARAM_TYPE => [
362 ParamValidator::PARAM_TYPE =>
'timestamp'
365 ParamValidator::PARAM_TYPE =>
'timestamp'
369 ParamValidator::PARAM_DEFAULT =>
'timestamp|url',
370 ParamValidator::PARAM_ISMULTI =>
true,
377 ParamValidator::PARAM_TYPE =>
'integer',
380 ParamValidator::PARAM_TYPE =>
'integer',
383 'sha1base36' =>
null,
385 ParamValidator::PARAM_TYPE =>
'user',
386 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
389 ParamValidator::PARAM_DEFAULT =>
'all',
390 ParamValidator::PARAM_TYPE => [
397 ParamValidator::PARAM_ISMULTI =>
true,
400 ParamValidator::PARAM_DEFAULT => 10,
401 ParamValidator::PARAM_TYPE =>
'limit',
402 IntegerDef::PARAM_MIN => 1,
415 private const PROPERTY_FILTER = [
'archivename',
'thumbmime',
'uploadwarning' ];
419 'action=query&list=allimages&aifrom=B'
420 =>
'apihelp-query+allimages-example-b',
421 'action=query&list=allimages&aiprop=user|timestamp|url&' .
422 'aisort=timestamp&aidir=older'
423 =>
'apihelp-query+allimages-example-recent',
424 'action=query&list=allimages&aimime=image/png|image/gif'
425 =>
'apihelp-query+allimages-example-mimetypes',
426 'action=query&generator=allimages&gailimit=4&' .
427 'gaifrom=T&prop=imageinfo'
428 =>
'apihelp-query+allimages-example-generator',
433 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allimages';
438class_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()