49 parent::__construct( $query, $moduleName,
'ai' );
51 $this->groupPermissionsLookup = $groupPermissionsLookup;
62 return $this->mRepo->getReplicaDB();
79 if ( $resultPageSet->isResolvingRedirects() ) {
80 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
83 $this->run( $resultPageSet );
90 private function run( $resultPageSet =
null ) {
103 $prop = array_fill_keys( $params[
'prop'],
true );
106 $this->
addTables( $fileQuery[
'tables'] );
107 $this->
addFields( $fileQuery[
'fields'] );
110 $ascendingOrder =
true;
111 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
112 $ascendingOrder =
false;
115 if ( $params[
'sort'] ==
'name' ) {
117 $disallowed = [
'start',
'end',
'user' ];
118 foreach ( $disallowed as $pname ) {
119 if ( isset( $params[$pname] ) ) {
122 'apierror-invalidparammix-mustusewith',
124 "{$prefix}sort=timestamp"
130 if ( $params[
'filterbots'] !=
'all' ) {
133 'apierror-invalidparammix-mustusewith',
134 "{$prefix}filterbots",
135 "{$prefix}sort=timestamp"
142 if ( $params[
'continue'] !==
null ) {
144 $op = $ascendingOrder ?
'>=' :
'<=';
145 $this->
addWhere( $db->expr(
'img_name', $op, $cont[0] ) );
151 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
153 if ( isset( $params[
'prefix'] ) ) {
164 $disallowed = [
'from',
'to',
'prefix' ];
165 foreach ( $disallowed as $pname ) {
166 if ( isset( $params[$pname] ) ) {
169 'apierror-invalidparammix-mustusewith',
177 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
181 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
188 $ascendingOrder ?
'newer' :
'older',
193 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', null, null );
195 if ( $params[
'continue'] !==
null ) {
197 $op = ( $ascendingOrder ?
'>=' :
'<=' );
198 $this->
addWhere( $db->buildComparison( $op, [
199 'img_timestamp' => $db->timestamp( $cont[0] ),
200 'img_name' => $cont[1],
205 if ( $params[
'user'] !==
null ) {
206 if ( isset( $fileQuery[
'fields'][
'img_user_text'] ) ) {
207 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
210 $this->
addWhereFld(
'img_user_text', $params[
'user'] );
214 if ( $params[
'filterbots'] !=
'all' ) {
219 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
220 'ug_user = actor_user',
221 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
224 $groupCond =
$params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
225 $this->
addWhere(
"ug_group IS $groupCond" );
230 if ( isset( $params[
'minsize'] ) ) {
231 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
234 if ( isset( $params[
'maxsize'] ) ) {
235 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
239 if ( isset( $params[
'sha1'] ) ) {
240 $sha1 = strtolower( $params[
'sha1'] );
244 $sha1 = \Wikimedia\base_convert( $sha1, 16, 36, 31 );
245 } elseif ( isset( $params[
'sha1base36'] ) ) {
246 $sha1 = strtolower( $params[
'sha1base36'] );
248 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
255 if ( $params[
'mime'] !==
null ) {
261 foreach ( $params[
'mime'] as $mime ) {
262 [ $major, $minor ] = File::splitMime( $mime );
264 $db->expr(
'img_major_mime',
'=', $major )
265 ->and(
'img_minor_mime',
'=', $minor );
267 if ( count( $mimeConds ) > 0 ) {
268 $this->
addWhere( $db->orExpr( $mimeConds ) );
279 $res = $this->
select( __METHOD__ );
284 foreach ( $res as $row ) {
285 if ( ++$count > $limit ) {
288 if ( $params[
'sort'] ==
'name' ) {
296 if ( $resultPageSet ===
null ) {
297 $file = $repo->newFileFromRow( $row );
299 [
'name' => $row->img_name ];
302 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
304 if ( $params[
'sort'] ==
'name' ) {
316 if ( $resultPageSet ===
null ) {
317 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
319 $resultPageSet->populateFromTitles( $titles );
327 ParamValidator::PARAM_DEFAULT =>
'name',
328 ParamValidator::PARAM_TYPE => [
334 ParamValidator::PARAM_DEFAULT =>
'ascending',
335 ParamValidator::PARAM_TYPE => [
350 ParamValidator::PARAM_TYPE =>
'timestamp'
353 ParamValidator::PARAM_TYPE =>
'timestamp'
357 ParamValidator::PARAM_DEFAULT =>
'timestamp|url',
358 ParamValidator::PARAM_ISMULTI =>
true,
365 ParamValidator::PARAM_TYPE =>
'integer',
368 ParamValidator::PARAM_TYPE =>
'integer',
371 'sha1base36' =>
null,
373 ParamValidator::PARAM_TYPE =>
'user',
374 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
377 ParamValidator::PARAM_DEFAULT =>
'all',
378 ParamValidator::PARAM_TYPE => [
385 ParamValidator::PARAM_ISMULTI =>
true,
388 ParamValidator::PARAM_DEFAULT => 10,
389 ParamValidator::PARAM_TYPE =>
'limit',
390 IntegerDef::PARAM_MIN => 1,
403 private const PROPERTY_FILTER = [
'archivename',
'thumbmime',
'uploadwarning' ];
408 'action=query&list=allimages&aifrom=B'
409 =>
'apihelp-query+allimages-example-b',
410 'action=query&list=allimages&aiprop=user|timestamp|url&' .
411 'aisort=timestamp&aidir=older'
412 =>
'apihelp-query+allimages-example-recent',
413 'action=query&list=allimages&aimime=image/png|image/gif'
414 =>
'apihelp-query+allimages-example-mimetypes',
415 'action=query&generator=allimages&gailimit=4&' .
416 'gaifrom=T&prop=imageinfo'
417 =>
'apihelp-query+allimages-example-generator',
423 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allimages';
428class_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()