40 parent::__construct( $query, $moduleName,
'ai' );
41 $this->mRepo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
52 return $this->mRepo->getReplicaDB();
68 if ( $resultPageSet->isResolvingRedirects() ) {
69 $this->
dieWithError(
'apierror-allimages-redirect',
'invalidparammix' );
72 $this->
run( $resultPageSet );
79 private function run( $resultPageSet =
null ) {
92 $prop = array_flip( $params[
'prop'] );
94 $fileQuery = LocalFile::getQueryInfo();
99 $ascendingOrder =
true;
100 if ( $params[
'dir'] ==
'descending' || $params[
'dir'] ==
'older' ) {
101 $ascendingOrder =
false;
104 if ( $params[
'sort'] ==
'name' ) {
106 $disallowed = [
'start',
'end',
'user' ];
107 foreach ( $disallowed as $pname ) {
108 if ( isset( $params[$pname] ) ) {
111 'apierror-invalidparammix-mustusewith',
113 "{$prefix}sort=timestamp"
119 if ( $params[
'filterbots'] !=
'all' ) {
122 'apierror-invalidparammix-mustusewith',
123 "{$prefix}filterbots",
124 "{$prefix}sort=timestamp"
131 if ( $params[
'continue'] !==
null ) {
132 $cont = explode(
'|', $params[
'continue'] );
134 $op = $ascendingOrder ?
'>' :
'<';
135 $continueFrom = $db->addQuotes( $cont[0] );
136 $this->
addWhere(
"img_name $op= $continueFrom" );
142 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older', $from, $to );
144 if ( isset( $params[
'prefix'] ) ) {
145 $this->
addWhere(
'img_name' . $db->buildLike(
146 $this->titlePartToKey( $params[
'prefix'],
NS_FILE ),
147 $db->anyString() ) );
151 $disallowed = [
'from',
'to',
'prefix' ];
152 foreach ( $disallowed as $pname ) {
153 if ( isset( $params[$pname] ) ) {
156 'apierror-invalidparammix-mustusewith',
164 if ( $params[
'user'] !==
null && $params[
'filterbots'] !=
'all' ) {
168 [
'apierror-invalidparammix-cannotusewith',
"{$prefix}user",
"{$prefix}filterbots" ]
175 $ascendingOrder ?
'newer' :
'older',
180 $this->
addWhereRange(
'img_name', $ascendingOrder ?
'newer' :
'older',
null, null );
182 if ( $params[
'continue'] !==
null ) {
183 $cont = explode(
'|', $params[
'continue'] );
185 $op = ( $ascendingOrder ?
'>' :
'<' );
186 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
187 $continueName = $db->addQuotes( $cont[1] );
188 $this->
addWhere(
"img_timestamp $op $continueTimestamp OR " .
189 "(img_timestamp = $continueTimestamp AND " .
190 "img_name $op= $continueName)"
195 if ( $params[
'user'] !==
null ) {
196 $actorQuery = ActorMigration::newMigration()
197 ->getWhere( $db,
'img_user', $params[
'user'] );
198 $this->
addTables( $actorQuery[
'tables'] );
200 $this->
addWhere( $actorQuery[
'conds'] );
202 if ( $params[
'filterbots'] !=
'all' ) {
203 $actorQuery = ActorMigration::newMigration()->getJoin(
'img_user' );
204 $this->
addTables( $actorQuery[
'tables'] );
211 'ug_user = ' . $actorQuery[
'fields'][
'img_user'],
212 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
215 $groupCond = $params[
'filterbots'] ==
'nobots' ?
'NULL' :
'NOT NULL';
216 $this->
addWhere(
"ug_group IS $groupCond" );
221 if ( isset( $params[
'minsize'] ) ) {
222 $this->
addWhere(
'img_size>=' . (
int)$params[
'minsize'] );
225 if ( isset( $params[
'maxsize'] ) ) {
226 $this->
addWhere(
'img_size<=' . (
int)$params[
'maxsize'] );
230 if ( isset( $params[
'sha1'] ) ) {
231 $sha1 = strtolower( $params[
'sha1'] );
235 $sha1 = Wikimedia\base_convert( $sha1, 16, 36, 31 );
236 } elseif ( isset( $params[
'sha1base36'] ) ) {
237 $sha1 = strtolower( $params[
'sha1base36'] );
239 $this->
dieWithError(
'apierror-invalidsha1base36hash' );
246 if ( $params[
'mime'] !==
null ) {
247 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
252 foreach ( $params[
'mime'] as
$mime ) {
253 list( $major, $minor ) = File::splitMime(
$mime );
254 $mimeConds[] = $db->makeList(
256 'img_major_mime' => $major,
257 'img_minor_mime' => $minor,
263 if ( count( $mimeConds ) > 0 ) {
272 $limit = $params[
'limit'];
275 if ( !$ascendingOrder ) {
278 if ( $params[
'sort'] ==
'timestamp' ) {
279 $this->
addOption(
'ORDER BY',
'img_timestamp' . $sortFlag );
281 $this->
addOption(
'ORDER BY',
'img_name' . $sortFlag );
289 foreach (
$res as $row ) {
290 if ( ++$count > $limit ) {
293 if ( $params[
'sort'] ==
'name' ) {
301 if ( $resultPageSet ===
null ) {
302 $file = $repo->newFileFromRow( $row );
303 $info = array_merge( [
'name' => $row->img_name ],
307 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $info );
309 if ( $params[
'sort'] ==
'name' ) {
317 $titles[] = Title::makeTitle(
NS_FILE, $row->img_name );
321 if ( $resultPageSet ===
null ) {
322 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'img' );
324 $resultPageSet->populateFromTitles( $titles );
375 'sha1base36' =>
null,
378 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
379 UserDef::PARAM_RETURN_OBJECT =>
true,
401 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
412 'action=query&list=allimages&aifrom=B'
413 =>
'apihelp-query+allimages-example-b',
414 'action=query&list=allimages&aiprop=user|timestamp|url&' .
415 'aisort=timestamp&aidir=older'
416 =>
'apihelp-query+allimages-example-recent',
417 'action=query&list=allimages&aimime=image/png|image/gif'
418 =>
'apihelp-query+allimages-example-mimetypes',
419 'action=query&generator=allimages&gailimit=4&' .
420 'gaifrom=T&prop=imageinfo'
421 =>
'apihelp-query+allimages-example-generator',
426 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.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
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)
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.