User:ZooFari/Sandbox.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">
// Original Flickrreview script written by [[User:Patstuart]]
// Rewritten and extended by [[User:ZooFari]] 
// Special thanks to [[User:Krinkle]] and [[User:DieBuche]] for assistance
// See talk page for documentation
$ = jQuery; $(document).ready(function(){

// LRP
window.LicenseReview_P = function () {
		var desc = prompt("Description:", "")
	document.editform.wpTextbox1.value = document.editform.wpTextbox1.value
		.replace(/((D|d)escription=)/g, 'Description=' + desc + '')
		.replace(/(==Summary==)|(== Summary ==)/g, '=={{int:filedesc}}==').replace(/(==Licensing==)|(== Licensing ==)/g, '=={{int:license}}==').replace(/({{description missing}})/g, '');
	document.editform.wpSummary.value = 'Adding a description';
	document.editform.wpWatchthis.checked = false;
	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', 'cleanup');
	if(targets.length === 0) return true;
	
	targets[0].style.textAlign = 'center';

		var passlink = wgScript+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit&functionName=LicenseReviewChange";
	
		targets[0].innerHTML = '[<a href="'+passlink+'">Add Description</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("LicenseReview_P", "AddDesc", 6, "top");
	});
} else {
	addFunction("LicenseReview_P", "AddDesc", 6, "top");
}

});
// </source>