Jdlrobson added a comment.

  I'm happy to help with code review etc.
  
  > I would hope then that swapping out which client should be used based on if 
Wikibase is loaded or not would be fairly trivial? And that should either live 
in WVUI or in Wikibase as some kind of override?
  
  My expectation is ideally this would be a config only change .
  Ideally Wikidata would set `wgVectorSearchApi = 
'/w/rest.php/v1/wikidata-search/title?q=$1&limit=$2.` and it would just work.
  
  However, here's an approach that can be used right now to demonstrate a 
potential short-term client that could live inside wikibase using the old API. 
Paste this code into your JS console on 
https://en.wikipedia.org/?useskinversion=2&useskin=vector to see in action.
  
    mw.config.set('wgVectorSearchClient', {
        fetchByTitle: function ( query, domain, limit = 10 ) {
                var abort = function () {
                        // not implemented
                };
                var fetched = fetch( 
'https://www.wikidata.org/w/api.php?origin=*&action=wbsearchentities&format=json&errorformat=plaintext&language=en&uselang=en&type=item&search='
 + query )
                        .then( function ( res ) {
                                console.log('hi', res);
                                return res.json();
                        } ).then( function (data) {
                                var result = {
                                        query: query,
                                        results: data.search.map( function ( 
search ) {
                                                return {
                                                        id: search.pageid,
                                                        key: search.id,
                                                        title: search.label + ' 
(' + search.title + ')',
                                                        description: 
search.description
                                                        // thumbnail: TODO
                                                }
                                        } )
                                };
                                return result;
                        } );
    
                return {
                        abort : abort,
                        fetch: fetched
                };
        }
    })

TASK DETAIL
  https://phabricator.wikimedia.org/T275251

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Jdlrobson
Cc: Volker_E, Manuel, karapayneWMDE, GreenReaper, R4356th, despens, 
darthmon_wmde, WMDE-leszek, daniel, sdkim, alexhollender, LGoto, Yair_rand, 
MPhamWMF, ovasileva, Addshore, Lydia_Pintscher, Aklapper, Jdlrobson, 
Patafisik_WMF, Invadibot, Selby, caldera, maantietaja, Akuckartz, Demian, 
WDoranWMF, holger.knust, EvanProdromou, DannyS712, Nandana, Lahi, Gq86, 
GoranSMilovanovic, QZanden, LawExplorer, Winter, JJMC89, Iniquity, _jensen, 
rosalieper, Agabi10, Scott_WUaS, Pchelolo, Niedzielski, Izno, Wikidata-bugs, 
aude, GWicke, Dinoguy1000, Mbch331, Jay8g
_______________________________________________
Wikidata-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to