API:Purge
Appearance
Bu sayfa MediaWiki Eylem API'si belgelerinin bir parçasıdır. |
MediaWiki sürümü: | ≥ 1.14 |
POST isteği verilen başlık için önbelleği temizler.
API belgesi
Örnekler
Örnek 1: Bir veya iki sayfayı temizle
POST isteği
Yanıt
{
"batchcomplete": "",
"purge": [
{
"ns": 0,
"title": "NonexistentArticle",
"missing": ""
},
{
"ns": 0,
"title": "Main Page",
"purged": ""
}
],
"normalized": [
{
"from": "Main_Page",
"to": "Main Page"
}
]
}
Örnek kod
Python
#!/usr/bin/python3
"""
purge_two_pages.py
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge two or more pages
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "purge",
"titles": "Main_Page|Nonexistent",
"format": "json"
}
R = S.post(url=URL, params=PARAMS)
DATA = R.text
print(DATA)
PHP
<?php
/*
purge_two_pages.php
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge two or more pages
MIT license
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
purge();
function purge() {
global $endPoint;
$params = [
"action" => "purge",
"titles" => "Main_Page|Nonexistent",
"format" => "json"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endPoint );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo ( $output );
}
JavaScript
/*
purge_two_pages.js
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge two or more pages
MIT license
*/
var request = require('request').defaults({jar: true}),
url = "https://en.wikipedia.org/w/api.php";
function purge() {
var params = {
action: "purge",
titles: "Main_Page|Nonexistent",
format: "json"
};
request.post({ url: url, form: params }, function (error, res, body) {
if (error) {
return;
}
console.log(body);
});
}
// Start the function
purge();
MediaWiki JS
/*
purge_two_pages.js
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge two or more pages
MIT License
*/
var params = {
action: 'purge',
titles: 'Main_Page|Nonexistent',
format: 'json'
},
api = new mw.Api();
api.post( params ).done( function ( data ) {
console.log( data );
} );
Örnek 2: Ana ad alanındaki ilk 10 sayfayı temizleyin
POST isteği
Yanıt
{
"batchcomplete": "",
"continue": {
"gapcontinue": "!!Destroy-Oh-Boy!!",
"continue": "gapcontinue||"
},
"purge": [
{
"ns": 0,
"title": "!",
"purged": ""
},
{
"ns": 0,
"title": "!!",
"purged": ""
}
...
]
}
Örnek kod
Python
#!/usr/bin/python3
"""
purge_namespace_pages.py
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge first 10 pages in the main namespace
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "purge",
"generator": "allpages",
"gapnamespace": "0",
"gaplimit": "10",
"format": "json"
}
R = S.post(url=URL, params=PARAMS)
DATA = R.text
print(DATA)
PHP
<?php
/*
purge_namespace_pages.php
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge first 10 pages in the main namespace
MIT license
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
purge();
function purge() {
global $endPoint;
$params = [
"action" => "purge",
"generator" => "allpages",
"gapnamespace" => "0",
"gaplimit" => "10",
"format" => "json"
];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endPoint );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo ( $output );
}
JavaScript
/*
purge_namespace_pages.js
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge first 10 pages in the main namespace
MIT license
*/
var request = require('request').defaults({jar: true}),
url = "https://test.wikipedia.org/w/api.php";
function purge() {
var params = {
action: "purge",
generator: "allpages",
gapnamespace: "0",
gaplimit: "10",
format: "json"
};
request.post({ url: url, form: params }, function (error, res, body) {
if (error) {
return;
}
console.log(body);
});
}
// Start the function
purge();
MediaWiki JS
/*
purge_namespace_pages.js
MediaWiki API Demos
Demo of `purge` module: Sending post request to purge first 10 pages in the main namespace
MIT License
*/
var params = {
action: 'purge',
generator: 'allpages',
gapnamespace: '0',
gaplimit: '10',
format: 'json'
},
api = new mw.Api();
api.post( params ).done( function ( data ) {
console.log( data );
} );
Olası hatalar
Kod | Bilgi |
---|---|
cantpurge | Yalnızca 'purge' hakkına sahip kullanıcılar API aracılığıyla sayfaları temizleyebilir |
mustbeposted | purge modülü bir POST isteği gerektirir. |
invalidreason | İstenen sayfa başlığı geçersiz karakter içeriyor: "title". |
assertuserfailed | Oturumunuz kapandı, bu nedenle işlem tamamlanamadı. |
readonly | Veritabanı kilitlendi |
Parametre geçmişi
- v1.20:
pageid
tanıtıldı