From dce24c9784971b5a1a727836b9f79355525745f9 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Mon, 23 Nov 2020 14:55:35 -0800 Subject: [PATCH] Development: Allow us to test search with different API hosts By default the API uses location.host as the host, however during development it is useful to test against production wikis For example to test against English Wikipedia: $wgVectorSearchHost = 'en.wikipedia.org'; Note: Links when clicked will not take the user to the target page, and instead will take the user to the search results page with a link to create the page. The following config can be used to workaround that page: $wgDisableTextSearch = true; $wgSearchForwardUrl = "/w/index.php?title=$1"; Change-Id: I5fbac7f54844d7a9d6976007bc0d0ff9938b9f2b --- includes/Hooks.php | 1 + resources/mediawiki.d.ts | 3 ++- resources/skins.vector.js/searchLoader.js | 5 +++++ resources/skins.vector.search/App.vue | 2 +- skin.json | 4 ++++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index ccbecf76..5bc237e9 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -35,6 +35,7 @@ class Hooks { Config $config ) { return [ + 'wgVectorSearchHost' => $config->get( 'VectorSearchHost' ), 'wgVectorUseCoreSearch' => $config->get( 'VectorUseCoreSearch' ), ]; } diff --git a/resources/mediawiki.d.ts b/resources/mediawiki.d.ts index ff255833..6d5ad08d 100644 --- a/resources/mediawiki.d.ts +++ b/resources/mediawiki.d.ts @@ -36,7 +36,8 @@ interface MediaWiki { }; Api: MwApiConstructor; config: { - get( configKey: string|null ): string; + get( configKey: string|null, fallback?: any|null ): string; + set( configKey: string|null, value: any|null ): void; }, loader: { /** diff --git a/resources/skins.vector.js/searchLoader.js b/resources/skins.vector.js/searchLoader.js index 372a286f..eb52e491 100644 --- a/resources/skins.vector.js/searchLoader.js +++ b/resources/skins.vector.js/searchLoader.js @@ -132,6 +132,11 @@ function initSearchLoader( document ) { var searchForm = document.getElementById( SEARCH_FORM_ID ), searchInput = document.getElementById( SEARCH_INPUT_ID ); + // Allow developers to defined $wgVectorSearchHost in LocalSettings to target different APIs + if ( config.wgVectorSearchHost ) { + mw.config.set( 'wgVectorSearchHost', config.wgVectorSearchHost ); + } + if ( !searchForm || !searchInput ) { return; } diff --git a/resources/skins.vector.search/App.vue b/resources/skins.vector.search/App.vue index 2913e14d..e87716a3 100644 --- a/resources/skins.vector.search/App.vue +++ b/resources/skins.vector.search/App.vue @@ -52,7 +52,7 @@ module.exports = { }, domain: function () { // It might be helpful to allow this to be configurable in future. - return location.host; + return mw.config.get( 'wgVectorSearchHost', location.host ); } }, props: { diff --git a/skin.json b/skin.json index 7564c131..9b55fa90 100644 --- a/skin.json +++ b/skin.json @@ -173,6 +173,10 @@ } }, "config": { + "VectorSearchHost": { + "value": "", + "description": "Override default search API. Can be used with $wgDisableTextSearch and $wgSearchForwardUrl to mimic user experience on production." + }, "VectorUseIconWatch": { "value": true },