Extension:Proofread Page/Index data API
Appearance
The ProofreadPage extension provides read/write access to index categories and fields in both Wikitext and JSON[1]. Usually, for API access, JSON is easier.
Index field and category data is both stored in the main slot of an index page[2].
Note that while you can choose the content format, the content model of an index page is always proofread-index
.
Reading
[edit]Read the main slot content with action=parse
(see API:Parse), setting contentformat
as you wish:
- JSON:
application/json
(as of 29 Oct 2022, this is currently broken, see phab:T321446) - Wikitext:
text/x-wiki
(default if not given)
{
"action": "parse",
"format": "json",
"formatversion": 2,
"page": "Index:Sandbox.djvu",
"prop": "wikitext",
"contentformat": "application/json"
}
Response |
---|
{
"parse": {
"title": "Index:Sandbox.djvu",
"pageid": 3,
"wikitext": "{\"fields\":{\"Type\":\"book\",\"wikidata_item\":\"\",\"Title\":\"Pericles\",\"Language\":\"en\",\"Volume\":\"1\",\"Author\":\"[[Pericles]]\",\"Translator\":\"\",\"Editor\":\"Editor name\",\"Illustrator\":\"\",\"School\":\"\",\"Publisher\":\"\",\"Address\":\"\",\"Year\":\"\",\"Key\":\"\",\"ISBN\":\"\",\"OCLC\":\"\",\"LCCN\":\"\",\"BNF_ARK\":\"\",\"ARC\":\"\",\"Source\":\"_empty_\",\"Image\":\"1\",\"Progress\":\"X\",\"Pages\":\"<pagelist\\n1=Cover\\n2=1 \\/>\",\"Volumes\":\"\",\"Remarks\":\"\",\"Width\":\"\",\"Css\":\"\",\"Header\":\"\",\"Footer\":\"\"},\"categories\":[\"Other cat\"]}"
},
}
|
Specifically, the wikitext
field contains serialised JSON. You can deserialise this and manipulate it, then write it back.
Writing
[edit]This is done with the usual edit
action (see API:Edit).
{
"action": "edit",
"format": "json",
"formatversion": "2"
"title": "Index:Peri.djvu",
"text": "{\"fields\":{\"Type\":\"book\",\"wikidata_item\":\"\",\"Title\":\"Pericles\",\"Language\":\"en\",\"Volume\":\"1\",\"Author\":\"[[Pericles]]\",\"Translator\":\"\",\"Editor\":\"Editor name\",\"Illustrator\":\"\",\"School\":\"\",\"Publisher\":\"\",\"Address\":\"\",\"Year\":\"\",\"Key\":\"\",\"ISBN\":\"\",\"OCLC\":\"\",\"LCCN\":\"\",\"BNF_ARK\":\"\",\"ARC\":\"\",\"Source\":\"_empty_\",\"Image\":\"1\",\"Progress\":\"X\",\"Pages\":\"<pagelist\\n1=Cover\\n2=1 />\",\"Volumes\":\"\",\"Remarks\":\"\",\"Width\":\"\",\"Css\":\"\",\"Header\":\"\",\"Footer\":\"\"},\"categories\":[\"Other cat\"]}",
"contentformat": "application/json",
}
You will need to provide a valid token to perform any edit
action.
Response |
---|
{
"edit": {
"result": "Success",
"pageid": 3,
"title": "Index:Peri.djvu",
"contentmodel": "proofread-index",
"nochange": true,
"watched": true
},
}
|
Notes
[edit]- â From 1.38.wmf0 (phab:T291167)
- â Currently, it is stored as Wikitext, though this is an implementation detail - both JSON and Wikitext content formats are mapped to the internal format transparently.