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
This commit is contained in:
jdlrobson 2020-11-23 14:55:35 -08:00
parent e0c47dc462
commit dce24c9784
5 changed files with 13 additions and 2 deletions

View File

@ -35,6 +35,7 @@ class Hooks {
Config $config
) {
return [
'wgVectorSearchHost' => $config->get( 'VectorSearchHost' ),
'wgVectorUseCoreSearch' => $config->get( 'VectorUseCoreSearch' ),
];
}

View File

@ -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: {
/**

View File

@ -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;
}

View File

@ -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: {

View File

@ -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
},