Jump to content

User:Technical 13/SandBox/Gadget-extraTabs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Technical 13 (talk | contribs) at 13:02, 30 January 2014 (Saving point. This should fix some of the "redlink" issues (I want them to all show if they are really red or blue links... or as close as I can without the API for now)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var nsNum = mw.config.get('wgNamespaceNumber');
if(nsNum === 10 || nsNum === 11){
	var isPage = false, isTalk = false, isSand = false, isTest = false;
	var rawPageName = mw.config.get('wgTitle');
	if(rawPageName.indexOf('/sandbox') !== -1){
		rawPageName = rawPageName.slice(0, rawPageName.indexOf('/sandbox'));
		isSand = true;
	}
	if (rawPageName.indexOf('/testcases') !== -1) {
		rawPageName = rawPageName.slice(0, rawPageName.indexOf('/testcases'));
		isTest = true;
	}
	if(nsNum === 11) {
		isTalk = true;
	} else if(nsNum === 10){
		isPage = true;
	}
	var rawPage = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName);
	var talkPage = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName);
	var sandbox = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/sandbox');
	var sandTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/sandbox');
	var testcases = mw.config.get('wgArticlePath').replace('$1', 'Template:' + rawPageName + '/testcases');
	var testTalk = mw.config.get('wgArticlePath').replace('$1', 'Template_talk:' + rawPageName + '/testcases');
	$('#ca-nstab-template').find('a').attr('href', rawPage);
	$('#ca-talk').find('a').attr('href', talkPage);
	mw.util.addPortletLink('p-namespaces', sandbox, 'Sandbox', 'ca-sand', 'View the sandbox');
	mw.util.addPortletLink('p-namespaces', testcases, 'Testcases', 'ca-test', 'View the testcases');
/* sandbox talk page */
	if(isSand === true && isTalk === true){
		mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
		$('#ca-sandtalk').addClass("selected");
		$('#ca-talk').removeClass("selected");
		if($('#ca-nstab-template.new')){
			$('#ca-nstab-template.new').removeClass('new');
			$('#ca-sand').href($('#ca-sand').href() + '?action=edit&redlink=1').addClass('new');
		}
/* testcases talk page */
	} else if(isTest === true && isTalk === true){
		mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
		$('#ca-talk').removeClass("selected");
		$('#ca-testtalk').addClass("selected");
		if($('#ca-nstab-template.new')){
			$('#ca-nstab-template.new').removeClass('new');
			$('#ca-test').href($('#ca-test').href() + '?action=edit&redlink=1').addClass('new');
		}
/* sandbox page */
	} else if(isSand === true){
		$('#ca-nstab-template').removeClass("selected");
		$('#ca-sand').addClass("selected");
		mw.util.addPortletLink('p-namespaces', sandTalk, 'Talk', 'ca-sandtalk', 'View the talk page for the sandbox', '', '#ca-test');
		if($('#ca-talk.new')){
			$('#ca-talk.new').removeClass('new');
			$('#ca-sandTalk').href($('#ca-sandTalk').href() + '?action=edit&redlink=1').addClass('new');
		}
/* testcases page */
	} else if(isTest === true){
		$('#ca-nstab-template').removeClass("selected");
		$('#ca-test').addClass("selected");
		mw.util.addPortletLink('p-namespaces', testTalk, 'Talk', 'ca-testtalk', 'View the talk page for the testcases');
		if($('#ca-talk.new')){
			$('#ca-talk.new').removeClass('new');
			$('#ca-sandTalk').href($('#ca-sandTalk').href() + '?action=edit&redlink=1').addClass('new');
		}
/* template or talk page */
	} else if(isPage === true || isTalk === true){
		if($('#ca-nstab-template')){
			$('#ca-nstab-template').href($('#ca-nstab-template').href() + '?action=edit&redlink=1');
		}
		if($('#ca-talk.new')){
			$('#ca-talk.new').href($('#ca-talk.new').href() + '?action=edit&redlink=1');
		}
}