Extension:ProofreadPage/Index data API

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.

ReadingEdit

Read the main slot content with action=parse (see API:Parse), setting contentformat as you wish:

  • JSON: application/json
  • Wikitext: text/x-wiki (default if not given)
{
	"action": "parse",
	"format": "json",
    "formatversion": 2,
	"page": "Index:Sandbox.djvu",
	"prop": "wikitext",
	"contentformat": "application/json"
}

Example: https://en.wikisource.org/w/api.php?action=parse&format=json&formatversion=2&page=Index%3ASandbox.djvu&prop=wikitext&contentformat=application%2Fjson

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.

WritingEdit

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
    },
}

NotesEdit

  1. From 1.38.wmf0 (phab:T291167)
  2. 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.