Page MenuHomePhabricator

🎲️ Modify item's site link data
Closed, ResolvedPublic13 Estimated Story Points

Description

As a tool builder I want to be able to edit sitelinks so that the work in my tool can be saved back to Wikidata.

PATCH /entities/items/{item_id}/sitelinks

Notes:

  • The request contains a JSON body with a mandatory patch key containing a JSON Patch document plus optional metadata: tags, bot, comment.
  • Response body containing the updated sitelinks data, using the similar structure as GET /entities/items/{item_id}/sitelinks.
  • Handle HTTP conditional request headers as in PUT .../sitelinks/{site_id}
  • Handle user authentication/authorization like in PUT .../sitelinks/{site_id}
  • All edit data is validated

Autocomments:

  • should mimic the behavior of wbeditentity when editing sitelinks
  • Automated edit summaries to be of the form: /* wbeditentity-update:0| */

Error cases considered:

HTTP response coderesponse payload
Item does not exist 404 "code": "item-not-found"
"message": "Could not find an item with the ID: {item_id}"
Invalid item ID 400 "code": "invalid-item-id"
"message": "Not a valid item ID: {item_id}"
"context": {"item": "{item-id}"}
Invalid edit tag400 { "code": "invalid-edit-tag", "message": "Invalid MediaWiki tag: {tag}" }
Comment too long400 {"code": "comment-too-long", "message": "Comment must not be longer than {limit} characters"}
Item with the provided ID has been redirected to another item409"code": "redirected-item"
"message": "Item {item_id} has been merged into {other_id}."
Invalid JSON patch (general error)400"code": "invalid-patch"
"message": "The provided patch is invalid"
incorrect JSON patch operation400"code": "invalid-patch-operation"
"message": "Incorrect JSON patch operation: '<op>'"
"context": { "operation": <operation_object> }
invalid field type in JSON patch
(either of op, path, from is not a string)
400"code": "invalid-patch-field-type"
"message": "The value of '<field>' must be of type string"
"context": { "operation": <operation_object>, "field": <field> }
missing mandatory field in JSON patch
(op, path, value, also from on copy/move patches)
400"code": "missing-json-patch-field"
"message": "Missing '<field>' in JSON patch"
"context": { "operation": <operation_object>, "field": <field> }
Target of JSON Patch not found on the object409"code": "patch-target-not-found",
"message": "Target '<target>' not found on the resource",
"context": {
"operation": <operation_object>,
"field": <path>
}
JSON Patch test operation failed409"code": "patch-test-failed",
"message": "Test operation in the provided patch failed. At path '{path}' expected '{expected}', actual: '{actual}'",
"context": {
"operation": <operation_object>,
"actual-value": <actual>
}
After applying a patch, invalid site ID is used422 {"code": "patched-sitelinks-invalid-site-id", "message": "Not a valid site ID {site_id} in patched sitelinks", "context": { "site_id": "{site_id}" } }
After applying a patch, no sitelink title provided422 {"code": "patched-sitelink-missing-title", "message": "No sitelink title provided for site {site_id} in patched sitelinks", "context": { "site_id": "{site_id}" } }
After applying a patch, sitelink title is empty422 {"code": "patched-sitelink-title-empty", "message": "Sitelink cannot be empty for site {site_id} in patched sitelinks", "context": { "site_id": "{site_id}" } }
After applying a patch, sitelink title is invalid422 {"code": "patched-sitelink-invalid-title", "message": "Invalid sitelink title {title} for site {site_id} in patched sitelinks", "context": { "site_id": "{site_id}", "title": "{title}" } }
After applying a patch, page with given title does not exist422 {"code": "patched-sitelink-title-does-not-exist", "message": "Incorrect patched sitelinks. Page with title {title} does not exist on site {site_id}", "context": { "site_id": "{site_id}", "title": "{title}" } }
After applying a patch, a sitelink badge value is not an item ID422 {"code": "patched-sitelink-invalid-badge", "message": "Incorrect patched sitelinks. Badge value {badge} for site {site_id} is not an item ID", "context": { "site_id": "{site_id}", "badge": "{badge}" } }
After applying a patch, the sitelink added to item is in conflict with another item 422{"code": "patched-sitelink-conflict", "message": "Site {site_id} is already being used on {other_item_id}", "context": {"matching-item-id": "{other_item_id}", "site": "{site_id}"}
After applying a patch, the URL is modified 422{"code": "url-not-modifiable", "message": "URL of sitelink cannot be modified","context": { "site": <site_id> }}
After applying a patch, a item used as a sitelink badge is not allowed as a badge422 {"code": "patched-sitelink-item-not-a-badge", "message": "Incorrect patched sitelinks. Item {badge} used for site {site_id} is not allowed as a badge", "context": { "site_id": "{site_id}", "badge": "{badge}" } }
After applying a patch, badges field is not a list422 {"code": "patched-sitelink-badges-format", "message": "Badges value for site {site_id} is not a list in patched sitelinks", "context": { "site_id": "{site_id}", "badges": "{badges}" } }

Additional notes:

Task breakdown:

  • Add endpoint to OpenAPI spec (O)
  • happy path (M)
    • Handle edit metadata (bot flag, tags)
    • feel free to use the request validation/deserialization but don't handle errors yet
  • Generate the expected edit summary (J)
  • Authorization (S)
  • Validate user input (the patch document, item id, edit metadata) (D)
  • Handle errors that occur while patching sitelinks (O)
  • Validate the patched sitelinks (M)
    • does not include sitelink conflict detection
  • Handle patched sitelinks conflicts (J)
  • Handle unexpected URL modification (url-not-modifiable) (S)
    • should be included in the post patch validation
    • validate and deserialize the sitelinks first and then compare the URLs in the (known to be valid!) patched serialization against the URLs in the original read model serialization
  • Respond 404/409 if item not found or redirected (D)
  • Use the usual middlewares (O)
  • Add OpenAPI validation test (M)
  • Mark PATCH sitelinks production ready (J)

Event Timeline

@WMDE-leszek I went to the sandbox to see what edit summaries I got with wbeditentity for the different cases of editing sitelinks and it always always gave me the summary I've now added in the ticket. I'm not sure whether there's a huge difference between it saying "/* wbeditentity-update:0| */" or just "/* wbeditentity:0| */" It doesn't say anything smart or specific based on what I ask it to do.

@WMDE-leszek I went to the sandbox to see what edit summaries I got with wbeditentity for the different cases of editing sitelinks and it always always gave me the summary I've now added in the ticket. I'm not sure whether there's a huge difference between it saying "/* wbeditentity-update:0| */" or just "/* wbeditentity:0| */" It doesn't say anything smart or specific based on what I ask it to do.

wbeditentity-update:0 sounds about right, apologies, my mistake

Jakob_WMDE renamed this task from Modify item's site link data to 🎲️ Modify item's site link data.Feb 6 2024, 2:00 PM

Helloo @Ifrahkhanyaree_WMDE and @WMDE-leszek

I'm currently working on the edit summaries in this story and found that those two sentences in the task description don't match the current use case:

where BADGE_ITEMS_FORMATTED is a comma-separated list of wikitext links to item pages
see Wikibase\Repo\ChangeOp\ChangeOpSiteLink class, and surrounding classes, for further details of the existing Wikibase automated edit summary logic

As I tried the way Jakob described to see the edit summaries and it's only /* wbeditentity-update:0| */ even if I added/modified sitelink's badges.

I think those sentences were copied by mistake from https://phabricator.wikimedia.org/T342987. Am I right?