User:Paranomia/commonsextra.js

// // 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 = "Moved image to the Wikimedia Commons using 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 = "" + ch2_string_SpecifyNewName + "  " + ch2_string_UseWikiSense + " " + ch2_string_StartCommonsHelper + " "; }

function ch2Start { newName = document.getElementById("newnamet").value; var sense = document.getElementById("csense").checked; ch2.innerHTML = " " + ch2_string_FinishedUploading + " "; 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. Language code:  Image name:  New name:  (for direct upload only; leave blank to keep original name) Project:  (may also be wikibooks or wikisource) Use WikiSense to suggest categories  document.forms[0].doit.click; "); ch2framedoc.close; }

function ch2Finalize { ncd = ""; 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 = "" + ch2_string_Done + ""; }

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 = "   " + hostDiv.innerHTML; ch2 = document.getElementById("CH2div"); ch2.innerHTML = "" + ch2_string_MoveToCommons + " "; } } addOnloadHook(ch2Init); //