User:TomT0m/Leonore.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// To import, put in you common.js
// importScript('User:TomT0m/Leonore.js');

// Simple script to query the Leonore database http://www.culture.gouv.fr/public/mistral/leonore_fr 
// with the current item label in your language


( function ( mw, $ ) {
	var entityId = mw.config.get( 'wbEntityId' );
	if ( !entityId ) {
		return;
	}

	// to remember, css selector found in a sample page
	// html.client-js body.mediawiki div#content.mw-body div#bodyContent.mw-body-content div#mw-content-text.mw-content-ltr div#wb-item-Q192498.wb-entity h1#wb-firstHeading-Q192498.wb-firstHeading span.wb-property-container-value span.wb-value

	// building the CSS selector which depends on the entity ID, and querying the corresponding label in the DOM
	name_to_query = $("html.client-js body.mediawiki div#content.mw-body div#bodyContent.mw-body-content " +
	"div#mw-content-text.mw-content-ltr div#wb-item-"
	+ entityId + 
	".wb-entity h1#wb-firstHeading-"
	+ entityId +
	".wb-firstHeading span.wb-property-container-value span.wb-value").text();


	// sample query link
	// link http://www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=RETROUVER&REQ=((leloir):NOM,NOM2,NOM-JF,NOM-MARI,SURNOM,NOTES)


	// Add portlet link for item
	mw.util.addPortletLink(
		'p-tb',
		// link building
		'http://www.culture.gouv.fr/public/mistral/leonore_fr?' + $.param( {
			ACTION: "RETROUVER",
			REQ: "((" + name_to_query + "):NOM,NOM2,NOM-JF,NOM-MARI,SURNOM,NOTES)"
		} ),
		'Leonore',
		't-leonore',
		'This item label search in the Leonore database'
	);
}( mediaWiki, jQuery ) );