From EncyclopAtys
Translation Status → This page is one of the 25 we would like to see translated into English. |
Unübersetzt • Untranslated • No traducido • Non traduit • Не переведено |
Contents
Action API - Intro
Source: https://www.mediawiki.org/wiki/API:Query#Introduction_and_guidelines
The action=query module allows you to get 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 change wiki content.
The query module has many submodules (called query modules), each with a different function. There are 3 types of query modules:
- Meta information about the wiki and the logged-in user
- Properties of pages, including page revisions and content
- Lists of pages that match certain criteria (Most list queries return 10 items by default)
You should use multiple query modules together to get what you need in one request, e.g. prop=info|revisions&list=backlinks|embeddedin|allimages&meta=userinfo is a call to six modules in one request.
all property query modules work on a set of pages that you specify using either titles, pageids, revids, or generator parameters. Do not ask for one page at a time – this is very inefficient, and consumes lots of extra resources and bandwidth: request information about multiple pages by combining their titles or ids with the '|' pipe symbol: titles=PageA|PageB|PageC.
Use generator if you want to get data about a set of pages that would be the result of another API call. For ex, if you want to get data about pages in a certain category, instead of querying list=categorymembers and then querying again with pageids set to all the returned pages, you should combine the two API calls into one by specifying generator=categorymembers in place of the list parameter.
If you're querying Wikimedia wikis and requesting results as format=json (or php), then specify formatversion=2. The original result format was designed around XML; the new structure is easier to process (and defaults to utf8).
Action API - simple ex
http://en.wiki.ryzom.com/w/api.php?action=query&prop=revisions&rvprop=content&format=jsonfm&formatversion=2&titles=Main%20Page simply gets the wiki markup (content) of a page: fetch (action=query) the content (rvprop=content) of the most recent revision of Main Page (titles=Main%20Page) in JSON with whitespace to make it easier to read (format=jsonfm).
Action API - Specifying pages
- By name using the titles parameter, e.g. titles=Foo|Bar|Main_Page
- By page ID using the pageids parameter, e.g. pageids=123|456|75915
- By revision ID using the revids parameter, e.g. revids=478198|54872|54894545
- Most query modules will convert revision ID to the corresponding page ID. Only prop=revisions actually uses the revision ID itself.
- Using a generator
Specifying titles through the query string (either through titles or pageids) is limited to 50 titles per query (or 500 for those with the apihighlimits right, usually bots and sysops).
https://www.mediawiki.org/wiki/API:FAQ
- If you are trying to get information about a page, you probably will use a prop= submodule of action=query. Other query submodules return lists of pages and meta-information about the wiki. View the generated API help of all query submodules.
Action API - Title normalization
converts page titles to their canonical form (Cap, replacing _ with spaces, and changing namespace to the localized form defined for that wiki). Title normalization is done automatically, regardless of which query modules are used. However, any trailing line breaks in page titles (\n) will cause odd behavior and they should be stripped out first.
Missing and invalid titles: appear in the <pages> section, but they have the missing or invalid attribute set. In output formats that support numeric array keys (JSON and PHP serialized), missing and invalid titles will have unique, negative page IDs. Query modules will just ignore missing or invalid titles, as they can't do anything useful with them. The titles in the Special: and Media: namespaces cannot be queried.
Resolving redirects
when the page has a redir, contain from and to attributes and may contain a tofragment attribute for those redirects that point to specific sections.
Continuing queries
there are more data matching the query, the API result includes a continue element. If you want further data, you would add its values (in the example, continue=-|| and accontinue=List_of_19th_century_baseball_players) to the original request to get the next set of results. You continue to do this until an API result does not have a continue element, indicating there are no more data matching the query.
Getting a list of page IDs
When not using the new JSON formatversion=2, the result page set in JSON is returned as an object keyed by page ID which can be difficult to properly iterate over in JavaScript. The indexpageids parameter returns these page IDs as an array for easier iteration. Note that the ordering of these page IDs still does not necessarily correspond to the ordering of the input (whether directly or via a generator)
Page export
If the export parameter is set, an XML dump of all pages in the <pages> element will be added to the result - it only gives a result when used with specified titles (Generator, titles, pageids or revid). If the exportnowrap parameter is also set, only the XML dump (not wrapped in an API result) will be returned.
- export of User:Amosys/Draft/User_Manual/Part_4_-_Credits (with id, revision id and its contributor, comment..) https://en.wiki.ryzom.com//w/api.php?action=query&titles=User:Amosys/Draft/User_Manual/Part_4_-_Credits%7CTalk:&export&exportnowrap
Generators: use the output of a list instead of the titles
Other query modules will treat generated pages as if they were given in a parameter. Only one generator is allowed.
see lists
Lists
https://www.mediawiki.org/wiki/API:Lists
Lists generally return aggregations of data, such as pages gathered from across a wiki, or links gathered within a single page. To request a list, pass the list parameter of your query string a valid list submodule, such as allimages or usercontribs.
To use the list API, specify action=query&list=list1|list2 in the URL.
Ex https://www.mediawiki.org/wiki/API:Allcategories
- https://en.wikipedia.org/w/api.php?action=query&format=json&acfrom=15th-century%20caliphs&list=allcategories
- avec nb pages https://en.wiki.ryzom.com/w/api.php?action=query&format=json&acfrom=Gameplay&list=allcategories&acprop=size
Ex to list pages that belong to a given category. https://www.mediawiki.org/wiki/API:Categorymembers
- 20 p in category:gameplay https://en.wiki.ryzom.com/w/api.php?action=query&list=categorymembers&cmtitle=Category:Gameplay&cmlimit=20&format=json
- 20 p in FR catégorie gameplay https://fr.wiki.ryzom.com/w/api.php?action=query&list=categorymembers&cmtitle=Category:Gameplay&cmlimit=20&format=json
- 10 articles most recently added to a category https://en.wiki.ryzom.com/w/api.php?action=query&list=categorymembers&cmtitle=Category:Gameplay&cmsort=timestamp&cmdir=desc&format=json
- same on common with User Manual v4 https://atys.wiki.ryzom.com/w/api.php?action=query&list=categorymembers&cmtitle=Category:User_Manual_v4&cmsort=timestamp&cmdir=desc&format=json
- Get 10 subcategories of a category https://en.wiki.ryzom.com/w/api.php?action=query&list=categorymembers&cmtitle=Category:Gameplay&cmtype=subcat&format=json
Links
https://www.mediawiki.org/wiki/API:FAQ/fr