From d78ffeadb44a8b97048a56268396e91d4be4894e Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 4 Oct 2022 22:40:23 -0400 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E2=99=BB=EF=B8=8F=20use=20co?= =?UTF-8?q?re=20data=20for=20search=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Partials/Header.php | 19 +++++-------------- includes/SkinCitizen.php | 2 +- skin.json | 1 + templates/Search__button.mustache | 4 ++-- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/includes/Partials/Header.php b/includes/Partials/Header.php index dfcf0416..3f8a2496 100644 --- a/includes/Partials/Header.php +++ b/includes/Partials/Header.php @@ -73,23 +73,14 @@ final class Header extends Partial { } /** - * Render the search box + * Decorate search box template data * + * @param array $searchBoxData original data-search-box * @return array - * @throws MWException */ - public function buildSearchProps(): array { - $skin = $this->skin; - - $toggleMsg = $skin->msg( 'citizen-search-toggle' )->text(); - - return [ - // TODO: This should be called in skin.json - 'msg-citizen-search-toggle' => $toggleMsg, - 'msg-citizen-search-toggle-shortcut' => $toggleMsg . ' [/]', - 'form-action' => $this->getConfigValue( 'Script' ), - 'html-input' => $skin->makeSearchInput( [ 'id' => 'searchInput' ] ), - 'page-title' => SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey(), + public function decorateSearchBoxData( $searchBoxData ): array { + return $searchBoxData +=[ + 'msg-citizen-search-toggle-shortcut' => '[/]', 'html-random-href' => Skin::makeSpecialUrl( 'Randompage' ), ]; } diff --git a/includes/SkinCitizen.php b/includes/SkinCitizen.php index 84092bb4..f2fdcca4 100644 --- a/includes/SkinCitizen.php +++ b/includes/SkinCitizen.php @@ -96,7 +96,6 @@ class SkinCitizen extends SkinMustache { // Data objects 'data-header' => [ 'data-personal-menu' => $header->buildPersonalMenu(), - 'data-search-box' => $header->buildSearchProps(), ], 'data-sitestats' => $drawer->getSiteStatsData(), // HTML strings @@ -109,6 +108,7 @@ class SkinCitizen extends SkinMustache { 'msg-citizen-footer-desc' => $this->msg( "citizen-footer-desc" )->inContentLanguage()->parse(), 'msg-citizen-footer-tagline' => $this->msg( "citizen-footer-tagline" )->inContentLanguage()->parse(), // Decorate data provided by core + 'data-search-box' => $header->decorateSearchBoxData( $parentData['data-search-box'] ), 'data-portlets-sidebar' => $drawer->decorateSidebarData( $parentData['data-portlets-sidebar'] ), 'data-footer' => $footer->decorateFooterData( $parentData['data-footer'] ), ]; diff --git a/skin.json b/skin.json index 9198a6a1..5fd57d3b 100644 --- a/skin.json +++ b/skin.json @@ -41,6 +41,7 @@ "citizen-drawer-toggle", "citizen-languages-toggle", "citizen-personalmenu-toggle", + "citizen-search-toggle", "randompage", "search", "sitetitle" diff --git a/templates/Search__button.mustache b/templates/Search__button.mustache index ac49437a..b3f33f3a 100644 --- a/templates/Search__button.mustache +++ b/templates/Search__button.mustache @@ -1,5 +1,5 @@ {{! - string msg-citizen-search-toggle-shortcut message with shortcut key for search toggle + string msg-citizen-search-toggle-shortcut shortcut key message string msg-citizen-search-toggle tooltip message for search toggle }}
@@ -12,7 +12,7 @@ id="citizen-search__buttonCheckbox" class="mw-checkbox-hack-button citizen-header__buttonCheckbox" for="citizen-search__checkbox" - title="{{msg-citizen-search-toggle-shortcut}}" + title="{{msg-citizen-search-toggle}} {{msg-citizen-search-toggle-shortcut}}" aria-hidden="true"> {{msg-citizen-search-toggle}}