Extension:BotQuery

Query.php provides read-only access to various metadata about pages of MediaWiki projects. It has been installed on all Wikimedia projects, see also installation on other MediaWiki projects.

What follows is derived from /w/query.php, for this site /w/query.php, see that page for up-to-date info. The example queries on that page apply to the site concerned. Similarly the examples below apply for this site.

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 various machine readable formats; the default format xmlfm - XML format in HTML - is, with a browser, fairly suitable for human reading also; however, it is "cluttered" with xml tags, and the pagenames in the output are not linked.

More than one piece of information may be requested with a single query.

Usage
/w/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
/w/query.php?what=links|templates&titles=Help:Template - Get a list of all links and templates used on the page Help:Template.

/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

/w/query.php?what=revisions&revids=403918&rvcomments - Get revision 403918 with some of its properties.

Properties of the entire site
info - General site information Example: /w/query.php?what=info

namespaces - List of localized namespace names Example: /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.

Examples:
 * /w/query.php?what=userinfo&uiisblocked&uihasmsg&uiextended
 * /w/query.php?what=userinfo&uioptions=timecorrection|skin -- 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: /w/query.php?what=recentchanges&rchide=liu|bots

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: /w/query.php?what=allpages&aplimit=50 (first 50 pages) /w/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: /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: /w/query.php?what=category&cptitle=Days /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: /w/query.php?what=users&usfrom=Y

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

Examples:
 * /w/query.php?what=redirects&titles=Main_page
 * /w/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:
 * /w/query.php?what=permissions&titles=Main_page|User%20Talk:Yurik

links
List of regular page links, including a link to a non-existing page produced by attempting to include the page.

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

langlinks
Inter-language links

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

templates
List of pages embedded in a given page (the same list as given on the edit page, except that an attempt to embed a non-existing page, producing a link, counts for the query functions as linking, not embedding.

Example:
 * /w/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:
 * /w/query.php?what=categories&titles=Albert%20Einstein&clextended

backlinks
List of pages linking to a given page (the entries of "What links here" not marked with "inclusion", plus those marked with "inclusion" which not only include the given page but also link to it)

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.

Examples:
 * /w/query.php?what=backlinks&titles=Main%20Page&blfilter=all
 * /w/query.php?what=backlinks&titles=Main%20Page&blnamespace=12&blfilter=all

embeddedin
List of pages a given page is embedded in as template (the entries of "What links here" marked with "inclusion")

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:
 * /w/query.php?what=embeddedin&titles=Abc&eilimit=500&eifilter=all

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:
 * /w/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.

Examples:
 * /w/query.php?what=revisions&titles=Main%20Page&rvlimit=10&rvcomments -- last 10 revisions of the Main Page
 * /w/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:
 * /w/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:
 * /w/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:
 * /w/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. With a browser the output seems the best available for human readability, although it is "cluttered" with xml tags. Errors will return the usage screen, unless 'nousage' parameter is given.

Example:
 * /w/query.php?what=links|templates&titles=Help:Go%20button&format=xmlfm

jsonfm - JSON format in HTML Example: /w/query.php?what=links|templates&titles=Help:Go%20button&format=jsonfm (Format info: http://en.wikipedia.org/wiki/JSON)

txt - print_r output (HTML) Example: /w/query.php?what=links|templates&titles=Help:Go%20button&format=txt (Format info: http://www.php.net/print_r)

dbg - PHP source code using var_export (HTML) Example: /w/query.php?what=links|templates&titles=Help:Go%20button&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 the 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: /w/query.php?what=links|templates&titles=Help:Go%20button&format=xml

json - JSON format Example: /w/query.php?what=links|templates&titles=Help:Go%20button&format=json (Format info: http://en.wikipedia.org/wiki/JSON)

php - PHP serialized format using serialize Example: /w/query.php?what=links|templates&titles=Help:Go%20button&format=php (Format info: http://www.php.net/serialize)

wddx - WDDX - Web Distributed Data eXchange format Example: /w/query.php?what=links|templates&titles=Help:Go%20button&format=wddx (Format info: http://en.wikipedia.org/wiki/WDDX)

Links

 * Home Page: http://en.wikipedia.org/wiki/User:Yurik/Query_API
 * Suggestions: http://en.wikipedia.org/wiki/User_talk:Yurik/Query_API
 * Changelog and Source: *http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/BotQuery/query%2Ephp?view=log

Credits
This feature was written and is being maintained by Yuri Astrakhan (@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.