API:Query

The   module allows you to fetch information about a wiki and the data stored in it, such as the wikitext of a particular page, the links and categories of a set of pages, or the token you need to.

Query modules
The query module has three types of submodules (also called query modules):


 * about the wiki and the logged-in user.


 * of pages, including page revisions and content.


 * of pages that match certain criteria.

Example 1: Specifying pages
Unlike meta and list query modules, all property query modules work on a set of pages that can be specified in one of the following ways:


 * By name using the   parameter, e.g.  .


 * By page ID using the   parameter, e.g.  .


 * By revision ID using the   parameter, e.g.  . Most query modules will convert revision ID to the corresponding page ID.  Only  actually uses the revision ID itself.


 * Using a 1>#Generators</>|generator.

Example 2: Title normalization
Title normalization converts page titles to their canonical form.

This means capitalizing the first character, replacing underscores with spaces, and changing namespace to the localized form defined for that wiki.

Example 3: Missing and invalid titles
Titles that don't exist or are invalid will have a <tvar|1> </> or <tvar|2> </> attribute set in the response.

In output formats that support numeric array keys, missing and invalid titles will have negative page IDs.

Example 4: Continuing queries
When all the data is not returned in the response of a query, there will be a <tvar|1> </> attribute to indicate that there is more data.

To get further data, add its values to the original request.

Example 5: Batchcomplete
The API returns a <tvar|1> </> element to indicate that all data for the current batch of items has been returned.

In the response of the sample query below, <tvar|1> </> has been included to indicate that all the data for each of the three images has been returned.

The next continuation will begin returning data for the next set of 3 images.

Example 6: Generators
Use generators if you want to get data about a set of pages.

For example, to get data about pages in a certain category, instead of querying <tvar|1> </> and then querying again with <tvar|2> </> set to all the returned pages, combine the two API calls into one by using <tvar|3> </>.

When using a list module as a generator, you don't need to specify the pages.

However, for a property module, you should 1>#Specifying pages</>|specify the pages which the generator will work on.

For example, to load all pages that are linked to from the main page, use <tvar|1> </>.

Parameters passed to a generator must be prefixed with a. For instance, when using, use   instead of.

The sample query below gets links and categories for the first three pages in the main namespace starting with "Ba".

Parameter history

 * v1.21: Introduced <tvar|1> </>
 * v1.24: Introduced <tvar|1> </> (note raw continuation was the default behavior until v1.26)

Additional notes

 * Specifying titles through <tvar|1> </> or <tvar|2> </> is limited to 50 titles per query, or 500 for those with the <tvar|3> </> right.
 * Use multiple query modules together to get what you need in one request, e.g. <tvar|1> </>.
 * Generators always pass page titles to the query module. Unlike lists (which may include additional data by default), generators should not output any information themselves, unless when explicitly requested via the generator module's query parameters.

Resolving redirects
Redirects can be resolved automatically, so that the target of a redirect is returned instead of the given title. When present, they will always contain <tvar|1> </> and <tvar|2> </> attributes and may contain a <tvar|3> </> attribute for those redirects that point to specific sections.

Both normalization and redirection may take place. In the case of multiple redirects, all redirects will be resolved, and in case of a circular redirect, there might not be a page in the 'pages' section (see also 1>#Circular redirects</>|below). Redirect resolution cannot be used in combination with the <tvar|1> </> parameter or with a generator generating revids; doing that will produce a 2>#Possible warnings</>|warning and will not resolve redirects for the specified revids.

The examples below show how the <tvar|1> </> parameter works.