User:Avicennasis/nowcommonsreview.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Avicennasis/nowcommonsreview. |
//<source lang=javascript>
/**
* NowCommonsReview tagger
* URL: http://en.wikipedia.org/wiki/User:MGA73/nowcommonsreview.js
* Credits:
* MGA73, ZooFari, Krinkle
*
* Based on http://commons.wikimedia.org/wiki/User:ZooFari/licensereviewer.js by Patstuart
*/
window.nowcommonsreview = "0.20 (2010-06-23)";
// NowCommons review passed
function NowCommonsReviewOK(autosave){
var needAppend=document.editform.wpTextbox1.value;
document.editform.wpTextbox1.value = needAppend.replace(/({{([Nn]ow|[Dd]b-now|[Mm]oved *to) *(C|c)ommons([^\}]*?)|[Dd]b-[Ff]8)}}/g, '$1|reviewer=' + mw.config.get("wgUserName") + '}}{{db-f8}}');
document.editform.wpSummary.value = '[[Template:NowCommons|NowCommons review]] passed (using [[User:MGA73/nowcommonsreview.js|nowcommonsreviewer]])';
document.editform.wpMinoredit.checked = true;
if(autosave){ document.editform.submit(); }
}
// NowCommons review failed
function NowCommonsReviewNotOK(autosave){
var needAppend=document.editform.wpTextbox1.value;
var reason = window.prompt("Reason for failed NowCommons review:","");
if (reason===null) {return;} /* on cancel button, actually cancel */
document.editform.wpTextbox1.value = needAppend.replace(/({{([Nn]ow|[Dd]b-now|[Mm]oved *to) *(C|c)ommons([^\}]*?)|[Dd]b-[Ff]8)}}/g, '$1|reason=' + reason + '}}').replace(/\{\{([Nn]ow|[Dd]b-now|[Mm]oved *to) *(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 = $("div.nowcommons-reviewme");
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 = mw.config.get("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 passlink = mw.config.get("wgScript")+"?title="+encodeURIComponent(mw.config.get("wgPageName"))+"&action=edit&functionName=NowCommonsReviewOK";
var faillink = mw.config.get("wgScript")+"?title="+encodeURIComponent(mw.config.get("wgPageName"))+"&action=edit&functionName=NowCommonsReviewNotOK";
targets[0].innerHTML = '[<a href="'+passlink+'">pass review</a>] [<a href="'+faillink+'">fail review</a>]';
return true;
}
});
// Link/Button maker
function addFunction(functionNameString, buttonDisplayName, buttonID){
if (mw.util.getParamValue('functionName')==functionNameString){
$(function(){
eval(functionNameString+"(true)");
});
}
var _href;
if (mw.config.get("wgAction")=="edit" || mw.config.get("wgAction")=="submit"){
_href = "javascript:"+functionNameString+"(true);";
} else {
_href = mw.config.get("wgScript")+"?title="+encodeURIComponent(mw.config.get("wgPageName"))+"&action=edit&functionName="+functionNameString;
}
// Add buttons
$(function(){ mw.util.addPortletLink('p-cactions', _href, buttonDisplayName, 'ca-'+buttonID, '', null, 0); });
$(function(){ mw.util.addPortletLink('p-tb', _href, buttonDisplayName, 'tb-'+buttonID, '', null, 0); });
}
// Fire it off:
addFunction("NowCommonsReviewOK", "NowCommons OK", "nowcommonsreview");
addFunction("NowCommonsReviewNotOK", "NowCommons Not OK", "nowcommonsreview");
//</source>