API:Protectedtitles

MediaWiki version:
1.15

GET request to list titles protected from creation.

This module can be used as a generator .

API documentation

list=protectedtitles (pt)

(main | query | protectedtitles)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

List all titles protected from creation.

Specific parameters:
Other general parameters are available.
ptnamespace

Only list titles in these namespaces.

Values (separate with | or alternative): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 486, 487, 710, 711, 828, 829, 1198, 1199, 2600, 5500, 5501
To specify all values, use *.
ptlevel

Only list titles with these protection levels.

Values (separate with | or alternative): autoconfirmed, sysop
ptlimit

How many total pages to return.

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

In which direction to enumerate:

newer
List oldest first. Note: ptstart has to be before ptend.
older
List newest first (default). Note: ptstart has to be later than ptend.
One of the following values: newer, older
Default: older
ptstart

Start listing at this protection timestamp.

Type: timestamp (allowed formats)
ptend

Stop listing at this protection timestamp.

Type: timestamp (allowed formats)
ptprop

Which properties to get:

timestamp
Adds the timestamp of when protection was added.
user
Adds the user that added the protection.
userid
Adds the user ID that added the protection.
comment
Adds the comment for the protection.
parsedcomment
Adds the parsed comment for the protection.
expiry
Adds the timestamp of when the protection will be lifted.
level
Adds the protection level.
Values (separate with | or alternative): comment, expiry, level, parsedcomment, timestamp, user, userid
Default: timestamp|level
ptcontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.


Example

GET request

Get the first 2 titles only sysops can create.

Response

{
    "batchcomplete": "",
    "continue": {
        "ptcontinue": "20190520051937|118|Dj_Consequence",
        "continue": "-||"
    },
    "query": {
        "protectedtitles": [
            {
                "ns": 118,
                "title": "Draft:DJ Consequence",
                "timestamp": "2019-05-20T05:34:39Z",
                "level": "sysop"
            },
            {
                "ns": 0,
                "title": "DJ Consequence",
                "timestamp": "2019-05-20T05:20:31Z",
                "level": "sysop"
            }
        ]
    }
}

Sample code

Python

#This file is auto-generated. See modules.json and autogenerator.py for details

#!/usr/bin/python3

"""
    get_protectedtitles.py

    MediaWiki API Demos
    Demo of `Protectedtitles` module: Get the first 2 titles which only sysops can create

    MIT License
"""

import requests

S = requests.Session()

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

PARAMS = {
    "action": "query",
    "format": "json",
    "list": "protectedtitles",
    "ptlevel": "sysop",
    "ptlimit": "2"
}

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

PAGES = DATA["query"]["protectedtitles"]

for p in PAGES:
    print(p["title"])

PHP

<?php

//This file is autogenerated. See modules.json and autogenerator.py for details

/*
    get_protectedtitles.php

    MediaWiki API Demos
    Demo of `Protectedtitles` module: Get the first 2 titles which only sysops can create

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "list" => "protectedtitles",
    "ptlevel" => "sysop",
    "ptlimit" => "2"
];

$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"]["protectedtitles"] as $k => $v ) {
    echo( $v["title"] . "\n" );
}

JavaScript

//This file is autogenerated. See modules.json and autogenerator.py for details

/*
    get_protectedtitles.js

    MediaWiki API Demos
    Demo of `Protectedtitles` module: Get the first 2 titles which only sysops can create

    MIT License
*/

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

var params = {
    action: "query",
    format: "json",
    list: "protectedtitles",
    ptlevel: "sysop",
    ptlimit: "2"
};

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.protectedtitles;
        for (var p in pages) {
            console.log(pages[p].title);
        }
    })
    .catch(function(error){console.log(error);});

MediaWiki JS

// This file is autogenerated. See modules.json and autogenerator.py for details

/*
	get_protectedtitles.js

	MediaWiki API Demos
	Demo of `Protectedtitles` module: Get the first 2 titles which only sysops can create

	MIT License
*/

var params = {
		action: 'query',
		format: 'json',
		list: 'protectedtitles',
		ptlevel: 'sysop',
		ptlimit: '2'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	var pages = data.query.protectedtitles,
		p;
	for ( p in pages ) {
		console.log( pages[ p ].title );
	}
} );

Parameter history

  • v1.23: Introduced continue
  • v1.17: Introduced userid
  • v1.16: Introduced parsedcomment

See also