58 parent::__construct( $query, $moduleName,
'ai' );
71 return $this->mRepo->getReplicaDB();
87 if ( $resultPageSet->isResolvingRedirects() ) {
88 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
91 $this->
run( $resultPageSet );
98 private function run( $resultPageSet =
null ) {
106 $db = $this->
getDB();
111 $prop = array_fill_keys( $params[
'prop'],
true );
113 $fileQuery = LocalFile::getQueryInfo();
114 $this->
addTables( $fileQuery[
'tables'] );
115 $this->
addFields( $fileQuery[
'fields'] );
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 ) {
151 $cont = explode(
'|', $params[
'continue'] );
153 $op = $ascendingOrder ?
'>' :
'<';
154 $continueFrom = $db->addQuotes( $cont[0] );
155 $this->
addWhere(
"img_name $op= $continueFrom" );
161 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
163 if ( isset( $params[
'prefix'] ) ) {
164 $this->
addWhere(
'img_name' . $db->buildLike(
165 $this->titlePartToKey( $params[
'prefix'],
NS_FILE ),
166 $db->anyString() ) );
170 $disallowed = [
'from',
'to',
'prefix' ];
171 foreach ( $disallowed as $pname ) {
172 if ( isset( $params[$pname] ) ) {
175 'apierror-invalidparammix-mustusewith',
183 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
187 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
194 $ascendingOrder ?
'newer' :
'older',
199 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older',
null, null );
201 if ( $params[
'continue'] !==
null ) {
202 $cont = explode(
'|', $params[
'continue'] );
204 $op = ( $ascendingOrder ?
'>' :
'<' );
205 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
206 $continueName = $db->addQuotes( $cont[1] );
207 $this->
addWhere(
"img_timestamp $op $continueTimestamp OR " .
208 "(img_timestamp = $continueTimestamp AND " .
209 "img_name $op= $continueName)"
214 if ( $params[
'user'] !==
null ) {
215 $this->
addWhereFld( $fileQuery[
'fields'][
'img_user_text'], $params[
'user'] );
217 if ( $params[
'filterbots'] !=
'all' ) {
222 'ug_group' => $this->groupPermissionsLookup->getGroupsWithPermission(
'bot' ),
223 'ug_user = actor_user',
224 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
227 $groupCond = $params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
228 $this->
addWhere(
"ug_group IS $groupCond" );
233 if ( isset( $params[
'minsize'] ) ) {
234 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
237 if ( isset( $params[
'maxsize'] ) ) {
238 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
242 if ( isset( $params[
'sha1'] ) ) {
243 $sha1 = strtolower( $params[
'sha1'] );
247 $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
248 } elseif ( isset( $params[
'sha1base36'] ) ) {
249 $sha1 = strtolower( $params[
'sha1base36'] );
251 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
258 if ( $params[
'mime'] !==
null ) {
259 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
264 foreach ( $params[
'mime'] as
$mime ) {
265 list( $major, $minor ) = File::splitMime(
$mime );
266 $mimeConds[] = $db->makeList(
268 'img_major_mime' => $major,
269 'img_minor_mime' => $minor,
275 if ( count( $mimeConds ) > 0 ) {
284 $limit = $params[
'limit'];
287 if ( !$ascendingOrder ) {
290 if ( $params[
'sort'] ==
'timestamp' ) {
291 $this->
addOption(
'ORDER BY',
'img_timestamp' . $sortFlag );
293 $this->
addOption(
'ORDER BY',
'img_name' . $sortFlag );
301 foreach (
$res as $row ) {
302 if ( ++$count > $limit ) {
305 if ( $params[
'sort'] ==
'name' ) {
313 if ( $resultPageSet ===
null ) {
314 $file = $repo->newFileFromRow( $row );
315 $info = array_merge( [
'name' => $row->img_name ],
319 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
321 if ( $params[
'sort'] ==
'name' ) {
329 $titles[] = Title::makeTitle(
NS_FILE, $row->img_name );
333 if ( $resultPageSet ===
null ) {
334 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
336 $resultPageSet->populateFromTitles( $titles );
387 'sha1base36' =>
null,
390 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
412 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
423 'action=query&list=allimages&aifrom=B'
424 =>
'apihelp-query+allimages-example-b',
425 'action=query&list=allimages&aiprop=user|timestamp|url&' .
426 'aisort=timestamp&aidir=older'
427 =>
'apihelp-query+allimages-example-recent',
428 'action=query&list=allimages&aimime=image/png|image/gif'
429 =>
'apihelp-query+allimages-example-mimetypes',
430 'action=query&generator=allimages&gailimit=4&' .
431 'gaifrom=T&prop=imageinfo'
432 =>
'apihelp-query+allimages-example-generator',
437 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 available pages.
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)
GroupPermissionsLookup $groupPermissionsLookup
getHelpUrls()
Return links to more detailed help pages about the module.
run( $resultPageSet=null)
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.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Prioritized list of file repositories.
getLocalRepo()
Get the local repository, i.e.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.