MediaWiki:Gadget-linkscount.js

(Szerkesztő:Bencemac/Gadget-linkscount.js szócikkből átirányítva)

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
/**
 * MediaWiki integrated backlinks count tool
 * Source: https://www.wikidata.org/w/index.php?title=MediaWiki:Linkscount.js&oldid=1661819056
 * Author: User:Ebrahim
 * Translator: User:Bencemac (Hungarian)
 */
(function () {
	if (['Whatlinkshere', 'GlobalUsage'].indexOf(mw.config.get('wgCanonicalSpecialPageName')) === -1) return;
	var isGlobalUsagePage = mw.config.get('wgCanonicalSpecialPageName') === 'GlobalUsage';

	var userLanguage = mw.config.get('wgUserLanguage');
	var translations = {
		en: {
			linksCountText: 'links: ',
			transclusionCountText: 'transclusions: ',
			fileLinkCountText: 'file local usages: ',
			fileGlobalLinkCountText: 'file global usages: ',
			countText: 'count',
			invalidTitleText: 'invalid title',
			serverErrorText: 'server error, click to retry',
			comma: ','
		},
		hu: {
			linksCountText: 'Linkek: ',
			transclusionCountText: 'Beillesztések: ',
			fileLinkCountText: 'Fájlhivatkozások: ',
			fileGlobalLinkCountText: 'Globális fájlhivatkozások: ',
			countText: 'Hivatkozások száma',
			invalidTitleText: 'Érvénytelen cím',
			serverErrorText: 'Szerverhiba, kattints az újrapróbálkozáshoz',
			comma: ','
		},
	};
	

	var finished;
	function init() {
		finished = false;
		$.i18n().load( translations );
		$('#linkscount-tool').remove();
		$('fieldset:first').append($('<span>', {
			id: 'linkscount-tool'
		}).append(' ', $('<a>', {
			text: '(' + $.i18n('countText') + ')'
		}).click(function (e) {
			e.preventDefault();
			finished = true;
			var title = mw.Title.newFromText($('input[name=target]').val());
			if (title === null) {
				mw.notify($.i18n('invalidTitleText'));
				return;
			}
			var button = $(this).css('color', 'lightgray');
			var ns = title.getNamespaceId();
			var page = title.getMain();
			$.post('https://linkscount.toolforge.org/', {
				namespace: isGlobalUsagePage ? 6 : ns,
				p: page,
				fromNamespace: $('#namespace').val(),
				invertFromNamespace: isGlobalUsagePage ? false : $('#nsinvert')[0].checked,
				dbname: mw.config.get('wgDBname')
			}).then(function (response) {
				if (response['#error']) {
					init();
					mw.notify($.i18n('serverErrorText'));
					return;
				}
				var text = response.pagelinks.toLocaleString(userLanguage);
				if (response.templatelinks) {
					text = $.i18n('transclusionCountText') +
						response.templatelinks.toLocaleString(userLanguage) +
						$.i18n('comma') + ' ' + $.i18n('linksCountText') + text;
				}
				if (response.filelinks) {
					text = $.i18n('fileLinkCountText') +
						response.filelinks.toLocaleString(userLanguage) +
						$.i18n('comma') + ' ' + (response.templatelinks
							? text
							: $.i18n('linksCountText') + text);
				}
				if (response.globalfilelinks) {
					text = $.i18n('fileGlobalLinkCountText') +
						response.globalfilelinks.toLocaleString(userLanguage) +
						$.i18n('comma') + ' ' + (response.templatelinks || response.filelinks
							? text
							: $.i18n('linksCountText') + text);
				}
				button.replaceWith($('<span>').text('(' + text + ')'));
			}).catch(function () {
				init();
				mw.notify($.i18n('serverErrorText'));
			});
		})));
	}

	function reinit() { if (finished) { init(); }}

	mw.loader.using(['mediawiki.Title', 'jquery.i18n']).then(function () {
		$(init);
		$('#namespace, #nsinvert').change(reinit);
		$('input[name=target]').change(reinit);
		$('input[name=target]').keyup(reinit);
	});
})();