User:ZooFari/nld.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// <source lang="javascript">
// Exempt
window.exemptNld = function () {
		document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/{{no license([^\}]*?)}}/g, '{{No license$1|del=exempt}}');

	document.editform.wpSummary.value = 'File is exempt from {{no license}} deletion.';
	document.editform.wpMinoredit.checked = true;

	document.editform.submit();
//

window.addFunction = function(functionNameString, buttonDisplayName, checkNameSpaceFlag, whereAdd) {
	if ( wgNamespaceNumber !== checkNameSpaceFlag && wgPageName !== "Commons:Sandbox" ) {
		return;
	}

	if ( getParamValue('functionName') == functionNameString) {
			eval(functionNameString+"(true)");
	}

	var href;
	if ( wgAction == 'edit' ){ 
		href = "javascript:" + functionNameString + "(true)";
	} else {
		href = wgScript + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&functionName=" + functionNameString;
	}
	
	if (whereAdd == 'top') {
		mw.util.addPortletLink('p-cactions', href, buttonDisplayName);
	} else if (whereAdd == 'toolbox') {
		mw.util.addPortletLink('p-tb', href, buttonDisplayName);
	}
	// [link]
	var targets = getElementsByClassName(document, 'div', 'NL');
	if(targets.length === 0) return true;
	
	targets[0].style.textAlign = 'center';

		var exemptlink = wgScript+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit&functionName=exemptNld";
	
		targets[0].innerHTML = '[<a href="'+exemptlink+'">exempt</a>]';
		return true;
	//
}


// jQuery UI is not loaded on all pages yet:
if (jQuery.ui == undefined) {
	$.getScript(wgServer + '/w/extensions/UsabilityInitiative/css/vector/jquery-ui-1.7.2.css');
	$.getScript(wgServer + '/w/extensions/UsabilityInitiative/js/js2stopgap/jui.combined.min.js', function(){

		addFunction("exemptNld", "exempt", 6, "");
	});
} else {
	addFunction("exemptNld", "exempt", 6, "");
}

// </source>