From 475f80cf76669437d25171db59f2a08bd2fa67a8 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 10 Sep 2024 13:09:33 +0330 Subject: [PATCH] Use browser native URL instead of mw.Uri Bug: T374314 Change-Id: I66be10c017e853ea130b0919789b22c4c3f12622 --- resources/skins.vector.search/instrumentation.js | 6 +++--- skin.json | 2 +- tests/jest/instrumentation.test.js | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/resources/skins.vector.search/instrumentation.js b/resources/skins.vector.search/instrumentation.js index 0b384f0d6..399ad3543 100644 --- a/resources/skins.vector.search/instrumentation.js +++ b/resources/skins.vector.search/instrumentation.js @@ -124,9 +124,9 @@ function getWprovFromResultIndex( index ) { function addWprovToSearchResultUrls( results, offset ) { return results.map( ( result, index ) => { if ( result.url ) { - const uri = new mw.Uri( result.url ); - uri.query.wprov = getWprovFromResultIndex( index + offset ); - result = Object.assign( {}, result, { url: uri.toString() } ); + const url = new URL( result.url, location.href ); + url.searchParams.set( 'wprov', getWprovFromResultIndex( index + offset ) ); + result = Object.assign( {}, result, { url: url.toString() } ); } return result; } ); diff --git a/skin.json b/skin.json index 6fe9c67d4..b022c115a 100644 --- a/skin.json +++ b/skin.json @@ -230,7 +230,7 @@ }, "skins.vector.search": { "dependencies": [ - "mediawiki.Uri", + "web2017-polyfills", "mediawiki.util", "skins.vector.search.codex.scripts" ], diff --git a/tests/jest/instrumentation.test.js b/tests/jest/instrumentation.test.js index 5be338a28..9b5ef2a70 100644 --- a/tests/jest/instrumentation.test.js +++ b/tests/jest/instrumentation.test.js @@ -13,7 +13,8 @@ describe( 'instrumentation', () => { test( 'addWprovToSearchResultUrls without offset', () => { const url1 = 'https://host/?title=Special%3ASearch&search=Aa', url2Base = 'https://host/?title=Special%3ASearch&search=Ab', - url3 = 'https://host/Ac'; + url3 = 'https://host/Ac', + url5 = '/index.php?title=Special%3ASearch&search=Ad'; const results = [ { title: 'Aa', @@ -29,6 +30,10 @@ describe( 'instrumentation', () => { }, { title: 'Ad' + }, + { + title: 'Ae', + url: url5 } ]; @@ -48,6 +53,10 @@ describe( 'instrumentation', () => { }, { title: 'Ad' + }, + { + title: 'Ae', + url: `${ location.origin }${ url5 }&wprov=acrw1_4` } ] ); expect( results[ 0 ].url ).toStrictEqual( url1 );