Jump to content

MediaWiki talk:Wdsearch.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Screenshot of the Earth test search, with this script adding links to Wikidata, Reasonator, Commons, and Wikipedia.

See screenshot at right. See more info via Magnus and Gerard.

USAGE

On en.wikipedia, add the following lines to your common.js page:

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	importScript('MediaWiki:Wdsearch.js');
}

On other Wikipedias, add these lines, instead:

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	mw.loader.load('http://en.wiki.x.io/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript');
}

Please update Venetian translation. Thanks!

[edit]
	'vec' : {
		'commons_cat' : 'Categoria in Commons' ,
		'wikipedias' : 'Voxe de Wikipedia' ,
		'wikivoyages' : 'Guide torìsteghe so Wikivoyage' ,
		'wikisources' : 'Voxe de Wikisource' ,
		'header' : 'Rexultai riserca in Wikidata' ,
		'reasonator' : 'Fa védar detaji del ełemento so Reasonator'
	},

@MSGJ and Mr. Stradivarius: Please update Venetian translation. Thanks! --Fierodelveneto (talk) 08:20, 25 June 2020 (UTC)[reply]

@Izno: hello, sorry if I ping you. Could you add this translation? We would really need it. Thank you very much and I apologize again. --Fierodelveneto (talk) 11:26, 2 July 2020 (UTC)[reply]
Set the request answered to n since I cannot update this page. It is a Javascript page which means it needs an interface administrator. If someone does not come to fix it in the next week or so, post there at the linked place. --Izno (talk) 14:09, 2 July 2020 (UTC)[reply]
 Done 'vec' added. — xaosflux Talk 16:06, 2 July 2020 (UTC)[reply]

Turkish translation

[edit]
	'tr' : {
		'commons_cat' : 'Commons kategorisi' ,
		'wikipedias' : 'Vikipedi maddeleri' ,
		'wikivoyages' : 'Vikigezgin gezi rehberleri' ,
		'wikisources' : 'Vikikaynak sayfaları' ,
		'header' : 'Vikiveri arama sonuçları' ,
		'reasonator' : 'Reasonator\'da öge ayrıntılarını göster'

Thanks. --ToprakM 11:28, 22 July 2020 (UTC)[reply]

 Done @ToprakM: this has been added. — xaosflux Talk 13:43, 22 July 2020 (UTC)[reply]

Edit request: code fix

[edit]

This change fixed some JavaScript errors, but is not efficient as it examinates the attributes of all elements of the page…

(Actually, that code should not even be working, because the ' span.wd_desc' part got included in the looked up ID value…)

I would recommend to undo the above linked change, and instead apply the following code, which makes use of $.escapeSelector():

$('#'+$.escapeSelector(v)+' span.wd_desc')

Ping Jon (WMF).

Od1n (talk) 20:08, 25 October 2023 (UTC)[reply]

As far as I know, selectors are matched from right to left, so to make the it really efficient, we should force matching from left to right. And that could even overcome the escaping problem in a natural way:
			$.each ( q , function ( k , v ) {
				wd_auto_desc.loadItem ( v , {
					target: $(document.getElementById(v).querySelector('span.wd_desc')),
					links : the_project ,
//					callback : function ( q , html , opt ) { mw.log ( q + ' : ' + html ) } ,
//					linktarget : '_blank'
				} ) ;
			});
(assuming that #v always exists and always contains a single <span class="wd_desc">—I’m just making assumptions because the code is really hard to read with one-character variable names and no documentation comments). —Tacsipacsi (talk) 16:32, 26 October 2023 (UTC)[reply]
 Done using Tacsipacsi's code. And yes, it was totally broken before - I spent a long time debugging before realizing that. * Pppery * it has begun... 22:44, 27 October 2023 (UTC)[reply]
After a quick look at the code, I think it would really need an overhaul…:
  • Agree with Tacsipacsi, the one-letter variables make the code difficult to understand, and are hard to search for.
  • There are other occurrences of unescaped IDs (search for '#'), which may – or may not – also need to be escaped.
  • I also had a look at the API requests, and they seem to be suboptimal. See File:Wdsearch - API requests.png.
About the "desc injection" feature that we have repaired here, I think it would be better to remove it actually, as it adds a lot of noise. Compare File:Wdsearch - Without desc injection.png (previous, broken code) with File:Wdsearch - With desc injection.png (new, fixed code). Note it was broken for 3 years and nobody complained about it…
Note that on frwiki, this gadget is imported and enabled by default, for all users.
Od1n (talk) 17:22, 29 October 2023 (UTC)[reply]
Another approach to consider is to only do desc injection if the Wikidata item doesn't have a manual description. But then I'm not a user of this script, so my opinion doesn't really count.
For the other unescaped IDs - if they needed to be escaped then Jon (WMF) would have escaped them already, so I don't think any further action is needed there. On the other issues, it's unlikely someone will actually take up your opportunity to rewrite this code, but if you have a specific edit needing an Iadmin to handle then feel free to reactivate {{edit interface-protected}} and I or someone else will handle it. * Pppery * it has begun... 17:33, 29 October 2023 (UTC)[reply]