API:Categories/cs: Difference between revisions
Appearance
Content deleted Content added
Created page with "Popis" |
Updating to match new version of source page |
||
| (12 intermediate revisions by 2 users not shown) | |||
| Line 4: | Line 4: | ||
'''Žádost GET''' pro zobrazení {{ll|Help:Categories|kategorií}} spojených se stránkou nebo stránkami. |
'''Žádost GET''' pro zobrazení {{ll|Help:Categories|kategorií}} spojených se stránkou nebo stránkami. |
||
Tento modul lze použít jako |
Tento modul lze použít jako {{ll|API:Query#Generators|zdroj}}. |
||
<span id="API_documentation"></span> |
<span id="API_documentation"></span> |
||
== Dokumentace API == |
== Dokumentace API == |
||
| ⚫ | |||
{| style="color: black; background-color: #f8f8f8; border-spacing: 20px; border: 1px solid darkgray;" |
|||
| ⚫ | |||
|} |
|||
<span id="Example"></span> |
<span id="Example"></span> |
||
| Line 64: | Line 62: | ||
<span id="Sample_code"></span> |
<span id="Sample_code"></span> |
||
=== Ukázkový kód === |
=== Ukázkový kód === |
||
<!-- Transclude Sample code --> |
<!-- Transclude Sample code --> |
||
{{:{{translatable}}/Sample code 1}} |
{{:{{translatable}}/Sample code 1}} |
||
| Line 72: | Line 69: | ||
{| class="wikitable" |
{| class="wikitable" |
||
|+ |
|+ |
||
!Kód!!Popis |
! Kód !! Popis |
||
|- |
|- |
||
| clshow || {{int|apierror-show}} |
| clshow || {{int|apierror-show}} |
||
|} |
|} |
||
<span id="Parameter_history"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
== |
== Historie parametrů == |
||
* v1.20: Představeno <code>cldir</code> |
|||
</div> |
|||
* v1. |
* v1.16: Představeno <code>clprop=hidden</code> |
||
* v1. |
* v1.15: Představeno <code>clcategories</code> |
||
* v1. |
* v1.14: Představeno <code>clshow</code> |
||
* v1. |
* v1.13: Představeno <code>clcontinue</code>, <code>cllimit</code>, <code>clprop=timestamp</code> |
||
* v1.13: <span lang="en" dir="ltr" class="mw-content-ltr">Introduced <code>clcontinue</code>, <code>cllimit</code>, <code>clprop=timestamp</code></span> |
|||
<span id="See_also"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
== |
== Související odkazy == |
||
* {{ll|API:Categorymembers}} - uvádí stránky, které jsou členy určité kategorie. |
|||
</div> |
|||
* {{ll|API:Allpages}} - vypíše všechny stránky splňující určitá kritéria. Může také přistupovat do kategorie {{ll|Manual:Namespace|namespace}}. |
|||
* {{ll|API:Categorymembers}} - <span lang="en" dir="ltr" class="mw-content-ltr">lists pages which are members of a certain category.</span> |
|||
* {{ll|API:Allcategories}} - modul <code>{{ll|API:Lists|list}}</code>, který získává kategorie z celé wiki na základě určitých kritérií souvisejících s názvem kategorie. |
|||
* {{ll|API:Allpages}} - <span lang="en" dir="ltr" class="mw-content-ltr">lists all pages fitting a certain criteria; it can also access the category {{ll|Manual:Namespace|namespace}}.</span> |
|||
* {{ll|API:Allcategories}} - <span lang="en" dir="ltr" class="mw-content-ltr">a <code>{{ll|API:Lists|list}}</code> module that gets categories from across the entire wiki, based on certain criteria relating to the category title.</span> |
|||
Latest revision as of 02:23, 21 June 2026
| Tato stránka je součástí dokumentace k API Action MediaWiki. |
| Verze MediaWiki: | ≥ 1.11 |
Žádost GET pro zobrazení kategorií spojených se stránkou nebo stránkami.
Tento modul lze použít jako zdroj.
Dokumentace API
Příklad
Dotazování přes GET
GET požadavek na zobrazení kategorií na stránce.
Odpověď
{
"continue": {
"clcontinue": "13828397|Afrofuturists",
"continue": "||"
},
"query": {
"pages": {
"13828397": {
"pageid": 13828397,
"ns": 0,
"title": "Janelle Mon\u00e1e",
"categories": [
{
"ns": 14,
"title": "Category:1985 births"
},
{
"ns": 14,
"title": "Category:21st-century American actresses"
},
{
"ns": 14,
"title": "Category:21st-century American singers"
},
...
]
}
}
}
}
Ukázkový kód
Python
#!/usr/bin/python3
"""
get_categories.py
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"prop": "categories",
"titles": "Janelle Monáe"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items():
for cat in v['categories']:
print(cat["title"])
PHP
<?php
/*
get_categories.php
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"prop" => "categories",
"titles" => "Janelle Monáe"
];
$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"]["pages"] as $k => $v ) {
foreach( $v["categories"] as $k => $v ) {
echo( $v["title"] . "\n" );
}
}
JavaScript
/*
get_categories.js
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
prop: "categories",
titles: "Janelle Monáe"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var pages = response.query.pages;
for (var p in pages) {
for (var cat of pages[p].categories) {
console.log(cat.title);
}
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_categories.js
MediaWiki API Demos
Demo of `Categories` module: Get categories associated with a page.
MIT License
*/
var params = {
action: 'query',
format: 'json',
prop: 'categories',
titles: 'Janelle Monáe'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.pages,
p;
for ( p in pages ) {
pages[ p ].categories.forEach( function ( cat ) {
console.log( cat.title );
} );
}
} );
Možné chyby
| Kód | Popis |
|---|---|
| clshow | Nesprávny parameter – vzájomne sa vylučujúce hodnoty nemožno zadať naraz. |
Historie parametrů
- v1.20: Představeno
cldir - v1.16: Představeno
clprop=hidden - v1.15: Představeno
clcategories - v1.14: Představeno
clshow - v1.13: Představeno
clcontinue,cllimit,clprop=timestamp
Související odkazy
- API:Členové kategorie - uvádí stránky, které jsou členy určité kategorie.
- API:Všechny stránky - vypíše všechny stránky splňující určitá kritéria. Může také přistupovat do kategorie namespace.
- API:Všechny kategorie - modul
list, který získává kategorie z celé wiki na základě určitých kritérií souvisejících s názvem kategorie.