Jump to content

MediaWiki talk:Wdsearch.js: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Line 85: Line 85:
</syntaxhighlight> (assuming that <code>#<var>v</var></code> always exists and always contains a single <code>&lt;span class="wd_desc"&gt;</code>—I’m just making assumptions because the code is really hard to read with one-character variable names and no documentation comments). —[[User:Tacsipacsi|Tacsipacsi]] ([[User talk:Tacsipacsi|talk]]) 16:32, 26 October 2023 (UTC)
</syntaxhighlight> (assuming that <code>#<var>v</var></code> always exists and always contains a single <code>&lt;span class="wd_desc"&gt;</code>—I’m just making assumptions because the code is really hard to read with one-character variable names and no documentation comments). —[[User:Tacsipacsi|Tacsipacsi]] ([[User talk:Tacsipacsi|talk]]) 16:32, 26 October 2023 (UTC)
: {{Done}} using Tacsipacsi's code. And yes, it was totally broken before - I spent a long time debugging before realizing that. [[User:Pppery|* Pppery *]] [[User talk:Pppery|<sub style="color:#800000">it has begun...</sub>]] 22:44, 27 October 2023 (UTC)
: {{Done}} using Tacsipacsi's code. And yes, it was totally broken before - I spent a long time debugging before realizing that. [[User:Pppery|* Pppery *]] [[User talk:Pppery|<sub style="color:#800000">it has begun...</sub>]] 22:44, 27 October 2023 (UTC)
::After a quick look at the code, I think it would really need an overhaul…:
::* Agree with [[User:Tacsipacsi|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 <code>'#'</code>), which may –&nbsp;or may not&nbsp;– 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]].
::Note that on frwiki, this gadget is imported and enabled by default, for all users.
::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…
::[[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 17:22, 29 October 2023 (UTC)

Revision as of 17:23, 29 October 2023

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('https://en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript');
}

Please update Venetian translation. Thanks!

	'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

	'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

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.
Note that on frwiki, this gadget is imported and enabled by default, for all users.
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…
Od1n (talk) 17:22, 29 October 2023 (UTC)[reply]