Remove $wgVectorSearchHost, replace with $wgVectorSearchApiUrl
This allows the URL to the other wiki's rest.php to be configured exactly, rather than assuming that it has the same wgScriptPath as the current wiki. This is necessary to make this feature work on PatchDemo, where wgScriptPath looks like '/123abc456/w'. $wgVectorSearchHost is removed, since nothing uses it except PatchDemo (where it's broken) and development setups. Bug: T319494 Change-Id: Ife042f4f683d366a31a642723746d4aa80774c03
This commit is contained in:
parent
508d5fc548
commit
5693594bd1
|
@ -98,7 +98,7 @@ class Hooks implements
|
|||
Config $config
|
||||
) {
|
||||
return [
|
||||
'wgVectorSearchHost' => $config->get( 'VectorSearchHost' ),
|
||||
'wgVectorSearchApiUrl' => $config->get( 'VectorSearchApiUrl' ),
|
||||
'wgVectorWebABTestEnrollment' => self::getActiveABTest( $config ),
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/** See Vector\Hooks::getVectorResourceLoaderConfig */
|
||||
interface VectorResourceLoaderVirtualConfig {
|
||||
wgVectorSearchHost: string;
|
||||
wgVectorSearchApiUrl: string;
|
||||
}
|
||||
|
|
|
@ -141,9 +141,9 @@ function initSearchLoader( document ) {
|
|||
var searchBoxes = document.querySelectorAll( '.vector-search-box' ),
|
||||
isWikidata = mw.config.get( 'wgWikiID' ) === 'wikidatawiki';
|
||||
|
||||
// Allow developers to defined $wgVectorSearchHost in LocalSettings to target different APIs
|
||||
if ( config.wgVectorSearchHost ) {
|
||||
mw.config.set( 'wgVectorSearchHost', config.wgVectorSearchHost );
|
||||
// Allow developers to defined $wgVectorSearchApiUrl in LocalSettings to target different APIs
|
||||
if ( config.wgVectorSearchApiUrl ) {
|
||||
mw.config.set( 'wgVectorSearchApiUrl', config.wgVectorSearchApiUrl );
|
||||
}
|
||||
|
||||
if ( !searchBoxes.length ) {
|
||||
|
|
|
@ -155,7 +155,9 @@ module.exports = exports = defineComponent( {
|
|||
* @param {string} value
|
||||
*/
|
||||
onInput: function ( value ) {
|
||||
const domain = mw.config.get( 'wgVectorSearchHost', location.host ),
|
||||
const searchApiUrl = mw.config.get( 'wgVectorSearchApiUrl',
|
||||
mw.config.get( 'wgScriptPath' ) + '/rest.php'
|
||||
),
|
||||
query = value.trim();
|
||||
|
||||
if ( query === '' ) {
|
||||
|
@ -166,7 +168,7 @@ module.exports = exports = defineComponent( {
|
|||
|
||||
instrumentation.listeners.onFetchStart();
|
||||
|
||||
restClient.fetchByTitle( query, domain, 10, this.showDescription ).fetch
|
||||
restClient.fetchByTitle( query, searchApiUrl, 10, this.showDescription ).fetch
|
||||
.then( ( data ) => {
|
||||
this.suggestions = data.results;
|
||||
this.searchFooterUrl = urlGenerator.generateUrl( query );
|
||||
|
|
|
@ -66,7 +66,7 @@ function adaptApiResponse( config, query, restResponse, showDescription ) {
|
|||
/**
|
||||
* @callback fetchByTitle
|
||||
* @param {string} query The search term.
|
||||
* @param {string} domain The base URL for the wiki without protocol. Example: 'sr.wikipedia.org'.
|
||||
* @param {string} searchApiUrl The URL to rest.php
|
||||
* @param {number} [limit] Maximum number of results.
|
||||
* @return {AbortableSearchFetch}
|
||||
*/
|
||||
|
@ -85,9 +85,9 @@ function restSearchClient( config ) {
|
|||
/**
|
||||
* @type {fetchByTitle}
|
||||
*/
|
||||
fetchByTitle: ( q, domain, limit = 10, showDescription = true ) => {
|
||||
fetchByTitle: ( q, searchApiUrl, limit = 10, showDescription = true ) => {
|
||||
const params = { q, limit };
|
||||
const url = '//' + domain + config.get( 'wgScriptPath' ) + '/rest.php/v1/search/title?' + $.param( params );
|
||||
const url = searchApiUrl + '/v1/search/title?' + $.param( params );
|
||||
const result = fetchJson( url, {
|
||||
headers: {
|
||||
accept: 'application/json'
|
||||
|
|
|
@ -473,9 +473,9 @@
|
|||
"value": [],
|
||||
"description": "Temporary configuration flag for allowing users to preview the new Vector skin."
|
||||
},
|
||||
"VectorSearchHost": {
|
||||
"VectorSearchApiUrl": {
|
||||
"value": "",
|
||||
"description": "Override default search API. Can be used with $wgDisableTextSearch and $wgSearchForwardUrl to mimic user experience on production."
|
||||
"description": "To override the default search API, set this to the URL to rest.php on another wiki. Can be used with $wgDisableTextSearch and $wgSearchForwardUrl to mimic user experience on production."
|
||||
},
|
||||
"VectorUseIconWatch": {
|
||||
"value": true
|
||||
|
|
|
@ -66,7 +66,7 @@ describe( 'restApiSearchClient', () => {
|
|||
|
||||
const searchResult = await restSearchClient( configMock ).fetchByTitle(
|
||||
'media',
|
||||
'en.wikipedia.org',
|
||||
'https://en.wikipedia.org/w/rest.php',
|
||||
2
|
||||
).fetch;
|
||||
|
||||
|
@ -87,7 +87,7 @@ describe( 'restApiSearchClient', () => {
|
|||
if ( mockedRequests ) {
|
||||
expect( fetchMock ).toHaveBeenCalledTimes( 1 );
|
||||
expect( fetchMock ).toHaveBeenCalledWith(
|
||||
'//en.wikipedia.org/w/rest.php/v1/search/title?q=media&limit=2',
|
||||
'https://en.wikipedia.org/w/rest.php/v1/search/title?q=media&limit=2',
|
||||
{ headers: { accept: 'application/json' }, signal: controller.signal }
|
||||
);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ describe( 'restApiSearchClient', () => {
|
|||
|
||||
const searchResult = await restSearchClient( configMock ).fetchByTitle(
|
||||
'thereIsNothingLikeThis',
|
||||
'en.wikipedia.org'
|
||||
'https://en.wikipedia.org/w/rest.php'
|
||||
).fetch;
|
||||
|
||||
/* eslint-disable-next-line compat/compat */
|
||||
|
@ -111,7 +111,7 @@ describe( 'restApiSearchClient', () => {
|
|||
if ( mockedRequests ) {
|
||||
expect( fetchMock ).toHaveBeenCalledTimes( 1 );
|
||||
expect( fetchMock ).toHaveBeenCalledWith(
|
||||
'//en.wikipedia.org/w/rest.php/v1/search/title?q=thereIsNothingLikeThis&limit=10',
|
||||
'https://en.wikipedia.org/w/rest.php/v1/search/title?q=thereIsNothingLikeThis&limit=10',
|
||||
{ headers: { accept: 'application/json' }, signal: controller.signal }
|
||||
);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ describe( 'restApiSearchClient', () => {
|
|||
|
||||
await expect( restSearchClient( configMock ).fetchByTitle(
|
||||
'anything',
|
||||
'en.wikipedia.org'
|
||||
'https://en.wikipedia.org/w/rest.php'
|
||||
).fetch ).rejects.toThrow( 'failed' );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -56,10 +56,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
[
|
||||
[
|
||||
'VectorWebABTestEnrollment' => [],
|
||||
'VectorSearchHost' => 'en.wikipedia.org'
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php'
|
||||
],
|
||||
[
|
||||
'wgVectorSearchHost' => 'en.wikipedia.org',
|
||||
'wgVectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'wgVectorWebABTestEnrollment' => [],
|
||||
]
|
||||
],
|
||||
|
@ -83,10 +83,10 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
],
|
||||
],
|
||||
'VectorSearchHost' => 'en.wikipedia.org'
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php'
|
||||
],
|
||||
[
|
||||
'wgVectorSearchHost' => 'en.wikipedia.org',
|
||||
'wgVectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'wgVectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
|
@ -115,7 +115,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
# Bad experiment (no buckets)
|
||||
[
|
||||
[
|
||||
'VectorSearchHost' => 'en.wikipedia.org',
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'VectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
|
@ -125,7 +125,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
# Bad experiment (no unsampled bucket)
|
||||
[
|
||||
[
|
||||
'VectorSearchHost' => 'en.wikipedia.org',
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'VectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
|
@ -140,7 +140,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
# Bad experiment (wrong format)
|
||||
[
|
||||
[
|
||||
'VectorSearchHost' => 'en.wikipedia.org',
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'VectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
|
@ -153,7 +153,7 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
# Bad experiment (samplingRate defined as string)
|
||||
[
|
||||
[
|
||||
'VectorSearchHost' => 'en.wikipedia.org',
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'VectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
|
|
Loading…
Reference in New Issue