User:MGA73/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. |
This user script seems to have a documentation page at User:MGA73/nowcommonsreview. |
//<source lang=javascript>
/*global $, mw */
/**
* 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
*/
(function (window, $){
window.nowcommonsreview = "0.20 (2010-06-23)";
$.when(mw.loader.using( ["mediawiki.util"] ), $.ready.promise).then(function () {
if (mw.config.get("wgNamespaceNumber") === 6) {
var actions = [
// NowCommons review passed
{
fn: function (){
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") + "}}");
document.editform.wpSummary.value = "[[Template:NowCommons|NowCommons review]] passed (using [[User:MGA73/nowcommonsreview.js|nowcommonsreviewer]])";
document.editform.wpMinoredit.checked = true;
document.editform.submit();
},
name: "NowCommonsReviewOK",
displayName: "NowCommons OK"
},
// NowCommons review failed
{
fn: function (){
var needAppend = document.editform.wpTextbox1.value;
var reason = window.prompt("Reason for failed NowCommons review:","");
/* on cancel button, actually cancel */
if (reason !== null) {
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;
document.editform.submit();
}
},
name: "NowCommonsReviewNotOK",
displayName: "NowCommons Not OK"
}
];
// [review] link inserter
var html;
if (mw.config.get("wgCategories").join("|").match(/Wikipedia files reviewed on Wikimedia Commons/)){
// This page is in a reviewed category. Dont display links.
html = "<small>Already reviewed</small>";
} else { // This NowCommons page isn't reviewed yet. Show links.
html = actions.map(function (action){
return "[" + $("<a></a>").attr("href", mw.config.get("wgScript") + "?title=" +
encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&functionName=" +
action.name).text(action.displayName)[0].outerHTML + "]";
}).join(" ");
}
$("div.nowcommons-reviewme").css("text-align", "center").html(html);
// Link/Button maker
actions.forEach(function (action){
//functionNameString, buttonDisplayName, callback
if (mw.util.getParamValue("functionName") == action.name){
action.fn(true);
} else {
var _href;
var callback;
if (["edit", "submit"].indexOf(mw.config.get("wgAction")) > -1){
_href = "javascript:void(0);";
callback = action.fn;
} else {
_href = mw.config.get("wgScript") + "?title=" + encodeURIComponent(mw.config.get("wgPageName")) + "&action=edit&functionName=" + action.name;
}
// Add buttons
[["cactions", "ca"], ["tb", "tb"]].forEach(function (actionData) {
var node = mw.util.addPortletLink("p-" + actionData[0], _href, action.displayName, "ca-" + actionData[1], "", null, 0);
if (callback) {
$(node).click(callback);
}
});
}
});
}
});
}(window, $));
//</source>