Query

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Patrick (talk | contribs) at 09:35, 8 August 2006 (→‎Examples). It may differ significantly from the current version.

Query.php is a read-only method for accessing various metadata about Wiki pages. What follows is derived from http://en.wikipedia.org/w/query.php , see that page for up-to-date info.

Summary

This API provides a way for your applications to query data directly from the MediaWiki servers. One or more pieces of information about the site and/or a given list of pages can be retrieved. Information may be returned in either a machine (xml, json, php, wddx) or a human readable format. More than one piece of information may be requested with a single query.

Usage

query.php ? format=... & what=...|...|... & titles=...|...|... & ...

Common parameters

  • format - How should the output be formatted. See formats section below.
  • what - What information the server should return. See the list of available properties below.
  • More than one property may be requested at the same time, separated by pipe '|' symbol.
  • titles - A list of titles, separated by the pipe '|' symbol.
  • pageids - A list of page ids, separated by the pipe '|' symbol.
  • revids - List of revision ids, separated by '|' symbol. See 'revisions' property for additional information.
  • noprofile - When present, each sql query execution time will be hidden.
  • proxysite - Access alternative site (wikipedia/wikinews/wikiquote/...)
  • proxylang - Access alternative language (en/ru/he/commons/...)
    • Note: proxying is a security workaround for the browser-based scripts. Avoid using it if you can.
  • User is treated as anonymous, and only sites/languages hosted at the same cluster are accessible.

Examples

//meta.wikimedia.org/w/query.php?what=links|templates&titles=User:Yurik This query will return a list of all links and templates used on the page User:Yurik

//meta.wikimedia.org/w/query.php?what=revisions&titles=Main_Page&rvlimit=100&rvstart=20060401000000&rvcomments Get a list of 100 last revisions of the main page with comments, but only if it happened after midnight April 1st 2006

//meta.wikimedia.org/w/query.php?what=revisions&revids=1&rvcomments Get revision 1 with some of its properties

Notes

Some queries marked with *slow query* are known to be database intensive. Please optimize their use. Some properties may add status information to the <query> element. For example, query.php?what=allpages&aplimit=3 will set an element <query>/<allpages next='B'> to the next available value. For the next request, set '__from' to that value to continue paging: query.php?what=allpages&aplimit=3&apfrom=B In addition, <query> element has performance time (in ms) for both database and total processing to allow request optimization.

Supported properties

Properties of the entire site

info - General site information

Example: http://meta.wikimedia.org/w/query.php?what=info

namespaces - List of localized namespace names

Example: http://meta.wikimedia.org/w/query.php?what=namespaces

userinfo - Information about current user.

The information will always include 'name' element, and optionally 'anonymous' or 'bot' flags.
Parameters supported:
uiisblocked- If present, and current user or IP is blocked, a 'blocked' flag will be added.
uihasmsg - If present, and current user or IP has messages waiting, a 'messages' flag will be added.
uiextended - If present, includes additional information such as rights and groups.
uioptions - A list of user preference options to get, separated by '|'. For the complete list see User.php source file.
Example: http://meta.wikimedia.org/w/query.php?what=userinfo&uiisblocked&uihasmsg&uiextended
http://meta.wikimedia.org/w/query.php?what=userinfo&uioptions=timecorrection%7Cskin -- get user's timezone and chosen skin

recentchanges - Adds recently changed articles to the output list.

Parameters supported:
rcfrom - Timestamp of the first entry to start from. The list order reverses.
rclimit - How many total links to return.
Smaller size is possible if pages changes multiple times.
rchide - Which entries to ignore 'minor', 'bots', 'anons', 'liu' (loged-in users).
Cannot specify both anons and liu.
Example: http://meta.wikimedia.org/w/query.php?what=recentchanges&rchide=liu%7Cbots

allpages - Enumerates all available pages to the output list.

Parameters supported:
aplimit - How many total pages to return
apfrom - The page title to start enumerating from.
apnamespace - Limits which namespace to enumerate. Default 0 (Main)
apfilterredir- Which pages to list: 'all' (default), 'redirects', or 'nonredirects'
Example: http://meta.wikimedia.org/w/query.php?what=allpages&aplimit=50 (first 50 pages)
query.php?what=allpages&aplimit=20&apnamespace=10&apfrom=C&apfilterredir=nonredirects
(20 templates starting with 'C' that are not redirects)

nolanglinks - Enumerates pages without language links to the output list (automatically filters out redirects).

Parameters supported:
nllimit - How many total pages to return
nlfrom - The page title to start enumerating from.
nlnamespace - Limits which namespace to enumerate. Default 0 (Main)
Example: http://meta.wikimedia.org/w/query.php?what=nolanglinks&nllimit=10&nlfrom=A

category - Adds pages in a given category to the output list.

Parameters supported:
cptitle - A category name, either with or without the 'Category:' prefix.
cplimit - How many total pages (in category) to return.
cpfrom - The category sort key to continue paging. Starts at the beginning by default.
cpnamespace- Optional namespace id: Includes only the pages in the category that are in one namespace.
cpextended - Add extra information like sortkey and timestamp to the category output.
Example: http://meta.wikimedia.org/w/query.php?what=category&cptitle=Days
http://meta.wikimedia.org/w/query.php?what=category&cptitle=Time&cpnamespace=14 -- show subcategories of category Time

users - Adds user pages to the output list.

Parameters supported:
usfrom - Start user listing from...
uslimit - How many total links to return.
Example: http://meta.wikimedia.org/w/query.php?what=users&usfrom=Y

Properties of specified pages

redirects - For all given redirects, provides additional information such as page IDs and double-redirection

Example: query.php?what=redirects&titles=Main_page
query.php?what=recentchanges|redirects (Which of the recent changes are redirects?)

permissions - For all found pages, check if the user can edit them.

Parameters supported:
prcanmove - Also check if the page can be moved.
Example: query.php?what=permissions&titles=Main_page|User%20Talk:Yurik

links - List of regular page links

Example: query.php?what=links&titles=MediaWiki|Wikipedia

langlinks - Inter-language links

Example: query.php?what=langlinks&titles=MediaWiki|Wikipedia

templates - List of used templates

Example: query.php?what=templates&titles=Main_Page

categories - List of categories the page belongs to

Parameters supported:
clextended - Add extra information like sortkey and timestamp
Example: query.php?what=categories&titles=Albert%20Einstein&clextended

backlinks - What pages link to this page(s)

Parameters supported:
blfilter - Of all given pages, which should be queried:
'redirects', 'nonredirects', 'existing' (blue links, default), or 'all' (red links)
blnamespace- Optional namespace id: limits the namespace of the originating pages
bllimit - How many total links to return
blcontfrom - From which point to continue. Use the 'next' value from the previous queries.
Example: query.php?what=backlinks&titles=Main%20Page&bllimit=10

embeddedin - What pages include this page(s) as template(s)

Parameters supported:
eifilter - Of all given pages, which should be queried:
'redirects', 'nonredirects', 'existing' (blue links, default), or 'all' (red links)
einamespace- Optional namespace id: limits the namespace of the originating pages
eilimit - How many total links to return
eicontfrom - From which point to continue. Use the 'next' value from the previous queries.
Example: query.php?what=embeddedin&titles=Template:Stub&eilimit=10

imagelinks - What pages use this image(s)

ilfilter - Of all given images, which should be queried:
'existing', 'all' (default, includes non-existent or those stored on Wikimedia Commons)
ilnamespace- Optional namespace id: limits the namespace of the originating pages
illimit - How many total links to return
ilcontfrom - From which point to continue. Use the 'next' value from the previous queries.
Example: query.php?what=imagelinks&titles=Image:HermitageAcrossNeva.jpg&illimit=10

revisions - Revision history - Lists edits performed to the given pages

Parameters supported:
rvuniqusr - Get last #rvlimit revisions by unique authors. *slow query*
rvcomments - Include summary strings.
rvcontent - Include raw wiki text. *slow query*
rvlimit - How many links to return *for each title*. Defaults to 10, or 0 if revids=... was specified.
rvoffset - When too many results are found, use this to page. *obsolete* This option is likely to disappear soon.
rvstart - Timestamp of the earliest entry.
rvend - Timestamp of the latest entry.
rvrbtoken - If logged in as an admin, a rollback tokens for top revisions will be included in the output.
Example: query.php?what=revisions&titles=Main%20Page&rvlimit=10&rvcomments -- last 10 revisions of the Main Page
query.php?what=revisions&titles=Main%20Page&rvuniqusr&rvlimit=3&rvcomments -- 3 last unique users with their last revisions.

usercontribs - User contribution history - Lists last edits performed by the given user(s)

Parameters supported:
uccomments - If specified, the result will include summary strings.
uclimit - How many links to return *for each user*.
uctop - Filter results by contributions that are still on top:
'all' (default), 'only' (only the ones marked as top), 'exclude' (all non-top ones)
ucstart - Timestamp of the earliest entry.
ucend - Timestamp of the latest entry.
ucrbtoken - If logged in as an admin, a rollback tokens for top revisions will be included in the output.
Example: query.php?what=usercontribs&titles=User:YurikBot&uclimit=20&uccomments

imageinfo - Image information

Parameters supported:
iiurl - Add image URLs.
iihistory - Include all past revisions of the image.
iishared - Include image info from the shared image repository (commons)
Example: query.php?what=imageinfo|allpages&aplimit=10&apnamespace=6&iiurl -- show first 10 images with URLs

content - Raw page content - Retrieves raw wiki markup for all found pages.

*slow query* Please optimize content requests to reduce load on the servers.
Duplicate results may be obtained through revisions+rvcontent request
Example: query.php?what=content&titles=Main%20Page

Supported formats

xmlfm - XML format in HTML (Default)

The data is presented as an indented syntax-highlighted XML format.
Errors will return this usage screen, unless 'nousage' parameter is given.
Example: query.php?what=info&format=xmlfm

jsonfm - JSON format in HTML

Example: query.php?what=info&format=jsonfm (Format info: http://en.wikipedia.org/wiki/JSON)

txt - print_r() output (HTML)

Example: query.php?what=info&format=txt (Format info: http://www.php.net/print_r)

dbg - PHP source code using var_export() (HTML)

Example: query.php?what=info&format=dbg (Format info: http://www.php.net/var_export)

xml - XML format

Optional indentation can be enabled by supplying 'xmlindent' parameter.
Errors will return this usage screen, unless 'nousage' parameter is given.
Internet Explorer is known to have many issues with text/xml output.
Please use other browsers or switch to xmlfm format while debugging.
Example: query.php?what=info&format=xml

json - JSON format

Example: query.php?what=info&format=json (Format info: http://en.wikipedia.org/wiki/JSON)

php - PHP serialized format using serialize()

Example: query.php?what=info&format=php (Format info: http://www.php.net/serialize)

wddx - WDDX - Web Distributed Data eXchange format

Example: query.php?what=info&format=wddx (Format info: http://en.wikipedia.org/wiki/WDDX)

Links

Credits

This feature was written and is being maintained by Yuri Astrakhan (FirstnameLastname@gmail.com) Please leave your comments and suggestions at http://en.wikipedia.org/wiki/User_talk:Yurik

This extension came as the result of IRC discussion between Yuri Astrakhan (en:Yurik), Tim Starling (en:Tim Starling), and Daniel Kinzler(de:Duesentrieb) The extension was first implemented by Tim to provide interlanguage links and history summary. It was later completely rewritten by Yuri, introducing the rest of properties, meta information, and various formatting options.