API:Protectedtitles
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.15 |
GET request to list titles protected from creation.
This module can be used as a generator .
API documentation
edit
Example
editGET request
editGet the first 2 titles only sysops can create.
Response
edit{
"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
editPython
edit#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
edit<?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
edit//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
edit// 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
edit- v1.23: Introduced
continue
- v1.17: Introduced
userid
- v1.16: Introduced
parsedcomment
See also
edit- API:Protect - Change a page's protection level.