API:Geschützte Titel
Appearance
Diese Seite ist Teil der Dokumentation der MediaWiki action API. |
MediaWiki Version: | ≥ 1.15 |
GET-Abfrage um vor Erstellung geschützte Seitentitel aufzulisten.
Dieses Modul kann als Generator benutzt werden.
API-Dokumentation
Beispiel
GET-Anfrage
Erhalte die ersten 2 Titel, die nur von Administratoren erstellt werden können.
api.php? action=query& format=json& list=protectedtitles& ptlevel=sysop [In der ApiSandbox ausprobieren]
Antwort
{
"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"
}
]
}
}
Beispielcode
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 );
}
} );
Parametergeschichte
- v1.23: Eingeführt
continue
- v1.17: Eingeführt
userid
- v1.16: Eingeführt
parsedcomment
Siehe auch
- API:Schützen - Den Schutzstatus einer Seite ändern