Page MenuHomePhabricator

Prefill input fields by URL parameter
Closed, ResolvedPublic5 Estimated Story Points

Description

As a Lexeme creator, when I visit the Create a new Lexeme page with some fields pre-filled from URL parameters I would like to have the form state filled with those parameters in order to save time for repeated Lexeme creation.

Problem:
We want to accept pre-filling some of the input fields via a URL parameter.

Example:
https://www.wikidata.org/wiki/Special:NewLexeme?lemma=foo

BDD
GIVEN a link to Special:NewLexeme including URL parameters encoding parts of the new Lexeme’s data
WHEN opening the link
THEN the input fields are populated from the URL parameters

Acceptance criteria:

  • input submitted via URL parameters is put in the input fields on page-load

Notes:

  • This works in the current Special Page and is used by templates to pre-fill the page for specific languages.
  • The parameter names should be the same as in the current implementation so existing links will continue to work.

Event Timeline

The No-JS version already supports this, presumably because we copied over the relevant code along with most of the rest of SpecialNewLexeme.php. We’ll have to implement it for the JS version, though.

Task Breakdown Notes:

  • The URL gets QIDs as values, but we will need to show Item labels in the lookup fields
  • In all the cases in the table below, we would like to figure out if the language code can be inferred.
  • We can already request the label and the language code (if it is associated with the language item) on the server side, will help us avoid an addition client side request(s)
  • When the Language Item is provided the lookup would be prefilled with the language label and when clicked a new search should be initiated with the text of the label.
  • What should happen if the language parameter is not a valid QID? @Lydia_Pintscher
  • What should happen if the spelling variant parameter is not a valid language code? @Lydia_Pintscher
  • The comparison of a language code value against a list of valid language code can be performed either in the server or client
CaseLanguage QID in URLSpelling Variant in URLLanguage Code of Item
1Englishenen
2Englishnlen
3English---en
4Dutchnl---
5Dutch------
6---nl---
  • In cases 1 and 3 the spelling variant field should not be shown
  • In case 2: How do we reconcile the difference between the language code in the URL and the one stated on the Item? @Lydia_Pintscher (Currently it uses the language code of the item, and ignores the spelling variant in the URL, without should any warning or the spelling variant field)
  • In cases 4 and 6 the spelling variant should be shown and have 'nl' preselected.
  • In case 5 only the language item should be preselected and the spelling variant field is shown.

Plan of Action:

  1. Get the information from the URL into the client (one way or another)
  2. Prefill the lemma from the URL parameters
  3. Fetch Labels in the server side, and include them in the client
  4. Attempt to prefill the lexical category
  5. Retrieve the language code for a language item if specified in the URL
  6. Prefill Lexeme language and spelling variant, consult the use cases above for possible combinations

As soon as the first step in the plan of action above is achieved, we can break off sub-tasks based on the steps in this comment, when they can already be picked up.

  • What should happen if the language parameter is not a valid QID? @Lydia_Pintscher
  • What should happen if the spelling variant parameter is not a valid language code? @Lydia_Pintscher

In both cases I'd say let's leave the field empty and basically ignore what is coming from the URL parameter.

  • In case 2: How do we reconcile the difference between the language code in the URL and the one stated on the Item? @Lydia_Pintscher

I'd let the URL parameter "win" in this case.

Change 790295 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/WikibaseLexeme@master] [PoC]: parse all url params on server

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

Change 790296 had a related patch set uploaded (by Michael Große; author: Michael Große):

[mediawiki/extensions/WikibaseLexeme@master] [PoC] parse only needed URL params on server

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

Change 790296 abandoned by Michael Große:

[mediawiki/extensions/WikibaseLexeme@master] [PoC] parse only needed URL params on server

Reason:

We decided to go with I65a73b0af5477ccf0da5170098617474957acabd

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