API:Tags/de
![]() | Diese Seite ist Teil der Dokumentation der MediaWiki action API. |
MediaWiki Version: | ≥ 1.16 |
GET-Abfrage um gültige Änderungs-Markierungen aufzulisten.
API-Dokumentation
![]() | Die folgende Dokumentation ist die Ausgabe von Special: |
list=tags (tg)
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
List change tags.
Specific parameters:
Other general parameters are available.
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
The maximum number of tags to list.
- Type: integer or max
- The value must be between 1 and 500.
- Default: 10
Which properties to get:
- displayname
- Adds system message for the tag.
- description
- Adds description of the tag.
- hitcount
- Adds the number of revisions and log entries that have this tag.
- defined
- Indicate whether the tag is defined.
- source
- Gets the sources of the tag, which may include extension for extension-defined tags and manual for tags that may be applied manually by users.
- active
- Whether the tag is still being applied.
- Values (separate with | or alternative): active, defined, description, displayname, hitcount, source
- Default: (empty)
Example:
Beispiel
GET-Anfrage
Erhalte die ersten drei Änderungs-Markierungen und deren Trefferzahlen.
api.php? action=query& format=json& list=tags& tgprop=hitcount& tglimit=3 [In der ApiSandbox ausprobieren]
Antwort
{
"batchcomplete": "",
"continue": {
"continue": "-||",
"tgcontinue": "Extraneous formatting"
},
"query": {
"tags": [
{
"hitcount": 2481517,
"name": "AWB"
},
{
"hitcount": 10849,
"name": "Addition of interwiki link"
},
{
"hitcount": 819,
"name": "Citing predatory open access journal"
}
]
}
}
Beispielcode
Python
#!/usr/bin/python3
"""
get_tags.py
MediaWiki API Demos
Demo of `Tags` module: Get the first three change tags and their hitcounts.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "tags",
"tgprop": "hitcount",
"tglimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
TAGS = DATA["query"]["tags"]
for t in TAGS:
print(t["name"])
PHP
<?php
/*
get_tags.php
MediaWiki API Demos
Demo of `Tags` module: Get the first three change tags and their hitcounts.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "tags",
"tgprop" => "hitcount",
"tglimit" => "3"
];
$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"]["tags"] as $k => $v ) {
echo( $v["name"] . "\n" );
}
JavaScript
/*
get_tags.js
MediaWiki API Demos
Demo of `Tags` module: Get the first three change tags and their hitcounts.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "tags",
tgprop: "hitcount",
tglimit: "3"
};
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 tags = response.query.tags;
for (var t in tags) {
console.log(tags[t].name);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_tags.js
MediaWiki API Demos
Demo of `Tags` module: Get the first three change tags and their hitcounts.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'tags',
tgprop: 'hitcount',
tglimit: '3'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var tags = data.query.tags,
t;
for ( t in tags ) {
console.log( tags[ t ].name );
}
} );
Zusätzliche Anmerkungen
- Dieses Modul kann nicht als Generator benutzt werden.
Siehe auch
- API:Recentchanges - Listet Letzte Änderungen auf
- API:Markierungen verwalten - Markierungen definieren oder löschen