API:Purge
| This page is part of the MediaWiki Action API documentation. |
| Please help improve this technical documentation! Take our MediaWiki Action API Technical Documentation User Feedback Survey before 6 January – Note: The survey uses Google Forms. See Privacy Statement – Thanks! |
| MediaWiki version: | ≥ 1.14 |
Contents
API documentation[edit]
|
action=purge(main | purge)
Purge the cache for the given titles. Parameters:
Examples:
|
Examples[edit]
Example 1: Purge one or two pages[edit]
POST Request[edit]
Response[edit]
{
"batchcomplete": "",
"purge": [
{
"ns": 0,
"title": "Main Page",
"purged": ""
},
{
"ns": 0,
"title": "Nonexistent",
"purged": ""
}
],
"normalized": [
{
"from": "Main_Page",
"to": "Main Page"
}
]
}
Sample code[edit]
purge_two_pages.py
#!/usr/bin/python3
"""
purge_two_pages.py
MediaWiki Action API Code Samples
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)
Example 2: Purge first 10 pages in the main namespace[edit]
POST Request[edit]
Response[edit]
{
"batchcomplete": "",
"continue": {
"gapcontinue": "!!Destroy-Oh-Boy!!",
"continue": "gapcontinue||"
},
"purge": [
{
"ns": 0,
"title": "!",
"purged": ""
},
{
"ns": 0,
"title": "!!",
"purged": ""
}
...
]
}
Sample code[edit]
purge_namespace_pages.py
#!/usr/bin/python3
"""
purge_namespace_pages.py
MediaWiki Action API Code Samples
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)
Possible errors[edit]
| Code | Info |
|---|---|
| cantpurge | Only users with the 'purge' right can purge pages via the API |
| mustbeposted | The purge module requires a POST request. |
| invalidreason | The requested page title contains invalid characters: "title". |
Parameter history[edit]
- v1.20: Introduced
page ID