diff --git a/includes/Constants.php b/includes/Constants.php index f8d1446..0e3d378 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -133,6 +133,31 @@ final class Constants { */ public const QUERY_PARAM_SKIN_VERSION = 'useskinversion'; + /** + * The `mediawiki.searchSuggest` protocol piece of the SearchSatisfaction instrumention reads + * the value of an element with the "data-search-loc" attribute and set the event's + * `inputLocation` property accordingly. + * + * When the search widget is moved as part of the "Search 1: Search widget move" feature, the + * "data-search-loc" attribute is set to this value. + * + * See also: + * - https://www.mediawiki.org/wiki/Reading/Web/Desktop_Improvements/Features#Search_1:_Search_widget_move + * - https://phabricator.wikimedia.org/T261636 and https://phabricator.wikimedia.org/T256100 + * - https://gerrit.wikimedia.org/g/mediawiki/core/+/61d36def2d7adc15c88929c824b444f434a0511a/resources/src/mediawiki.searchSuggest/searchSuggest.js#106 + * + * @var string + */ + public const SEARCH_BOX_INPUT_LOCATION_MOVED = 'header-moved'; + + /** + * Similar to `Constants::SEARCH_BOX_INPUT_LOCATION_MOVED`, when the search widget hasn't been + * moved, the "data-search-loc" attribute is set to this value. + * + * @var string + */ + public const SEARCH_BOX_INPUT_LOCATION_DEFAULT = 'header-navigation'; + /** * This class is for namespacing constants only. Forbid construction. * @throws FatalError diff --git a/includes/SkinVector.php b/includes/SkinVector.php index a97eeea..30fd3d5 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -122,6 +122,11 @@ class SkinVector extends SkinMustache { // From Skin::getNewtalks(). Always returns string, cast to null if empty. $newTalksHtml = $skin->getNewtalks() ?: null; + $isSearchInHeader = $featureManager->isFeatureEnabled( Constants::FEATURE_SEARCH_IN_HEADER ); + $inputLocation = $isSearchInHeader + ? Constants::SEARCH_BOX_INPUT_LOCATION_MOVED + : Constants::SEARCH_BOX_INPUT_LOCATION_DEFAULT; + $commonSkinData = parent::getTemplateData() + [ 'page-langcode' => $title->getPageViewLanguage()->getHtmlCode(), 'page-isarticle' => (bool)$out->isArticle(), @@ -133,7 +138,9 @@ class SkinVector extends SkinMustache { 'html-categories' => $skin->getCategories(), 'data-footer' => $this->getFooterData(), - 'is-search-in-header' => $featureManager->isFeatureEnabled( Constants::FEATURE_SEARCH_IN_HEADER ), + + 'is-search-in-header' => $isSearchInHeader, + 'input-location' => $inputLocation, // Header 'data-logos' => ResourceLoaderSkinModule::getAvailableLogos( $this->getConfig() ), diff --git a/includes/templates/SearchBox.mustache b/includes/templates/SearchBox.mustache index 5ee7e0a..b9861c2 100644 --- a/includes/templates/SearchBox.mustache +++ b/includes/templates/SearchBox.mustache @@ -6,7 +6,7 @@
-
+
{{{html-input}}} {{! We construct two buttons (for 'go' and 'fulltext' search modes), but only one will be diff --git a/stories/types.js b/stories/types.js index 6af57ff..9ae080d 100644 --- a/stories/types.js +++ b/stories/types.js @@ -45,6 +45,8 @@ * @property {string|null} page-title the title of the search page * @property {string|null} html-button-search-fallback * @property {string|null} html-button-search + * @property {string} [input-location] An identifier corresponding the position of the search + * widget on the page, e.g. "header-navigation" */ /**