API:Tags - MediaWiki (original) (raw)
Languages:
| This page is part of the MediaWiki Action API documentation. |
|---|
| MediaWiki version: | ≥ 1.16 |
|---|
GET request to list valid change tags.
| The following documentation is the output of Special:ApiHelp/query+tags, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org). |
|---|
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
List change tags.
Specific parameters:
tgcontinue
When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.
tglimit
The maximum number of tags to list.
Type: integer or max
The value must be between 1 and 500.
Default: 10
tgprop
Which properties to get:
displayname
Adds the displayed name of the tag. This property will be omitted for hidden tags.
description
Adds the description of the tag.
hitcount
Adds the number of revisions and log entries that have this tag.
defined
Indicate whether the tag is defined (see source).
source
Gets the sources of the tag definition, which may include software for software-defined tags and manual for tags that may be applied manually by users.
active
Whether the tag is still being applied by the software, or may still be applied by users.
Values (separate with | or alternative): active, defined, description, displayname, hitcount, source
Default: (empty)
Get the first three change tags and their hitcounts.
{ "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" } ] } }
#!/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"])
"query", "format" => "json", "list" => "tags", "tgprop" => "hitcount", "tglimit" => "3" ]; url=url = url=endPoint . "?" . http_build_query( $params ); ch=curlinit(ch = curl_init( ch=curlinit(url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); output=curlexec(output = curl_exec( output=curlexec(ch ); curl_close( $ch ); result=jsondecode(result = json_decode( result=jsondecode(output, true ); foreach( result["query"]["tags"]asresult["query"]["tags"] as result["query"]["tags"]ask => $v ) { echo( $v["name"] . "\n" ); } /* 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);}); /* 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 ); } } ); * This module cannot be used as a [Generator](/wiki/Special:MyLanguage/API:generator "Special:MyLanguage/API:generator")[ ](/wiki/API:Generator "API:Generator"). * [API:Recentchanges](/wiki/Special:MyLanguage/API:Recentchanges "Special:MyLanguage/API:Recentchanges")[ ](/wiki/API:Recentchanges "API:Recentchanges") – List recent changes * [API:Managetags](/wiki/Special:MyLanguage/API:Managetags "Special:MyLanguage/API:Managetags")[ ](/wiki/API:Managetags "API:Managetags") – Define or delete tags