47 private $groupPermissionsLookup;
61 parent::__construct( $query, $moduleName,
'ai' );
63 $this->groupPermissionsLookup = $groupPermissionsLookup;
74 return $this->mRepo->getReplicaDB();
90 if ( $resultPageSet->isResolvingRedirects() ) {
91 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
94 $this->run( $resultPageSet );
101 private function run( $resultPageSet =
null ) {
109 $db = $this->
getDB();
114 $prop = array_fill_keys( $params[
'prop'],
true );
117 $this->
addTables( $fileQuery[
'tables'] );
118 $this->
addFields( $fileQuery[
'fields'] );
121 $ascendingOrder =
true;
122 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
123 $ascendingOrder =
false;
126 if ( $params[
'sort'] ==
'name' ) {
128 $disallowed = [
'start',
'end',
'user' ];
129 foreach ( $disallowed as $pname ) {
130 if ( isset( $params[$pname] ) ) {
133 'apierror-invalidparammix-mustusewith',
135 "{$prefix}sort=timestamp"
141 if ( $params[
'filterbots'] !=
'all' ) {
144 'apierror-invalidparammix-mustusewith',
145 "{$prefix}filterbots",
146 "{$prefix}sort=timestamp"
153 if ( $params[
'continue'] !==
null ) {
154 $cont = explode(
'|', $params[
'continue'] );
156 $op = $ascendingOrder ?
'>' :
'<';
157 $continueFrom = $db->addQuotes( $cont[0] );
158 $this->
addWhere(
"img_name $op= $continueFrom" );
164 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
166 if ( isset( $params[
'prefix'] ) ) {
167 $this->
addWhere(
'img_name' . $db->buildLike(
168 $this->titlePartToKey( $params[
'prefix'],
NS_FILE ),
169 $db->anyString() ) );
173 $disallowed = [
'from',
'to',
'prefix' ];
174 foreach ( $disallowed as $pname ) {
175 if ( isset( $params[$pname] ) ) {
178 'apierror-invalidparammix-mustusewith',
186 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
190 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
197 $ascendingOrder ?
'newer' :
'older',
202 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', null, null );
204 if ( $params[
'continue'] !==
null ) {
205 $cont = explode(
'|', $params[
'continue'] );
207 $op = ( $ascendingOrder ?
'>' :
'<' );
208 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
209 $continueName = $db->addQuotes( $cont[1] );
210 $this->
addWhere(
"img_timestamp $op $continueTimestamp OR " .
211 "(img_timestamp = $continueTimestamp AND " .
212 "img_name $op= $continueName)"
217 if ( $params[
'user'] !==
null ) {
218 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
220 if ( $params[
'filterbots'] !=
'all' ) {
225 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
226 'ug_user = actor_user',
227 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
230 $groupCond = $params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
231 $this->
addWhere(
"ug_group IS $groupCond" );
236 if ( isset( $params[
'minsize'] ) ) {
237 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
240 if ( isset( $params[
'maxsize'] ) ) {
241 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
245 if ( isset( $params[
'sha1'] ) ) {
246 $sha1 = strtolower( $params[
'sha1'] );
250 $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
251 } elseif ( isset( $params[
'sha1base36'] ) ) {
252 $sha1 = strtolower( $params[
'sha1base36'] );
254 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
261 if ( $params[
'mime'] !==
null ) {
262 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
267 foreach ( $params[
'mime'] as
$mime ) {
269 $mimeConds[] = $db->makeList(
271 'img_major_mime' => $major,
272 'img_minor_mime' => $minor,
278 if ( count( $mimeConds ) > 0 ) {
287 $limit = $params[
'limit'];
290 if ( !$ascendingOrder ) {
293 if ( $params[
'sort'] ==
'timestamp' ) {
294 $this->
addOption(
'ORDER BY',
'img_timestamp' . $sortFlag );
296 $this->
addOption(
'ORDER BY',
'img_name' . $sortFlag );
304 foreach (
$res as $row ) {
305 if ( ++$count > $limit ) {
308 if ( $params[
'sort'] ==
'name' ) {
316 if ( $resultPageSet ===
null ) {
317 $file = $repo->newFileFromRow( $row );
318 $info = array_merge( [
'name' => $row->img_name ],
322 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
324 if ( $params[
'sort'] ==
'name' ) {
336 if ( $resultPageSet ===
null ) {
337 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
339 $resultPageSet->populateFromTitles( $titles );
346 ParamValidator::PARAM_DEFAULT =>
'name',
347 ParamValidator::PARAM_TYPE => [
353 ParamValidator::PARAM_DEFAULT =>
'ascending',
354 ParamValidator::PARAM_TYPE => [
369 ParamValidator::PARAM_TYPE =>
'timestamp'
372 ParamValidator::PARAM_TYPE =>
'timestamp'
376 ParamValidator::PARAM_DEFAULT =>
'timestamp|url',
377 ParamValidator::PARAM_ISMULTI =>
true,
384 ParamValidator::PARAM_TYPE =>
'integer',
387 ParamValidator::PARAM_TYPE =>
'integer',
390 'sha1base36' =>
null,
392 ParamValidator::PARAM_TYPE =>
'user',
393 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
396 ParamValidator::PARAM_DEFAULT =>
'all',
397 ParamValidator::PARAM_TYPE => [
404 ParamValidator::PARAM_ISMULTI =>
true,
407 ParamValidator::PARAM_DEFAULT => 10,
408 ParamValidator::PARAM_TYPE =>
'limit',
409 IntegerDef::PARAM_MIN => 1,
415 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
422 private $propertyFilter = [
'archivename',
'thumbmime',
'uploadwarning' ];
426 'action=query&list=allimages&aifrom=B'
427 =>
'apihelp-query+allimages-example-b',
428 'action=query&list=allimages&aiprop=user|timestamp|url&' .
429 'aisort=timestamp&aidir=older'
430 =>
'apihelp-query+allimages-example-recent',
431 'action=query&list=allimages&aimime=image/png|image/gif'
432 =>
'apihelp-query+allimages-example-mimetypes',
433 'action=query&generator=allimages&gailimit=4&' .
434 'gaifrom=T&prop=imageinfo'
435 =>
'apihelp-query+allimages-example-generator',
440 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Allimages';
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
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.
Query module to enumerate all images.
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getDB()
Override parent method to make sure the repo's DB is used which may not necessarily be the same as th...
executeGenerator( $resultPageSet)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, RepoGroup $repoGroup, GroupPermissionsLookup $groupPermissionsLookup)
getHelpUrls()
Return links to more detailed help pages about the module.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
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.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
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.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
This is the main query class.
static splitMime(?string $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Local repository that stores files in the local filesystem and registers them in the wiki's own datab...
A class containing constants representing the names of configuration variables.
Prioritized list of file repositories.
getLocalRepo()
Get the local repository, i.e.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.