Page MenuHomePhabricator

Validate that lexeme language and lexical category, as well as form grammatical features, are existing items
Closed, ResolvedPublic5 Story Points

Description

As a Wikidata editor, I rely on Wikibase to enforce that certain invalid edits cannot be made.

Problem:
Currently, the language and lexical category of a lexeme and the grammatical features of a form can be set to nonexisting items via the API. For the lexeme features, this is visible in the following code:

new LexicalCategoryChangeOpDeserializer(
	new CompositeValidator( [] ), // FIXME: What does belong here?
	$wikibaseRepo->getStringNormalizer()
),
new LanguageChangeOpDeserializer(
	new CompositeValidator( [] ), // FIXME: What does belong here?
	$wikibaseRepo->getStringNormalizer()
),

Those CompositeValidators are supposed to contain at least one validator which checks that the item ID exists. For form grammatical features, I don’t even see a place where such validators are currently wired up, so that probably needs to be added somewhere (most likely in EditFormChangeOpDeserializer).

This is not a critical problem because Wikibase and WikibaseLexeme can deal with such entities (the item IDs are displayed like deleted items), but still, we should probably prevent this.

Example:
testwikidata:L:L132 was created with the following JSON:

{
  "lemmas": {
    "en": { "language": "en", "value": "test lexeme with non-existing items" }
  },
  "language": "Q99999999",
  "lexicalCategory": "Q99999999",
  "forms": [
    {
      "add": 1,
      "representations": {
        "en": { "language": "en", "value": "test form with non-existing item" }
      },
      "grammaticalFeatures": ["Q99999999"]
    }
  ]
}

BDD
GIVEN The item Q99999999 does not exist
WHEN I try to create a lexeme with the language Q99999999
OR I try to create a lexeme with the lexical category Q99999999
OR I try to create a form with the grammatical feature Q99999999
OR I try to edit an existing entity in such a fashion
THEN the API returns an error
AND no edit is performed

Acceptance criteria:

  • The API does not permit edits referring to nonexisting item IDs
  • The UI does not permit them either (it already doesn’t, but just to make sure)

Patch-For-Review

Details

Related Gerrit Patches:

Event Timeline

Addshore triaged this task as Medium priority.Nov 20 2018, 8:00 AM
Addshore set the point value for this task to 5.Nov 20 2018, 2:15 PM

Change 475004 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/extensions/WikibaseLexeme@master] Validate that lexeme language and lexical category are existing items

https://gerrit.wikimedia.org/r/475004

This patch only covers lexeme language and lexical category. Now I'm working on to get grammatical features working.

Change 475012 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/extensions/WikibaseLexeme@master] Add EntityExistsValidator to EditFormChangeOpDeserializer for grammatical features

https://gerrit.wikimedia.org/r/475012

Addshore moved this task from incoming to in progress on the Wikidata board.Nov 21 2018, 8:19 AM

Change 475012 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Add EntityExistsValidator to EditFormChangeOpDeserializer for grammatical features

https://gerrit.wikimedia.org/r/475012

Lucas_Werkmeister_WMDE updated the task description. (Show Details)

Change 475004 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Validate that lexeme language and lexical category are existing items

https://gerrit.wikimedia.org/r/475004

Addshore closed this task as Resolved.Jan 7 2019, 6:42 PM
Addshore claimed this task.
Restricted Application added a project: User-Addshore. · View Herald TranscriptJan 7 2019, 6:42 PM