API:Allusers: Difference between revisions
Appearance
Content deleted Content added
RobinHood70 (talk | contribs) →Parameters: Convert |
Use API documentation frame from the template |
||
(31 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
{{API}} |
{{API}} |
||
{{MW 1.11|and after}} |
|||
{| style="float:right" |
|||
<translate> |
|||
| {{MW 1.11}} |
|||
<!--T:1--> |
|||
|- |
|||
'''GET request''' to list all registered users, as ordered by username. |
|||
| |
|||
{{API-head |
|||
== API documentation == <!--T:2--> |
|||
|prefix=au |
|||
</translate> |
|||
|rrights=None |
|||
{{Api help|query+allusers|frame=yes}} |
|||
|postonly=No |
|||
|description=<nowiki>Enumerate all registered users, ordered by username</nowiki> |
|||
<translate> |
|||
|generator=no |
|||
== Example == <!--T:3--> |
|||
=== GET request === <!--T:4--> |
|||
</translate> |
|||
{{ApiEx |
|||
|desc=<translate><!--T:5--> GET request to list all users, starting from those whose name begins with the string, "<tvar name=1>Drov</tvar>"</translate> |
|||
|p1=action=query |
|||
|p2=format=json |
|||
|p3=list=allusers |
|||
|p4=auprefix=Drov |
|||
}} |
}} |
||
<translate> |
|||
=== Response === <!--T:6--> |
|||
</translate> |
|||
<div style="width:60%;"> |
|||
<syntaxhighlight lang="json"> |
|||
{ |
|||
"batchcomplete": "", |
|||
"continue": { |
|||
"aufrom": "Drovark", |
|||
"continue": "-||" |
|||
}, |
|||
"query": { |
|||
"allusers": [ |
|||
{ |
|||
"userid": 13239275, |
|||
"name": "Drov" |
|||
}, |
|||
{ |
|||
"userid": 7080866, |
|||
"name": "Drova" |
|||
}, |
|||
{ |
|||
"userid": 16013473, |
|||
"name": "Drova 82" |
|||
}, |
|||
... |
|||
] |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
</div> |
|||
<translate> |
|||
=== Sample code === <!--T:7--> |
|||
</translate> |
|||
<!-- Transclude Sample code --> |
|||
{{:{{translatable}}/Sample code 1}} |
|||
<translate> |
|||
== Possible errors == <!--T:8--> |
|||
</translate> |
|||
{| class="wikitable" |
|||
|+ |
|||
!<translate><!--T:9--> Code</translate>!!<translate><!--T:10--> Info</translate> |
|||
|- |
|||
|augroup-excludegroup || <translate><!--T:11--> group and excludegroup cannot be used together</translate> |
|||
|} |
|} |
||
<translate> |
|||
== Parameters == |
|||
== Parameter history == <!--T:12--> |
|||
{{ApiParam|from |The user name to start enumerating from}} |
|||
</translate> |
|||
{{ApiParam|to |The user name to stop enumerating at}} |
|||
* v1.12: <translate><!--T:21--> Introduced <tvar name=1><code>auprop=registration</code></tvar></translate> |
|||
{{ApiParam|prefix |Search for all users that begin with this value}} |
|||
{{ApiParam|dir |Direction to sort in. One value: ascending, descending. Default: ascending}} |
|||
{{ApiParam|group |Limit users to given group name(s).|values=bot, sysop, bureaucrat (+ any other group that is defined on the wiki). This is different for every wiki; see the API help or [[API:Parameter information|action=paraminfo]] for a list of possible values}} |
|||
{{ApiParam|excludegroup |Exclude users in given group name(s)}} |
|||
{{ApiParam|rights |Limit users to given right(s)}} |
|||
{{ApiParam|prop |What pieces of information to include.}} |
|||
{{ApiParam|bullet=*|blockinfo |Adds the information about a current block on the user}} |
|||
{{ApiParam|bullet=*|groups |Lists groups that the user is in. This uses more server resources and may return fewer results than the limit}} |
|||
{{ApiParam|bullet=*|implicitgroups|Lists all the groups the user is automatically in}} |
|||
{{ApiParam|bullet=*|rights |Lists rights that the user has}} |
|||
{{ApiParam|bullet=*|editcount |Adds the edit count of the user}} |
|||
{{ApiParam|bullet=*|registration |Adds the timestamp of when the user registered if available (may be blank)}} |
|||
{{ApiParam|limit |How many total user names to return.|maxallowed=500|default=10}} |
|||
{{ApiParam|witheditsonly|Only list users who have made edits}} |
|||
{{ApiParam|activeusers |Only list users active in the last 30 days(s)}} |
|||
<translate> |
|||
== Example == |
|||
== Additional notes == <!--T:13--> |
|||
{{ApiEx |
|||
| desc=Show a list of usernames starting with Y (or whichever sorts first after that) |
|||
| p1= action=query |
|||
| p2= list=allusers |
|||
| p3= aufrom=Y |
|||
| result=<source lang="xml"> |
|||
<api> |
|||
<query> |
|||
<allusers> |
|||
<u userid="3634417" name="Y" /> |
|||
<u userid="53928" name="Y (usurped)" /> |
|||
<u userid="7341556" name="Y 12345 ut" /> |
|||
<u userid="10969800" name="Y 19" /> |
|||
<u userid="9302968" name="Y 1praneeth" /> |
|||
<u userid="5191615" name="Y 20" /> |
|||
<u userid="8724565" name="Y 2112 Y" /> |
|||
<u userid="2941099" name="Y 4 yellow" /> |
|||
<u userid="13676048" name="Y 6" /> |
|||
<u userid="7423920" name="Y A D A carlos alberto" /> |
|||
</allusers> |
|||
</query> |
|||
<query-continue> |
|||
<allusers aufrom="Y A N K O" /> |
|||
</query-continue> |
|||
</api></source>}} |
|||
{{ApiEx |
|||
| desc=Show a list of first 5 sysops |
|||
| p1= action=query |
|||
| p2= list=allusers |
|||
| p3= augroup=sysop |
|||
| p4= aulimit=5 |
|||
| result=<source lang="xml"> |
|||
<api> |
|||
<query> |
|||
<allusers> |
|||
<u userid="111640" name="(aeropagitica)" /> |
|||
<u userid="99351" name="23skidoo" /> |
|||
<u userid="3030741" name="28bytes" /> |
|||
<u userid="365061" name="2over0" /> |
|||
<u userid="7044616" name="5 albert square" /> |
|||
</allusers> |
|||
</query> |
|||
<query-continue> |
|||
<allusers aufrom="7" /> |
|||
</query-continue> |
|||
</api></source>}} |
|||
<!--T:14--> |
|||
== Error Codes == |
|||
* This API call is case sensitive, so <tvar name=1><code>aufrom=DROV</code></tvar> doesn't return the same results as <tvar name=2><code>aufrom=Drov</code></tvar>.</translate> |
|||
None |
|||
<translate> |
|||
<!--T:15--> |
|||
* All registered usernames are saved and retrieved in capitalized form.</translate> <translate><!--T:16--> If you are using <tvar name=1><code>aufrom</code></tvar> or <tvar name=2><code>auprefix</code></tvar> in your query, make sure you are passing them values that start with an uppercase character.</translate> |
|||
<translate> |
|||
<!--T:17--> |
|||
* Although the default behavior is to list any user in the database, we can also limit our response to only those users who belong to a certain group, such as sysops, or bots.</translate> <translate><!--T:18--> User groups are how MediaWiki grants users certain rights and privileges; see <tvar name=1>{{ll|Help:User rights and groups}}</tvar> for more details on how this system works.</translate> |
|||
<translate> |
|||
[[Category:MediaWiki API query lists|{{PAGENAME}}]] |
|||
== See also == <!--T:19--> |
|||
</translate> |
|||
* {{ll|API:Users}} - <translate><!--T:20--> finds information about a list of users.</translate> |
Latest revision as of 17:40, 29 August 2024
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.11 |
GET request to list all registered users, as ordered by username.
API documentation
[edit]
Example
[edit]GET request
[edit]GET request to list all users, starting from those whose name begins with the string, "Drov"
Response
[edit]{
"batchcomplete": "",
"continue": {
"aufrom": "Drovark",
"continue": "-||"
},
"query": {
"allusers": [
{
"userid": 13239275,
"name": "Drov"
},
{
"userid": 7080866,
"name": "Drova"
},
{
"userid": 16013473,
"name": "Drova 82"
},
...
]
}
}
Sample code
[edit]Python
[edit]#!/usr/bin/python3
"""
get_allusers.py
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name
begins with the string, 'Drov'.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "allusers",
"auprefix": "Drov"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
USERS = DATA["query"]["allusers"]
for user in USERS:
print(user["name"])
PHP
[edit]<?php
/*
get_allusers.php
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name begins with the string, 'Drov'.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "allusers",
"auprefix" => "Drov"
];
$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"]["allusers"] as $k => $v ) {
echo( $v["name"] . "\n" );
}
JavaScript
[edit]/*
get_allusers.js
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those whose name begins with the string, 'Drov'.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "allusers",
auprefix: "Drov"
};
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 users = response.query.allusers;
for (var u in users) {
console.log(users[u].name);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
[edit]/*
get_allusers.js
MediaWiki API Demos
Demo of `Allusers` module: Get all users, starting from those
whose name begins with the string, 'Drov'.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'allusers',
auprefix: 'Drov'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var users = data.query.allusers,
u;
for ( u in users ) {
console.log( users[ u ].name );
}
} );
Possible errors
[edit]Code | Info |
---|---|
augroup-excludegroup | group and excludegroup cannot be used together |
Parameter history
[edit]- v1.12: Introduced
auprop=registration
Additional notes
[edit]- This API call is case sensitive, so
aufrom=DROV
doesn't return the same results asaufrom=Drov
. - All registered usernames are saved and retrieved in capitalized form. If you are using
aufrom
orauprefix
in your query, make sure you are passing them values that start with an uppercase character. - Although the default behavior is to list any user in the database, we can also limit our response to only those users who belong to a certain group, such as sysops, or bots. User groups are how MediaWiki grants users certain rights and privileges; see Help:User rights and groups for more details on how this system works.
See also
[edit]- API:Users - finds information about a list of users.