MediaWiki version:
1.23

GET request to view the list of logged-in contributors and the count of anonymous contributors to a page.

API documentation


Special:ApiHelp/query+contributors

Example

GET request

GET request to view the logged-in and anonymous contributors to a page.

Response

{
    "continue": {
        "pccontinue": "323710|1591",
        "continue": "||"
    },
    "query": {
        "pages": {
            "323710": {
                "pageid": 323710,
                "ns": 0,
                "title": "MediaWiki",
                "anoncontributors": 603,
                "contributors": [
                    {
                        "userid": 1,
                        "name": "Damian Yerrick"
                    },
                    {
                        "userid": 11,
                        "name": "Kpjas"
                    },
                    {
                        "userid": 43,
                        "name": "Lee Daniel Crocker"
                    },
                    ...
                ]
            }
        }
    }
}

Sample code

Python

#!/usr/bin/python3

"""
    get_contributors.py

    MediaWiki API Demos
    Demo of `Contributors` module: List all the logged-in contributors and count of anonymous 
    contributors to a page.

    MIT License
"""

import requests

S = requests.Session()

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

import requests

S = requests.Session()

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

PARAMS = {
    "action": "query",
    "titles": "MediaWiki",
    "prop": "contributors",
    "format": "json"
}

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

print(DATA)

PHP

<?php
/*
    get_contributors.php

    MediaWiki API Demos
    Demo of `Contributors` module: List all the logged-in contributors and count of anonymous 
    contributors to a page.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "titles" => "MediaWiki",
    "prop" => "contributors",
    "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

/*
    get_contributors.js

    MediaWiki API Demos
    Demo of `Contributors` module: Get request to list all logged-in contributors and count of anonymous contributors to a page.

    MIT License
*/

const fetch = require('node-fetch');
var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    titles: "MediaWiki",
    prop: "contributors",
    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) {
        var pages = response.query.pages;
        for (var page in pages) {
            console.log(pages[page].anoncontributors);
            console.log(pages[page].contributors);
        }    
    })
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	get_contributors.js

	MediaWiki API Demos
	Demo of `Contributors` module: List all the logged-in contributors and count of anonymous 
        contributors to a page.
	MIT License
*/

var params = {
		action: 'query',
		titles: 'MediaWiki',
		prop: 'contributors',
		format: 'json'
	},
	api = new mw.Api();

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

Additional notes

  • This module cannot be used as a generator.

See also

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