Jump to content

API:Allusers: Difference between revisions

From mediawiki.org
Content deleted Content added
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

MediaWiki version:
1.11

GET request to list all registered users, as ordered by username.

API documentation

[edit]

list=allusers (au)

(main | query | allusers)

Enumerate all registered users.

Specific parameters:
Other general parameters are available.
aufrom

The username to start enumerating from.

auto

The username to stop enumerating at.

auprefix

Search for all users that begin with this value.

audir

Direction to sort in.

One of the following values: ascending, descending
Default: ascending
augroup

Only include users in the given groups. Does not include implicit or auto-promoted groups like *, user, or autoconfirmed.

Values (separate with | or alternative): accountcreator, autopatrolled, bot, bureaucrat, checkuser, checkuser-temporary-account-viewer, confirmed, flow-bot, import, interface-admin, ipblock-exempt, no-ipinfo, steward, suppress, sysop, translationadmin, transwiki, uploader
auexcludegroup

Exclude users in the given groups.

Values (separate with | or alternative): accountcreator, autopatrolled, bot, bureaucrat, checkuser, checkuser-temporary-account-viewer, confirmed, flow-bot, import, interface-admin, ipblock-exempt, no-ipinfo, steward, suppress, sysop, translationadmin, transwiki, uploader
aurights

Only include users with the given rights. Does not include rights granted by implicit or auto-promoted groups like *, user, or autoconfirmed.

Values (separate with | or alternative): abusefilter-access-protected-vars, abusefilter-bypass-blocked-external-domains, abusefilter-hidden-log, abusefilter-hide-log, abusefilter-log, abusefilter-log-detail, abusefilter-log-private, abusefilter-modify, abusefilter-modify-blocked-external-domains, abusefilter-modify-global, abusefilter-modify-restricted, abusefilter-privatedetails, abusefilter-privatedetails-log, abusefilter-protected-vars-log, abusefilter-revert, abusefilter-view, abusefilter-view-private, apihighlimits, applychangetags, autoconfirmed, autocreateaccount, autopatrol, autoreview, autoreviewrestore, badcaptcha, badoath, bigdelete, block, blockemail, bot, browsearchive, centralauth-createlocal, centralauth-lock, centralauth-merge, centralauth-rename, centralauth-suppress, centralauth-unmerge, changeemail, changetags, checkuser, checkuser-log, checkuser-temporary-account, checkuser-temporary-account-log, checkuser-temporary-account-no-preference, collectionsaveascommunitypage, collectionsaveasuserpage, confirmemail, createaccount, createpage, createtalk, delete, delete-redirect, deletechangetags, deletedhistory, deletedtext, deletelogentry, deleterevision, echo-create, edit, editautopatrolprotected, editautoreviewprotected, editcontentmodel, editeditorprotected, editextendedsemiprotected, editinterface, editmyoptions, editmyprivateinfo, editmyusercss, editmyuserjs, editmyuserjson, editmyuserjsredirect, editmywatchlist, editprotected, editsemiprotected, editsitecss, editsitejs, editsitejson, edittrustedprotected, editusercss, edituserjs, edituserjson, enrollasmentor, extendedconfirmed, flow-create-board, flow-delete, flow-edit-post, flow-edit-title, flow-hide, flow-lock, flow-suppress, globalblock, globalblock-exempt, globalblock-whitelist, globalgroupmembership, globalgrouppermissions, hideuser, import, importupload, ipblock-exempt, ipinfo, ipinfo-view-basic, ipinfo-view-full, ipinfo-view-log, linkpurge, lqt-merge, lqt-react, lqt-split, mailpassword, manage-all-push-subscriptions, managechangetags, managementors, markbotedits, massmessage, mergehistory, minoredit, move, move-categorypages, move-rootuserpages, move-subpages, movefile, movestable, mwoauthmanageconsumer, mwoauthmanagemygrants, mwoauthproposeconsumer, mwoauthsuppress, mwoauthupdateownconsumer, mwoauthviewprivate, mwoauthviewsuppressed, newsletter, newsletter-announce, newsletter-create, newsletter-delete, newsletter-manage, newsletter-restore, nominornewtalk, noratelimit, nuke, oathauth-api-all, oathauth-disable-for-user, oathauth-enable, oathauth-verify-user, oathauth-view-log, override-antispoof, override-export-depth, pagelang, pagetranslation, patrol, patrolmarks, protect, purge, read, renameuser, renderfile, renderfile-nonstandard, reupload, reupload-own, reupload-shared, review, rollback, sboverride, securepoll-create-poll, securepoll-edit-poll, securepoll-view-voter-pii, sendemail, setmentor, sfsblock-bypass, siteadmin, skipcaptcha, spamblacklistlog, stablesettings, stashbasehtml, stashedit, suppressionlog, suppressredirect, suppressrevision, tboverride, tboverride-account, templateeditor, thanks-notification, titleblacklistlog, torunblocked, transcode-reset, transcode-status, translate, translate-groupreview, translate-import, translate-manage, translate-messagereview, unblockself, undelete, unfuzzy, unreviewedpages, unwatchedpages, upload, upload_by_url, urlshortcode, urlshortener-create-url, urlshortener-manage-url, urlshortener-view-log, userrights, userrights-interwiki, validate, viewdeletedfile, viewmyprivateinfo, viewmywatchlist, viewsuppressed
Maximum number of values is 50 (500 for clients that are allowed higher limits).
auprop

Which pieces of information to include:

blockinfo
Adds the information about a current block on the user.
groups
Lists groups that the user is in. This uses more server resources and may return fewer results than the limit.
implicitgroups
Lists all the groups the user is automatically in.
rights
Lists rights that the user has.
editcount
Adds the edit count of the user.
registration
Adds the timestamp of when the user registered if available (may be blank).
centralids
Adds the central IDs and attachment status for the user.
Values (separate with | or alternative): blockinfo, centralids, editcount, groups, implicitgroups, registration, rights
aulimit

How many total usernames to return.

Type: integer or max
The value must be between 1 and 500.
Default: 10
auwitheditsonly

Only list users who have made edits.

Type: boolean (details)
auactiveusers

Only list users active in the last 30 days.

Type: boolean (details)
auattachedwiki

With auprop=centralids, also indicate whether the user is attached with the wiki identified by this ID.

auexcludenamed

Exclude users of named accounts.

Type: boolean (details)
auexcludetemp

Exclude users of temporary accounts.

Type: boolean (details)


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 as aufrom=Drov.
  • All registered usernames are saved and retrieved in capitalized form. If you are using aufrom or auprefix 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.