User:Paranomia/commonsextra.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:Paranomia/commonsextra. |
// <nowiki>
// CommonsHelper Helper (CH²) by Krimpet
// Released into the public domain
// wikEd compatibility patch by Paranomia
var ch2_wplanguage = "en";
var ch2_wpproject = "wikipedia";
var ch2_chlanguage = "en";
var ch2_edittitle_Prefix = "Editing Image:";
var ch2_edittitle_Postfix = "";
var ch2_string_SpecifyNewName = "New Name? (leave blank to keep original):";
var ch2_string_UseWikiSense = "Use WikiSense to suggest categories?";
var ch2_string_StartCommonsHelper = "Start CommonsHelper";
var ch2_string_FinishedUploading = "Click when finished uploading";
var ch2_string_Done = "Done! Review everything below to ensure it is correct, and save this page.";
var ch2_string_MoveToCommons = "Move image to Commons";
var ch2_string_EditSummary = "[[Wikipedia:Moving images to the Commons|Moved image to the Wikimedia Commons]] using [[User:Krimpet/CommonsHelper Helper|CH²]]";
var ch2_template_ncd = "subst:ncd";
var ch2_templates_copy = new Array(
"Copy to Wikimedia Commons",
"Move to Wikimedia Commons",
"Move to Commons",
"Move to commons",
"To Commons",
"to Commons"
);
var ch2_templates_embed = new Array(
"PD-USGov-HHS-CDC",
"PD-USGov-USDA-ARS"
);
var ch2 = null;
var ch2frame = null, ch2framedoc = null;
var newName = "";
var imageTitle = "";
function ch2Form() {
ch2.innerHTML = "<b>" + ch2_string_SpecifyNewName + " <input id=\"newnamet\"><br /><input id=\"csense\" type=checkbox value=1 /><b>" + ch2_string_UseWikiSense + "</b><br /><button onClick=\"ch2Start();\">" + ch2_string_StartCommonsHelper + "</button>";
}
function ch2Start() {
newName = document.getElementById("newnamet").value;
var sense = document.getElementById("csense").checked;
ch2.innerHTML = "<iframe name=\"CH2iframe\" id=\"CH2iframe\" height=\"300\" width=\"100%\"></iframe><br/><button onClick=\"ch2Finalize()\">" + ch2_string_FinishedUploading + "</button>";
ch2frame = document.getElementById("CH2iframe");
ch2framedoc = ch2frame.contentDocument;
if (ch2framedoc == undefined || ch2framedoc == null)
ch2framedoc = ch2frame.contentWindow.document;
ch2framedoc.open();
ch2framedoc.write("Enter a wikipedia language code and image name, and it will generate an image description to copy-and-paste for the commons upload form.</small><br/><form action=\'http://tools.wikimedia.de/~magnus/commonshelper.php?interface=" + ch2_chlanguage + "\' method=\'post\'>Language code: <input type=text name=language value=\'" + ch2_wplanguage + "\' cols=4/><br/>Image name: <input type=text name=image value=\'" + imageTitle + "\' cols=30/><br/>New name: <input type=text name=newname value=\'" + newName + "\' cols=30/> (for direct upload only; leave blank to keep original name)<br/>Project: <input type=text name=project value=\'" + ch2_wpproject + "\' cols=30/> (may also be wikibooks or wikisource)<br/><input type=checkbox name=commonsense value=1 " + (sense ? "checked" : "") + " />Use WikiSense to suggest categories<br/><input type=submit name=doit value=\'Get text\'/></form><script>document.forms[0].doit.click();</script>");
ch2framedoc.close();
}
function ch2Finalize() {
ncd = "{{" + ch2_template_ncd + (newName != "" ? "|Image:" + newName : "") + "}}";
if (typeof(wikEdUseWikEd) != 'undefined') {
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
}
}
editBox = document.editform.wpTextbox1;
for (var i = 0; i < ch2_templates_copy.length; i++)
editBox.value = editBox.value.replace("\{\{" + ch2_templates_copy[i] + "\}\}", ncd);
for (var i = 0; i < ch2_templates_embed.length; i++)
editBox.value = editBox.value.replace("\{\{" + ch2_templates_embed[i] + "\}\}", "\{\{" + ch2_templates_embed[i] + "|commons=" + ncd + "\}\}");
if (editBox.value.indexOf(ncd) == -1)
editBox.value += "\n" + ncd;
if (typeof(wikEdUseWikEd) != 'undefined') {
if (wikEdUseWikEd == true) {
WikEdUpdateFrame();
}
}
document.editform.wpSummary.value = ch2_string_EditSummary;
ch2.innerHTML = "<b>" + ch2_string_Done + "</b>";
}
function ch2Init() {
if (typeof ch2I18N != "undefined")
ch2I18N();
var pageTitle = document.getElementsByTagName('h1')[0].firstChild.nodeValue;
if (pageTitle.substring(0, ch2_edittitle_Prefix.length) != ch2_edittitle_Prefix ||
pageTitle.substring(pageTitle.length - ch2_edittitle_Postfix.length) != ch2_edittitle_Postfix)
return;
imageTitle = pageTitle.substring(ch2_edittitle_Prefix.length, pageTitle.length - ch2_edittitle_Postfix.length)
if (/*document.editform.wpTextbox1.value.indexOf("NowCommons") == -1 &&
document.editform.wpTextbox1.value.indexOf("subst:ncd") == -1 &&*/
document.getElementById("wikiPreview").innerHTML.length == 0) {
hostDiv = document.getElementById("toolbar");
if (hostDiv == null) hostDiv = document.getElementById("siteSub");
hostDiv.innerHTML = "<br><br><div id=\"CH2div\"></div><br>" + hostDiv.innerHTML;
ch2 = document.getElementById("CH2div");
ch2.innerHTML = "<button onClick=\"ch2Form();\">" + ch2_string_MoveToCommons + "</button>";
}
}
addOnloadHook(ch2Init);
// </nowiki>