Page MenuHomePhabricator

[MEX] M5 - Replace ActionAPI `wbeditentity` call with REST API PATCH request
Open, Needs TriagePublic

Description

We currently use the Action API to make changes to Wikidata from the MEX / wbui2025 interface.

Since the REST API is being actively developed by the reuse team and has the item editing functionality we need, it would make sense to use the REST API.

Port the existing wbeditentity call to use the REST API

Acceptance Criteria

  • The REST API is used by MEX/wbui2025 to make changes to Wikidata, instead of the Action API

Event Timeline

The api.postWithEditTokencall in line 26 of https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase/+/de96a53e5788a14194ec24bdda1f8351ba1bf719/repo/resources/wikibase.wbui2025/api/editEntity.js#26 would likely be replaced with something like

restApi.ajax(
	'/wikibase/v1/entities/items/' + entityId,
	{
		method: 'PATCH',
		contentType: 'application/json-patch+json',
		data: JSON.stringify(
			{"patch": [
				{
					"op": "replace",
					"path": "/statements",
					"value": statements
				}
			] }
		)
	}
)

For illustrative purposes, example Wikibase REST API call updating statements of item Q421 on Beta Wikidata

restClient = new mw.Rest();
restClient.ajax(
	'/wikibase/v1/entities/items/Q421',
	{
		method: 'PATCH',
		contentType: 'application/json-patch+json',
		data: JSON.stringify(
			{"patch": [
				{
					"op": "replace",
					"path": "/statements",
					"value": {
						"P694": [
							{"property": {"id": "P694"}, "value": {"type":"value", "content": "Q64" } },
							{"property": {"id": "P694"}, "value": {"type":"value", "content": "Q123" } }
						]
					}
				}
			] }
		)
	}
).done(
	function(data) {
		console.log(data)
	}
).fail(
	function( jqXHR, textStatus, errorThrown ) {
		console.log('error')
	}
);

Note: Wikibase REST API uses simpler JSON representation of item/property data, including how statements are represented in JSON. Differences from the JSON structure used e.g. in Action API have been outlined in https://doc.wikimedia.org/Wikibase/master/php/rest_data_format_differences.html - the frontend logic would like need to transform the statement data to a fitting JSON representation if it uses the Action-API-style JSON.

task time nov 25: this is a topic we should tackle as part of a larger inclusion on the restapi into wbui2025. will remove from M3

Arian_Bozorg renamed this task from [MEX] 3.2.2 Replace ActionAPI `wbeditentity` call with REST API PATCH request to [MEX] M5 - Replace ActionAPI `wbeditentity` call with REST API PATCH request.Jan 23 2026, 1:17 AM