Jump to content

User:PrimeHunter/Wikidata search.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* This script adds a Tools link saying "Wikidata search" to search Wikidata (see [[WP:Wikidata]])
   for the current page name.
   It also works on red links. If it finds a suitable result with an article in another language
   then consider using [[Template:Interlanguage link]] on an English article with the red link.
   If a page has a Wikidata item then MediaWiki adds a "Wikidata item" link under "In other projects".
   The script still adds the search link which may find other related Wikidata items.
   To use the script, add the following line to [[Special:MyPage/common.js]]:
 
importScript('User:PrimeHunter/Wikidata search.js'); // Linkback: [[User:PrimeHunter/Wikidata search.js]]
 
*/
 
mw.loader.using(['mediawiki.util'], function () {
  mw.util.addPortletLink(
    'p-tb',
    '//www.wikidata.org/wiki/Special:Search?search=' + encodeURIComponent( mw.config.get('wgPageName') ),
    'Wikidata search',
    't-wikidatasearch',
    'Search the page name in Wikidata',
    null,
    '#t-cite'
  );
});