Page MenuHomePhabricator

Add a function for scripts to load/reload a statement for the current entity
Open, Needs TriagePublic

Description

There are a number of gadgets and user scripts which create or edit statements. These usually tell the user to refresh the page to see the updated data, or refresh the page automatically after editing, because there's no way for the scripts to do it themselves.

If the page is not reloaded, the user sees an outdated version of the entity, which can cause problems (e.g. adding duplicate statements because the existing one is not visible). If the page is reloaded, that involves a lot of requests to the servers which could be avoided and slows down the user who needs to wait for the page to load and render and then find their position on the page again before they can continue editing. Therefore it would be useful for scripts to be able to tell the page to update the things they have changed without requiring a full page reload.

It would be expected to behave something like this:

  • There should be a function which accepts at least one statement ID as a parameter.
  • Ideally it should allow an array of IDs so that it doesn't have to be called multiple times if multiple statements were added/edited.
  • It should check that the ID is for a statement on the current entity. If not, it should refuse to load it.
  • If the statement is not already loaded (i.e. a new statement was added), it should be added to the page.
  • If the statement is already loaded (i.e. an existing statement was edited), it should be updated to show the current state.
  • If the statement no longer exists (i.e. an existing statement was deleted), it should be removed from the page.
  • After adding/updating a statement, it should be possible to make further edits to it using the normal UI.
  • After adding/updating/removing a statement, statement-related hooks should be called (wikibase.statement.saved for adding/updating, wikibase.statement.removed for removing) so that code which reacts to statements being changed is run.