MediaWiki:HalopediaUpload.js

// // Original script written by Espyo for Pikipedia // https://www.pikminwiki.com/MediaWiki:PikipediaUpload.js

var description_textarea; var type_select; var media_select; var specific_media_text; var game_select; var specific_game_text; var film_select; var specific_film_text; var comic_select; var specific_comic_text; var artist_select; var specific_artist_text; var source_select; var specific_source_text; var license_select; var final_textarea;

var description_tr; var type_tr; var media_tr; var specific_media_span; var game_tr; var specific_game_span; var film_tr; var specific_film_span; var comic_tr; var specific_comic_span; var artist_tr; var specific_artist_span; var source_tr; var specific_source_span; var license_tr; var final_tr;

var final_toggler_a;

var has_media = false; var has_game = false; var has_film = false; var has_comic = false; var has_artist = false; var has_license = false;

function main { if(typeof(mw) === "undefined" || mw.config.get("wgCanonicalNamespace") != "Special" || mw.config.get("wgTitle") != "Upload") return; if(window.location.href.indexOf("wpForReUpload=1") != -1) return;

//Get the table with the upload fields. var table = document.getElementById("mw-htmlform-description").firstChild; if(document.getElementById("wpUploadDescription") && document.getElementById("wpUploadDescription").value.length > 0) { //Hold on, there's already text here! Chances are this is the warning page. //Let's just hide the license box and quit. hide_license(table); return; }

//Hide the edit tools document.getElementsByClassName("mw-editTools")[0].style.display = "none";

create_description_textarea(table); create_media_list(table); create_game_list(table); create_film_list(table); create_comic_list(table); create_type_list(table); create_artist_list(table); create_source_list(table); create_license_list(table); hide_license(table); setup_final(table); handle_type_choice; }

function create_description_textarea(table) { description_textarea = document.createElement("textarea"); description_textarea.cols = "80"; description_textarea.onchange = create_final_result; description_tr = add_field("Summary:", description_textarea, table); }

function create_type_list(table) { var type_span = document.createElement("span"); type_select = document.createElement("select"); type_select.name = "type"; type_select.onchange = handle_type_choice; type_span.appendChild(type_select); add_option("screenshot", "Screenshot", type_select); add_option("concept", "Concept art", type_select); add_option("cover", "Cover art", type_select); add_option("render", "Render", type_select); add_option("asset", "Asset", type_select); add_option("logo", "Logo", type_select); add_option("icon", "Icon", type_select); add_option("audio", "Audio", type_select); add_option("document", "Document", type_select); add_option("real", "Real-world image", type_select); add_option("nonhalo", "Non-Halo image", type_select); add_option("user", "Personal user image", type_select); add_option("wiki", "Halopedia site image", type_select); specific_type_span = document.createElement("span"); type_span.appendChild(specific_type_span); specific_type_span.appendChild(document.createTextNode(" (use screenshot for comic/book page) ")); type_tr = add_field("File type:", type_span, table); }

function create_media_list(table) { var media_span = document.createElement("span"); media_select = document.createElement("select"); media_select.name = "media"; media_select.onchange = handle_media_choice; media_span.appendChild(media_select); add_option("game", "Game", media_select); add_option("film", "Film/series", media_select); add_option("comic", "Comic/graphic novel", media_select); add_option("book", "Other book", media_select); add_option("marketing", "Marketing material", media_select); add_option("merchandise", "Merchandise", media_select); add_option("website", "Website", media_select); add_option("other", "Other/Non-Halo media", media_select); specific_media_span = document.createElement("span"); media_span.appendChild(specific_media_span); specific_media_text = document.createElement("input"); specific_media_text.size = "42"; specific_media_text.onchange = create_final_result; specific_media_span.appendChild(document.createTextNode(" Please enter the book name exactly: ")); specific_media_span.appendChild(specific_media_text); media_tr = add_field("Media:", media_span, table); }

function create_game_list(table) { var game_span = document.createElement("span"); game_select = document.createElement("select"); game_select.name = "game"; game_select.onchange = handle_game_choice; game_span.appendChild(game_select); add_media("Halo: Combat Evolved", game_select); add_media("Halo: Combat Evolved Anniversary", game_select); add_media("Halo 2", game_select); add_media("Halo 2: Anniversary", game_select); add_media("Halo 3", game_select); add_media("Halo 3: ODST", game_select); add_media("Halo: Reach", game_select); add_media("Halo 4", game_select); add_media("Halo 5: Guardians", game_select); add_media("Halo Infinite", game_select); add_media("Halo: The Master Chief Collection", game_select); add_media("Halo Wars", game_select); add_media("Halo Wars 2", game_select); add_media("Halo: Spartan Assault", game_select); add_media("Halo: Spartan Strike", game_select); add_media("Halo: Fireteam Raven", game_select); add_media("Other", game_select); specific_game_span = document.createElement("span"); game_span.appendChild(specific_game_span); specific_game_text = document.createElement("input"); specific_game_text.size = "30"; specific_game_text.onchange = create_final_result; specific_game_span.appendChild(document.createTextNode(" Please enter the game name exactly: ")); specific_game_span.appendChild(specific_game_text); game_tr = add_field("Game:", game_span, table); }

function create_film_list(table) { var film_span = document.createElement("span"); film_select = document.createElement("select"); film_select.name = "film"; film_select.onchange = handle_film_choice; film_span.appendChild(film_select); add_media("Halo Legends", film_select); add_media("Halo 4: Forward Unto Dawn", film_select); add_media("Halo: Nightfall", film_select); add_media("Halo: The Television Series", film_select); add_media("Halo: The Fall of Reach", film_select); add_media("Halo: The Complete Video Collection", film_select); add_media("Other", film_select); specific_film_span = document.createElement("span"); film_span.appendChild(specific_film_span); specific_film_text = document.createElement("input"); specific_film_text.size = "24"; specific_film_text.onchange = create_final_result; specific_film_span.appendChild(document.createTextNode(" Please enter the film/series name exactly: ")); specific_film_span.appendChild(specific_film_text); film_tr = add_field("Film/series:", film_span, table); }

function create_comic_list(table) { var comic_span = document.createElement("span"); comic_select = document.createElement("select"); comic_select.name = "comic"; comic_select.onchange = handle_comic_choice; comic_span.appendChild(comic_select); add_media("Halo: Uprising", comic_select); add_media("Halo: Helljumper", comic_select); add_media("Halo: Blood Line", comic_select); add_media("Halo: Fall of Reach", comic_select); add_media("Halo: Initiation", comic_select); add_media("Halo: Escalation", comic_select); add_media("Halo: Rise of Atriox", comic_select); add_media("Halo: Collateral Damage", comic_select); add_media("Halo: Lone Wolf", comic_select); add_media("Other/graphic novel", comic_select); specific_comic_span = document.createElement("span"); comic_span.appendChild(specific_comic_span); specific_comic_text = document.createElement("input"); specific_comic_text.size = "20"; specific_comic_text.onchange = create_final_result; specific_comic_span.appendChild(document.createTextNode(" Please enter the comic series/graphic novel name exactly: ")); specific_comic_span.appendChild(specific_comic_text); comic_tr = add_field("Comic series:", comic_span, table); }

function create_artist_list(table) { var artist_span = document.createElement("span"); artist_select = document.createElement("select"); artist_select.name = "known"; artist_select.onchange = handle_artist_choice; artist_span.appendChild(artist_select); add_option("unknown", "Unknown", artist_select); add_option("known", "Known artist", artist_select); add_option("self", "I created it", artist_select); specific_artist_span = document.createElement("span"); artist_span.appendChild(specific_artist_span); specific_artist_text = document.createElement("input"); specific_artist_text.size = "58"; specific_artist_text.onchange = create_final_result; specific_artist_span.appendChild(document.createTextNode(" Please enter the artist's name: ")); specific_artist_span.appendChild(specific_artist_text); artist_tr = add_field("Artist:", artist_span, table); }

function create_source_list(table) { var source_span = document.createElement("span"); source_select = document.createElement("select"); source_select.name = "source"; source_select.onchange = handle_source_choice; source_span.appendChild(source_select); add_option("web", "From a website", source_select); add_option("self", "I created the file myself", source_select); add_option("direct", "Direct rip from source media", source_select); specific_source_span = document.createElement("span"); source_span.appendChild(specific_source_span); specific_source_text = document.createElement("input"); specific_source_text.size = "49"; specific_source_text.onchange = create_final_result; specific_source_span.appendChild(document.createTextNode(" Please link to the page: ")); specific_source_span.appendChild(specific_source_text); source_tr = add_field("Source:", source_span, table); }

function create_license_list(table) { license_select = document.createElement("select"); license_select.name = "license"; license_select.onchange = create_final_result; add_option("fairuse", "Fair use (most common)", license_select) add_option("cc-a2.5", "CC-Attribution 2.5", license_select); add_option("cc-a-sa3.0", "CC-Attribution-Share Alike 3.0", license_select); add_option("pd", "Public domain", license_select); add_option("unknown", "I don't know", license_select); license_tr = add_field("License:", license_select, table); }

function handle_type_choice { handle_media_choice; handle_game_choice; handle_film_choice; handle_comic_choice; handle_artist_choice; handle_source_choice; update_fields; }

function handle_media_choice { var cur_media = get_option(media_select); if(cur_media == "book") { specific_media_span.style.display = "inline"; } else { specific_media_span.style.display = "none"; }

if(cur_media == "comic" || cur_media == "book") { specific_type_span.style.display = "inline"; } else { specific_type_span.style.display = "none"; } update_fields; }

function handle_game_choice { var cur_game = get_option(game_select); if(cur_game == "Other") { specific_game_span.style.display = "inline"; } else { specific_game_span.style.display = "none"; } update_fields; }

function handle_film_choice { var cur_film = get_option(film_select); if(cur_film == "Other") { specific_film_span.style.display = "inline"; } else { specific_film_span.style.display = "none"; } update_fields; }

function handle_comic_choice { var cur_comic = get_option(comic_select); if(cur_comic == "Other/graphic novel") { specific_comic_span.style.display = "inline"; } else { specific_comic_span.style.display = "none"; } update_fields; }

function handle_artist_choice { var cur_artist = get_option(artist_select); if(cur_artist == "known") { specific_artist_span.style.display = "inline"; } else { specific_artist_span.style.display = "none"; } update_fields; }

function handle_source_choice { var cur_source = get_option(source_select); if(cur_source == "web") { specific_source_span.style.display = "inline"; } else { specific_source_span.style.display = "none"; } update_fields; }

function update_fields { var cur_type = get_option(type_select); var cur_media = get_option(media_select); var cur_game = get_option(game_select); var cur_film = get_option(film_select); var cur_comic = get_option(film_select); var cur_artist = get_option(artist_select); var cur_source = get_option(source_select); has_media = true; has_game = false; has_film = false; has_comic = false; has_artist = false; has_source = true; has_license = true;

if(cur_media == "game") { has_game = true; }

if(cur_media == "film") { has_film = true; }

if(cur_media == "comic") { has_comic = true; }

if(  (cur_media == "comic" && cur_type == "screenshot") ||   (cur_media == "book" && cur_type == "screenshot") ||    cur_type == "concept" || cur_type == "cover" ||    cur_type == "render" || cur_type == "asset" ||    cur_type == "logo" || cur_type == "icon" ||    cur_type == "audio" || cur_type == "document"  ) { has_artist = true; }

if (has_artist && cur_artist == "self") { has_source = false; }

media_tr.style.display = has_media ? "table-row" : "none"; game_tr.style.display = has_game ? "table-row" : "none"; film_tr.style.display = has_film ? "table-row" : "none"; comic_tr.style.display = has_comic ? "table-row" : "none"; artist_tr.style.display = has_artist ? "table-row" : "none"; source_tr.style.display = has_source ? "table-row" : "none"; license_tr.style.display = has_license ? "table-row" : "none"; create_final_result; }

function create_final_result { var t = ""; var cur_media = get_option(media_select); var cur_type = get_option(type_select); var cur_game = get_option(game_select); var cur_film = get_option(film_select); var cur_comic = get_option(comic_select); var cur_artist = get_option(artist_select); var cur_source = get_option(source_select); var cur_license = get_option(license_select); t += "\n\n" if(t.substr(t.length - 2) == "\n\n") { t = t.slice(0, t.length - 1); } final_textarea.value = t; }

function hide_license(table) { document.getElementById("wpLicense").parentNode.parentNode.style.display = "none"; }

function setup_final(table) { var final_toggler_div = document.createElement("div"); final_toggler_div.style.marginTop = "10px"; final_toggler_a = document.createElement("a"); final_toggler_a.href = "#"; final_toggler_a.innerHTML = "Show" final_toggler_a.onclick = function(e) { e.preventDefault; toggle_final; }; final_toggler_div.appendChild(document.createTextNode("[")); final_toggler_div.appendChild(final_toggler_a); final_toggler_div.appendChild(document.createTextNode("] final result box (if you need fine tuning)")); add_field("", final_toggler_div, table); final_tr = document.getElementById("wpUploadDescription").parentNode.parentNode; final_textarea = final_tr.getElementsByTagName("textarea")[0]; final_tr.style.display = "none"; final_tr.parentNode.appendChild(final_tr); //Move to last row. }

function toggle_final { if(final_tr.style.display == "none") { final_tr.style.display = "table-row"; final_toggler_a.innerHTML = "Hide"; } else { final_tr.style.display = "none"; final_toggler_a.innerHTML = "Show"; } }

function clear_el(el) { while(el.firstChild){ el.removeChild(el.firstChild); } }

function get_option(sel) { if (sel.options.length == 0) return null; return sel.options[sel.selectedIndex].value; }

function add_option(value, innerHTML, parent, selected) { var opt = document.createElement("option"); opt.value = value; opt.innerHTML = innerHTML; parent.appendChild(opt); if(typeof(selected) != "undefined") { opt.setAttribute("selected", ""); } return opt; }

function add_media(value, parent, selected) { var opt = document.createElement("option"); opt.value = value; opt.innerHTML = value; parent.appendChild(opt); if(typeof(selected) != "undefined") { opt.setAttribute("selected", ""); } return opt; }

function add_optgroup(label, parent) { var optgroup = document.createElement("optgroup"); optgroup.label = label; parent.appendChild(optgroup); return optgroup; }

function add_field(label, content, table) { var tr = document.createElement("tr"); var td1 = document.createElement("td"); td1.className = "mw-label"; td1.innerHTML = label; tr.appendChild(td1); var td2 = document.createElement("td"); td2.className = "mw-input"; td2.appendChild(content); tr.appendChild(td2); var ref = table.children[table.children.length - 3]; table.insertBefore(tr, ref); return tr; }

main;

//