MediaWiki version:
1.11

GET request to return information about the currently logged-in user.

API documentation


Special:ApiHelp/query+userinfo

Example

GET request

Get general user info and user rights.

Response

{
    "batchcomplete": "",
    "query": {
        "userinfo": {
            "id": 37494596,
            "name": "Zaycodes",
            "groups": [
                "*",
                "user"
            ],
            "rights": [
                "createaccount",
                "read",
                "edit",
                "createtalk",
                "writeapi",
                "viewmywatchlist",
                "editmywatchlist",
                "viewmyprivateinfo",
                "editmyprivateinfo",
                ...
            ]
        }
    }

Sample code

Python

#!/usr/bin/python3

"""
    userinfo.py
    MediaWiki API Demos
    Demo of `Userinfo` module: Get general user info and user rights
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "query",
    "meta": "userinfo",
    "uiprop": "rights",
    "format": "json"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)

PHP

<?php

/*
    userinfo.php
    MediaWiki API Demos
    Demo of `Userinfo` module: Get general user info and user rights
    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "meta" => "userinfo",
    "uiprop" => "rights",
    "format" => "json"
];

$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 );
var_dump( $result );

JavaScript

/*
    userinfo.js
    MediaWiki API Demos
    Demo of `Userinfo` module: Get general user info and user rights
    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    meta: "userinfo",
    uiprop: "rights",
    format: "json"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {console.log(response);})
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	userinfo.js
	MediaWiki API Demos
	Demo of `Userinfo` module: Get general user info and user rights
	MIT License
*/

var params = {
	action: 'query',
	meta: 'userinfo',
	uiprop: 'rights',
	format: 'json'
};
var api = new mw.Api();

api.get( params ).then( function ( data ) {
	console.log( data );
} );

Parameter history

  • v1.33: Introduced latestcontrib
  • v1.24: Introduced unreadcount
  • v1.18: Introduced implicitgroups, registrationdate, realname
  • v1.17: Introduced acceptlang
  • v1.16: Introduced changeablegroups
  • v1.15: Introduced email
  • v1.14: Introduced preferencestoken
  • v1.12: Introduced ratelimits, editcount

Additional notes

  • The code for the userinfo function is located at ApiQueryUserInfo.php.
  • If you need access to user information not listed here for a user on a Wikimedia project, please email privacy@wikimedia.org for further assistance.

See also

  • API:Users - for getting information about other users.
This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.