Page MenuHomePhabricator

[L] Take over the skin search input widget to submit to Special:MediaSearch
Closed, ResolvedPublic

Description

The top-right (in Vector) search widget is a pretty simple form that submits to Special:Search.
We would need that to submit to Special:MediaSearch, with the correct params.
This means:

  • The target of the form (or rather, the value title) must become Special:MediaSearch
  • The search input field must change from "search" to "q" (or alternatively, Special:MediaSearch must change from "q" to "search" - whichever makes most sense)

At first sight, it looks like the form(s) are in:

  • /includes/skins/templates/fallback/skin.mustache (default)
  • /skins/Vector/includes/templates/SearchBox.mustache (Vector)
  • Possibly other files for other skins

Given how they're spread across multiple files, I suspect we won't want to change their markup. Odds are also pretty good that there are assumptions in scripts (extensions, gadgets...)

The data for the form, however, seems to come from /includes/skins/SkinMustache.php, in a method called buildSearchProps, which is called from getTemplateData.
It seems like this is where we'll want to make the requisite changes, except that there doesn't (at first sight) appears to be an easy way to get in there.
Suggestion (in case there is in fact no existing way to modify from the outside): hooks also seem to be the de facto way to customize skins, judging from the amount of hooks already in Skin.php. It should be fairly easy to add a hook there, which WikibaseMediaInfo (or MediaSearch) can then hook into to override the target & search field.

Here is where we'll have to figure out what to do with the "search" or "q" field.
From this same place in the code, we could easily swap out the "search" input for "q", but other code might depend on this thing being called "q".
I'd be quite surprised if that were the case, but if so, we'll either have to start adjusting those - or simply fall back to updating Special:MediaSearch to operate on another query param...

Acceptance criteria:

  • The top-right search (in Vector skin) search widget must, when filled in & submitted, kick of the search in Special:MediaSearch
  • The top-left search (in Monobook skin) search widget must, when filled in & submitted, kick of the search in Special:MediaSearch
  • Autocomplete etc. (e.g. prefix searches, see T240404) must continue to work as they always did
  • The files depicting... feature is removed (see T273880)
  • Respect the preference set up in T273979

Event Timeline

matthiasmullie renamed this task from Take over the skin search input widget to Take over the skin search input widget to submit to Special:MediaSearch.Feb 4 2021, 1:10 PM

@ovasileva here is our task to update the search bar to point to Special:MediaSearch. We're currently aiming for end of March 2021.

CBogen renamed this task from Take over the skin search input widget to submit to Special:MediaSearch to [L] Take over the skin search input widget to submit to Special:MediaSearch.Feb 9 2021, 5:24 PM

The data for the form, however, seems to come from /includes/skins/SkinMustache.php, in a method called buildSearchProps, which is called from getTemplateData.
It seems like this is where we'll want to make the requisite changes, except that there doesn't (at first sight) appears to be an easy way to get in there.

I spoke with @Cparle about this and said that I'd add a comment with my thoughts for posterity. So…

Broadly speaking, I'm not a fan of adding more hooks but there's a case to be made in this instance. Alternatively, you could:

  • The search URL could be a configuration variable, which could be overridden in the usual way
  • The search URL could be a member variable on SkinMustache complete with getter/setter, which you could set in a RequestContextCreateSkin hook handler

Come to think of it, it's a little odd that the search path/URL isn't a config variable like wgScript, wgScriptPath, wgArticlePath, wgCookiePath, etc.

Some explanation of the patch in core:

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/670493

I made this change to falling back to Special:Search based on 'search' being in the request params

image.png (585×886 px, 150 KB)

I did it this way because the top-right search form and the Special:Search pages both have 'search' as form inputs, and we want the behaviour to be different for each form. Changing the fallback via hook or via config means it can't be

Change 670493 had a related patch set uploaded (by Cparle; owner: Cparle):
[mediawiki/core@master] Allow top-right search form target to be modifiable

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

Change 670507 had a related patch set uploaded (by Cparle; owner: Cparle):
[mediawiki/extensions/WikibaseMediaInfo@master] Allow searching from the top-right search bar to target Special:MediaSearch

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

Change 670493 had a related patch set uploaded (by Cparle; owner: Cparle):
[mediawiki/core@master] Allow top-right search form target to be modifiable

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

Change 670493 merged by jenkins-bot:
[mediawiki/core@master] Allow top-right search form target to be modifiable

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

Change 670507 merged by jenkins-bot:
[mediawiki/extensions/WikibaseMediaInfo@master] Allow searching from the top-right search bar to target Special:MediaSearch

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

Etonkovidova added a subscriber: Etonkovidova.
  • The target of the form (or rather, the value title) must become Special:MediaSearch
  • The search input field must change from "search" to "q" (or alternatively, Special:MediaSearch must change from "q" to "search" - whichever makes most sense)

The "q" for Special:MediaSearch is replaced with "search" -
https://commons.wikimedia.org/w/index.php?title=Special:MediaSearch&search=korat+cat&go=Go&type=image
compare with
https://commons.wikimedia.org/w/index.php?title=Special%3ASearch&search=korat+cat&go=Go&ns0=1&ns6=1&ns12=1&ns14=1&ns100=1&ns106=1

Moving to Verify on Production to check along with T273979 and T273880.

Checked in commons wmf.37 - all is in place.