User:ZooFari/QICtest.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>

// Promotion
function promo(autosave){
	var needAppend=document.editform.wpTextbox1.value;
	document.editform.wpTextbox1.value = needAppend.replace(/({{(N|n|db-n|Db-n)ow(C|c)ommons([^\}]*?))}}/g, '$1|reviewer=' + wgUserName + '}}');

	document.editform.wpSummary.value = 'Promoted one image';
	document.editform.wpMinoredit.checked = true;

	if(autosave){ document.editform.submit(); }
}

// Decline
function decline(autosave){
	var needAppend=document.editform.wpTextbox1.value;

	var reason = window.prompt("Reason for failed NowCommons review:","");
	document.editform.wpTextbox1.value = needAppend.replace(/({{(N|n|db-n|Db-n)ow(C|c)ommons([^}]*?))}}/g, '$1|reason=' + reason + '}}').replace(/\{\{(N|n|db-n|Db-n)ow(C|c)ommons/g, '{{NotMovedToCommons');

	document.editform.wpSummary.value = '[[Template:NowCommons|NowCommons review]] failed (using [[User:MGA73/nowcommonsreview.js|nowcommonsreviewer]])';
	document.editform.wpMinoredit.checked = true;

	if(autosave){ document.editform.submit(); }
}

// [review] link inserter
$(function(){

	var targets = getElementsByClassName(document, 'div', 'review-me');
	if(targets.length === 0) return true; // NowCommons is not on this page, return the function.
	
	targets[0].style.textAlign = 'center'; // center the text

	var catstring = wgCategories.join("|");

	if(catstring.match(/Wikipedia files reviewed on Wikimedia Commons/)){
		// This page is in a reviewed category. Dont display links.
		targets[0].innerHTML = '<small>Already reviewed</small>';
		return true; 

	} else { // This NowCommons page isn't reviewed yet. Show links.
		var promolink = wgScript+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit&functionName=promo";
		var declinelink = wgScript+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit&functionName=decline";
	
		targets[0].innerHTML = '[<a href="'+promolink+'">promo</a>] [<a href="'+declinelink+'">decline</a>]';
		return true;
	}	
});

// Link/Button maker
function addFunction(functionNameString, buttonDisplayName, buttonID){

	if (getURLParamValue('functionName')==functionNameString){
		addOnloadHook(function(){
			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;
	}

	// Add buttons
	addOnloadHook(function(){ mw.util.addPortletLink('p-cactions', _href, buttonDisplayName, 'ca-'+buttonID, '', null, 0); });
	addOnloadHook(function(){ mw.util.addPortletLink('p-tb', _href, buttonDisplayName, 'tb-'+buttonID, '', null, 0); });
}

addFunction("NowCommonsReviewOK", "NowCommons OK", "nowcommonsreview");
addFunction("NowCommonsReviewNotOK", "NowCommons Not OK", "nowcommonsreview");

//</source>