MediaWiki:I18nLink.js

/** * @name       JSONLink * @description Adds link to JSON page that contains translations on scripts' docs pages * @author     Railfail536 * @author     TheGoldenPatrik1 * @license    CC-BY-SA 3.0 * @status     Stable * @version    1.0 */ mw.loader.using(['mediawiki.api', 'mediawiki.Title']).then(function {	// Config	var config = mw.config.get([ 'wgCityId', 'wgNamespaceNumber', 'wgPageName', 'wgCategories', 'wgArticleId' ]);	if ( config.wgCityId !== '7931' || // Dev Wiki only config.wgNamespaceNumber !== 0 || // Main namepsace only !/JavaScript/.test(config.wgCategories.join) || // Load only if page is in 'JavaScript' category config.wgArticleId === 0 || window.JSONLinkLoaded // Double run prevention ) { return; }	window.JSONLinkLoaded = true;

var title = config.wgPageName, titleText = 'MediaWiki:Custom-' + title.replace(/\/.*/, '') /* Ignore subpages */ + '/i18n.json'; new mw.Api.get({		cb: Date.now,		action: 'query',		titles: titleText	}).done(function(d) {		var pages = d.query.pages;		if (d.error || pages[-1]) { return; }

// Prepend link $('#PageHeader ul.wds-list').prepend(			$('').append( $('', {					href: mw.util.getUrl(titleText),					text: 'JSON'				}) )		);	}); });