API:Všechny stránky
Akce API MediaWiki |
---|
Základní informace |
Přihlášení |
Uživatelské účty a uživatelé |
Operace spojené se stránkou |
|
Vyhledávání |
Nástroje pro vývojáře |
Návody |
v · d · u |
GET požadavek pro výpis všech stránek splňujících určitá kritéria v rámci dané oblasti Jmenný prostor .
Tento modul lze použít jako zdroj .
Dokumentace API
list=allpages (ap)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
Enumerate all pages sequentially in a given namespace.
- apfrom
The page title to start enumerating from.
- apcontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
- apto
The page title to stop enumerating at.
- apprefix
Search for all page titles that begin with this value.
- apnamespace
The namespace to enumerate.
- One of the following values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 710, 711, 828, 829, 1198, 1199, 2600, 5500, 5501
- Default: 0
- apfilterredir
Which pages to list.
Note: Due to miser mode, using this may result in fewer than aplimit results returned before continuing; in extreme cases, zero results may be returned.
- One of the following values: all, nonredirects, redirects
- Default: all
- apfilterlanglinks
Filter based on whether a page has langlinks. Note that this may not consider langlinks added by extensions.
- One of the following values: all, withlanglinks, withoutlanglinks
- Default: all
- apminsize
Limit to pages with at least this many bytes.
- Type: integer
- apmaxsize
Limit to pages with at most this many bytes.
Disabled due to miser mode.
- Type: integer
- apprtype
Limit to protected pages only.
- Values (separate with | or alternative): edit, move, upload
- apprlevel
Filter protections based on protection level (must be used with apprtype= parameter).
- Values (separate with | or alternative): Can be empty, or autoconfirmed, sysop
- apprfiltercascade
Filter protections based on cascadingness (ignored when apprtype isn't set).
- One of the following values: all, cascading, noncascading
- Default: all
- apprexpiry
Which protection expiry to filter the page on:
- indefinite
- Get only pages with indefinite protection expiry.
- definite
- Get only pages with a definite (specific) protection expiry.
- all
- Get pages with any protections expiry.
- One of the following values: all, definite, indefinite
- Default: all
- aplimit
How many total pages to return.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
- apdir
The direction in which to list.
- One of the following values: ascending, descending
- Default: ascending
- Show a list of pages starting at the letter B.
- api.php?action=query&list=allpages&apfrom=B [open in sandbox]
- Show info about 4 pages starting at the letter T.
- api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info [open in sandbox]
- Show content of first 2 non-redirect pages beginning at Re.
- api.php?action=query&generator=allpages&gaplimit=2&gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content [open in sandbox]
Příklad
Dotazování přes GET
Get all pages whose title contains the text "Jungle", in whole or part.
Response
{ "batchcomplete":"", "continue":{ "apcontinue":"Jungle_(Bakufu_Slump_album)", "continue":"-||" }, "query":{ "allpages":[ { "pageid":341265, "ns":0, "title":"Jungle" }, { "pageid":56461312, "ns":0, "title":"Jungle-runner" }, { "pageid":18698572, "ns":0, "title":"Jungle/Drum n bass" }, { "pageid":1487899, "ns":0, "title":"Jungle2jungle" }, { "pageid":30391179, "ns":0, "title":"JunglePup" } ... ] } }
Sample code
Python
#!/usr/bin/python3 """ get_allpages.py MediaWiki API Demos Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part. MIT License """ importrequests S = requests.Session() URL = "https://en.wikipedia.org/w/api.php" PARAMS = { "action": "query", "format": "json", "list": "allpages", "apfrom": "jungle", } R = S.get(url=URL, params=PARAMS) DATA = R.json() PAGES = DATA["query"]["allpages"] for page in PAGES: print(page["title"])
PHP
<?php /* get_allpages.php MediaWiki API Demos Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part. MIT License */ $endPoint = "https://en.wikipedia.org/w/api.php"; $params = [ "action" => "query", "format" => "json", "list" => "allpages", "apfrom" => "jungle" ]; $url = $endPoint . "?" . http_build_query( $params ); $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $output = curl_exec( $ch ); curl_close( $ch ); $result = json_decode( $output, true ); foreach( $result["query"]["allpages"] as $k => $v ) { echo( $v["title"] . "\n" ); }
JavaScript
/* get_allpages.js MediaWiki API Demos Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part. MIT License */ leturl="https://en.wikipedia.org/w/api.php"; constparams={ action:"query", format:"json", list:"allpages", apfrom:"jungle" } url+="?origin=*" Object.keys(params).forEach((key)=>{ url+=`&${key}=${params[key]}` }) fetch(url) .then((response)=>{ returnresponse.json() }) .then((response)=>{ constpages=response.query.allpages for(letpinpages){ console.log(pages[p].title) } }) .catch((error)=>{ console.log(error) })
MediaWiki JS
/* get_allpages.js MediaWiki API Demos Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part. MIT License */ varparams={ action:'query', format:'json', list:'allpages', apfrom:'jungle' }, api=newmw.Api(); api.get(params).done(function(data){ varpages=data.query.allpages, p; for(pinpages){ console.log(pages[p].title); } });
Possible errors
Code | Info |
---|---|
invalidparammix | The prlevel parameter may only be used with prtype. |
See also
- Chris G's botclasses/AllPagesBot.php — a bot that retrieves all files on a wiki, utilizing this API
- API:Členové kategorie — lists all pages within a category
- API:Kategorie — lists all categories associated with a certain page, which can aid in finding similar pages
- API:Všechny kategorie — lists all categories fitting a certain criteria
- API:Všechny obrázky — lists all images whose file names fit a certain criteria
- API:Všichni uživatelé — lists all users in alphabetical order