As a Contributor, I want to update a page, so that I can include more information or restructure the content.
PUT /page/{title}
Creates a new page or updates an existing page.
Notable request headers: none
Payload: JSON
- source: source code (usually wikitext) of page
- comment: summary of the update, to be set for the new revision
- latest: object with the following element
- id: ID of the revision this new source was based on; will be used for a three-way merge if applicable. If not present, treat like creating a new page
- content_model: content model of the main slot of the page; defaults to 'wikitext' for new pages or existing content model for updates to pages
- csrf_token: Optional CSRF token; required when using Cookie authentication; otherwise forbidden
Status:
200 – it worked
401 – not authenticated
403 – not authorized
404 - no such page (only if revision ID was submitted)
409 – a page with that title already exists (if no revision ID was submitted)
409 - the page has been edited since the revision provided, and an automatic merge failed (see below)
500 - server error, such as when a three-way merge failed
Notable response headers: none
Body: JSON
- id: numeric id of the page
- key: prefixed DB key of the page, like "Talk:Main_Page"
- title: title for display, like "Talk:Main Page"
- latest: latest revision of the page, object with these properties
- id: revision ID
- timestamp: revision timestamp
- license: Object for the preferred license of the page, including these properties:
- spdx: SPDX code
- url: URL for the license
- title: title of the license
- other_licenses: array of objects with {spdx, url, title} for other licenses the page is available under
- content_model: content model of the main slot of the page
- source: preferred source of the page; usually wikitext
Edit conflicts
If the client tries to create a page that already exists by leaving latest empty, there's a conflict.
To update a page, the client needs to submit the ID of the last revision it's seen. That provides a base revision. If there have been other revisions since that revision (while the user was editing, for example), the system should make an effort to automatically do a 3-way merge of the submitted changes.
If the 3-way merge fails, the error code should be 409 (conflict), and the body should be a regular error, but with the following additional properties:
- base: revision ID of the base revision
- local: the difference between the wikitext submitted and the base revision, in the same JSON diff format as T231347
- remote: the difference between the latest revision of the page and the base revision, in the same JSON diff format as T231347
Clients can use this response data to present a 3-way merge resolution UI to the end user if needed.