मीडियाविकि:Gadget-WikidataInfo.js

विकिपीडिया से

नोट: प्रकाशित करे के बाद, बदलाव देखे खातिर आपके अपने ब्राउजर के कैशे खाली करे के पड़ सकत बा।

  • फायरफॉक्स / सफारी:शिफ्ट दबा के रीलोड पर क्लिक करीं, या फिर Ctrl-F5 या Ctrl-R दबाईं (मैक पर ⌘-R)
  • गूगल क्रोम: Ctrl-Shift-R दबाईं (मैक पर ⌘-Shift-R)
  • इंटरनेट एक्स्प्लोरर/एज़: Ctrl दबा के Refresh पर क्लिक करीं, या Ctrl-F5 दबईं
  • ओपेरा: Menu → Settings में जाईं (मैक में Opera → Preferences) आ एकरे बाद Privacy & security → Clear browsing data → Cached images and files क्लिक करीं।
/**
 * Add a small box under a Wikipedia article's title displaying the label,
 * description, aliases and the identifier of the related Wikidata item
 *
 * Original script form:
 *  // [[d:User:Yair rand/WikidataInfo.js]]
 * dependencies=mediawiki.jqueryMsg
 */
// <nowiki>
location.search.indexOf( 'printable=yes' ) === -1
&& [
	'wikibase-item',
	'wikibase-property',
	'wikibase-lexeme',
	'flow-board',
	'EntitySchema',
	'proofread-index',
	'proofread-page'
].indexOf( mw.config.get( 'wgPageContentModel' ) ) === -1
&& mw.loader.using( [ 'mediawiki.jqueryMsg' ] ).done( function () {
	var translate = {
		'en': {
			notfound: "Wikidata item not found.",
			intro: "Wikidata: ",
			nolabel: "(No label)",
			nodescription: "no description given",
			aliases: "{{PLURAL:$1|Alias|Aliases}}: ",
			noaliases: "None"
		},
		'bh': {
			notfound: "कौनों विकिडेटा आइटम ना मिलल",
			intro: "विकिडेटा: ",
			nolabel: "(कौनों लेबल नइखे)",
			nodescription: "कवनों बिबरन नइखे दिहल",
			aliases: "अउरी दूसर नाँव: ",
			noaliases: "कौनों नइखे"
		},
		'bho': {
			notfound: "कौनों विकिडेटा आइटम ना मिलल",
			intro: "विकिडेटा: ",
			nolabel: "(कौनों लेबल नइखे)",
			nodescription: "कवनों बिबरन नइखे दिहल",
			aliases: "अउरी दूसर नाँव: ",
			noaliases: "कौनों नइखे"
		},
		'bn': {
			notfound: "উইকিউপাত্তের আইটেম পাওয়া যায়নি।",
			intro: "উইকিউপাত্ত: ",
			nolabel: "(লেবেল নেই)",
			nodescription: "বিবরণ দেওয়া হয়নি",
			aliases: "উপনামগুলি: ",
			noaliases: "কোনটি না"
		},
		'hi': {
			notfound: "विकिडाटा प्रविष्टि नहीं मिली।",
			intro: "विकिडाटा: ",
			nolabel: "(कोई लेबल नहीं)",
			nodescription: "कोई विवरण नहीं दिया गया",
			aliases: "{{PLURAL:$1|ऊर्फ|अन्य नाम}}: ",
			noaliases: "कुछ भी नहीं"
		},
		'ru': {
			notfound: "Объект Викиданных не найден.",
			intro: "Викиданные: ",
			nolabel: "(нет метки)",
			nodescription: "нет описания",
			aliases: "Синонимы: ",
			noaliases: "нет"
		}
	};
	var namespace = mw.config.get( 'wgNamespaceNumber' ),
		lang = mw.config.get( 'wgContentLanguage' ),
		page = ( namespace -= ( namespace > 0 && namespace % 2 ) ) === 0
			? mw.config.get( 'wgTitle' )
			: mw.config.get( 'wgFormattedNamespaces' )[ namespace ] + ':' + mw.config.get( 'wgTitle' );

	[ -1, 2, 6 ].indexOf( namespace ) === -1 && $.ajax( {
		url: '//www.wikidata.org/w/api.php',
		data: {
			'format': 'json',
			'action': 'wbgetentities',
			'sites': mw.config.get( 'wgDBname' ),
			'titles': page,
			'props': 'info|labels|descriptions|aliases',
			'languages': lang,
			'maxage': mw.config.get( "wgUserName" ) === null ? 900 : 30,
			'smaxage': mw.config.get( "wgUserName" ) === null ? 900 : 30,
			//'maxlag': 1
		},
		dataType: 'jsonp',
		cache: true
	} )
	.done( function ( data ) {
		if ( data.success ) {
			$( function () {
				var $d = $( '<div>' ).addClass( 'WDI-box' ),
					userLang = mw.config.get( 'wgUserLanguage' ),
					m = Object.prototype.hasOwnProperty.call( translate, userLang ) ? translate[ userLang ] : translate.en;
				mw.messages.set( 'WDI-aliases', m.aliases );
				$.each( data.entities, function ( entity, item ) {
					if ( entity == -1 ) {
						$d.append( $( '<a>' ).attr( 'href',
							'//www.wikidata.org/wiki/Special:NewItem?site=' +
							mw.config.get( 'wgDBname' ) +
							'&page=' + encodeURIComponent( page ) +
							'&label=' + encodeURIComponent( page ) +
							'&lang=' + lang
						).text( m.notfound ) );
					} else {
						var label = item.labels[ lang ] && item.labels[ lang ].value,
							description = item.descriptions[ lang ] && item.descriptions[ lang ].value,
							aliases = $.map( item.aliases[ lang ] || [], function ( alias ) {
								return alias.value;
							} );
						if ( window.WDIlimitaliases && WDIlimitaliases < aliases.length ){
							for( ; WDIlimitaliases < aliases.length; aliases.pop() ) ;
							aliases.push( '...' );
						}
						$d.append(
							$( '<a>' )
								.attr( 'href', '//www.wikidata.org/wiki/' + item.title )
								.text( m.intro + ( label || m.nolabel ) ),
							' (',
							$( '<a>' )
								.attr( 'href', '//www.wikidata.org/wiki/' + item.title )
								.text( item.title ),
							')',
							$( '<span>' ).text( ', ' ),
							$( '<i>' )
								.text( description || m.nodescription )
								.addClass( description ? 'WDI-desc' : 'WDI-desc WDI-nodesc' ),
							$( '<br>' ),
							$( '<span>' ).text( mw.msg( 'WDI-aliases', aliases.length ) + ( aliases.join( ', ' ) || m.noaliases ) )
						);
					}
				} );
				$d.appendTo( '#contentSub' );
			} );
		}
	} );
} );
// </nowiki>