Create new OOUI widget called `TemplateSearchWidget` for searching templates, with the same functionality as the merger of the existing template search fields in VisualEditor and TemplateWizard (i.e. CirrusSearch if available, prefix search if not).
The outcome of this will be a wrapper widget for a ComboBoxwidget that's equivalent to `ve.ui.MWTemplateTitleInputWidget that mixes in LookupElement` or `mw.TemplateWizard.SearchField`. Note that although we could subclass the formerbe creating a single-input widget like these are, we don't want to because we'll be adding more functionality to the TemplateSearchWidget (such as a tab bar under the search input) that'll mean it's probably easier to have a general Widget.
This task does not include actually using this new widget anywhere. We will want to add it somewhere for testing though (so please update this description when that's figured out).
##Existing search logic
TemplateWizard searches with a `prefixsearch` generator:
```
action=templatedata
includeMissingTitles=1
generator=prefixsearch
gpssearch=mytpl
gpsnamespace=10
gpslimit=10The new widget will be added in two subsequent tasks:
redirects=1* {T377416}
```* {T377417}
Whereas VE uses a `search` generator (in addition to prefixs##Search; clarity needed about why it makes the prefixsearch request): logic
```
action=query
prop=info|pageprops
generator=search
ppprop=disambiguation
redirects=true
gsrsearch=mytpl*
gsrnamespace=10
gsrlimit=10
gsrprop=redirecttitle
```The new widget will follow the existing search logic of the two systems (they should be referred to for actual details), and their behaviour is the same. the general approach is as follows (in both the below cases, the search is limited to the Template namespace, ID 10; this can be changed in config, but it doesn't look like it ever is):
```
action=query
format=json
formatversion=2
generator=prefixsearch
gpssearch=mytpl
gpsnamespace=10
gpslimit=10* Without CirrusSearch installed:
* A [[https://www.mediawiki.org/wiki/API:Prefixsearch | prefixsearch]].
``` * Followed by a [[https://www.mediawiki.org/wiki/Extension:TemplateData#API | templatedata]] request to get the template metadata (i.e. the descriptions).
Then w* With the results of that, it fetches the templatedata:CirrusSearch installed:
```
action=templatedata
titles=Template:Template1|Template:Template2|(lots more here…) * If the search term ends in an alphanumeric character, a [[https://www.mediawiki.org/wiki/Help:CirrusSearch#Words,_phrases,_and_modifiers | wildcard suffix]] search if run; otherwise it's a normal [[https://www.mediawiki.org/wiki/API:Search | search]].
includeMissingTitles=1 * A [[https://www.mediawiki.org/wiki/API:Prefixsearch | prefixsearch]] is also run, to make sure it finds any exact prefix matches.
``` * The results of these are combined.
Both are followed by a [[https://www.mediawiki.org/wiki/Extension:TemplateData#API | templatedata]] request to get the template metadata (i.e. the descriptions).
Note that TemplateWizard does combine parts of this as a generator, but we'll follow the VisualEditor approach here in order to keep the latter templatedata-fetching step simpler and separate.
##Widget design
Neither search input debounces, but rather send API requests on every keystroke. TemplateWizard aborts on subsequent ones;This task doesn't include any special design for the autocomplete field, VisualEditor doesn'tit'll be a standard OOUI LookupElement displaying a title and description (and no image).
Neither search input debounces, but rather send API requests on every keystroke. TemplateWizard aborts on subsequent ones; VisualEditor doesn't. Aborting would