fuddl / wd

a browser extension for wikidata
https://wikidata.org/wiki/Wikidata:Tools/Wikidata_for_Firefox
GNU General Public License v3.0
36 stars 6 forks source link

Feature request: Search via wikipedia url pasted/drag'n'dropped into the search box #132

Open davidscotson opened 10 months ago

davidscotson commented 10 months ago

Currently if you paste a Q42 style id into the search box, it'll use that to lookup an entry to match. This is particularly useful for people/things with very common names where the search might get swamped with other items.

I often find myself following a wikipedia link that a site provides to uniquely identify the current item, using the extension to quickly grab the Q-id then pasting it into the extension search box in another window.

It would be nice to skip a step and paste the url directly into the search box. Or drag and drop it into the sidebar.

In theory it's possible to grab links from user selected text too, even multiple ones and check them all, but I'm not sure how that would interact with people just trying to select the text of the link to search. Maybe display any link based match found as an additional search result at the top of the list?

fuddl commented 10 months ago

currently the search box does exactly what the wikidata website search box does. It calls this api endpoint:

https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&search=Q42&limit=10&errorformat=plaintext&language=en&uselang=en&type=item

If I enter the url into it it won't give me any results:

https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&search=https://en.wikipedia.org/wiki/Douglas_Adams&limit=10&errorformat=plaintext&language=en&uselang=en&type=item

I wouldn't like makeing it more complicated, then this.

But, as a fallback (when there are no results) and when it is a url, we could simply run all resolvers we usually have. That should have the intended efffect.

fuddl commented 10 months ago

If you want to do this, here are the important parts in the code:

this function resolves a url to a wikidata id: https://github.com/fuddl/wd/blob/d5f0dcd6721d21374e9733bb1cc6aacd74cffe71/src/resolver/index.ts#L33

You could call it here in case there are not results and the input is a url: https://github.com/fuddl/wd/blob/d5f0dcd6721d21374e9733bb1cc6aacd74cffe71/src/sidebar/wd-autocomplete.js#L1