MediaWiki:HalopediaUpload.js

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

var description_textarea; var type_select; var creator_select; var specific_creator_text; var media_select; var game_select; var film_select; var prerelease_source_select; var mode_select; var location_select; var subject_select; var specific_subject_text; var misc_select; var source_select; var specific_source_text; var license_select; var final_textarea;

var description_tr; var type_tr; var creator_tr; var specific_creator_span; var media_tr; var game_tr; var film_tr; var prerelease_source_tr; var mode_tr; var location_tr; var subject_tr; var specific_subject_span; var misc_tr; var source_tr; var specific_source_span; var license_tr; var final_tr;

var final_toggler_a;

var has_creator = false; var has_media = false; var has_game = false; var has_film = false; var has_prerelease_source = false; var has_mode = false; var has_location = false; var has_subject = false; var has_misc = 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_type_list(table); create_creator_list(table); create_media_list(table); create_game_list(table); create_film_list(table); create_prerelease_source_list(table); create_mode_list(table); create_location_list(table); create_subject_list(table); create_misc_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("Description:", description_textarea, table); }

function create_type_list(table) { type_select = document.createElement("select"); type_select.name = "type"; type_select.onchange = handle_type_choice; add_option("screenshot", "Screenshot", type_select); add_option("coverart", "Cover art", type_select); add_option("comic", "Comic", type_select); add_option("audio", "Audio", type_select); add_option("concept", "Concept art", type_select); add_option("asset", "Asset", type_select); add_option("document", "Document", type_select); add_option("merch", "Merchandise image", type_select); add_option("logo", "Logo", type_select); add_option("icon", "Icon", type_select); add_option("map", "Map", type_select); add_option("real", "Real world image", type_select); add_option("nonhalo", "Non-Halo", type_select); add_option("user", "Non-wiki user image", type_select); add_option("wiki", "Halopedia special image", type_select); type_tr = add_field("File type:", type_select, table); }

function create_creator_list(table) { var creator_span = document.createElement("span"); creator_select = document.createElement("select"); creator_select.name = "creator"; creator_select.onchange = handle_creator_choice; creator_span.appendChild(creator_select); add_option("unknown", "Unknown", creator_select); add_option("artist", "Artist", creator_select); add_option("self", "I created it", creator_select); specific_creator_span = document.createElement("span"); creator_span.appendChild(specific_creator_span); specific_creator_text = document.createElement("input"); specific_creator_text.size = "59"; specific_creator_text.onchange = create_final_result; specific_creator_span.appendChild(document.createTextNode(" Please enter the artist's name: ")); specific_creator_span.appendChild(specific_creator_text); creator_tr = add_field("Creator:", creator_span, table); }

function create_media_list(table) { media_select = document.createElement("select"); media_select.name = "media"; media_select.onchange = update_fields; add_option("game", "Game", media_select); add_option("film", "Film", media_select); add_option("marketing", "Marketing", media_select); add_option("website", "Website", media_select); add_option("other", "Other", media_select); media_tr = add_field("Media:", media_select, table); }

function create_game_list(table) { game_select = document.createElement("select"); game_select.name = "game"; game_select.onchange = handle_game_choice; var ot_optgroup = add_optgroup("Original trilogy", game_select); var rs_optgroup = add_optgroup("Reclaimer saga", game_select); var hss_optgroup = add_optgroup("Halo: Spartan series", game_select); var hws_optgroup = add_optgroup("Halo Wars series", game_select); var og_optgroup = add_optgroup("Other games", game_select); add_option("hce", "Halo: Combat Evolved", ot_optgroup); add_option("hcea", "Halo: Combat Evolved Anniversary", ot_optgroup); add_option("h2", "Halo 2", ot_optgroup); add_option("h2a", "Halo 2: Anniversary", ot_optgroup); add_option("h3", "Halo 3", ot_optgroup); add_option("h4", "Halo 4", rs_optgroup); add_option("h5g", "Halo 5: Guardians", rs_optgroup); add_option("hi", "Halo Infinite", rs_optgroup); add_option("hsa", "Halo: Spartan Assault", hss_optgroup); add_option("hss", "Halo: Spartan Strike", hss_optgroup); add_option("hw", "Halo Wars", hws_optgroup); add_option("hw2", "Halo Wars 2", hws_optgroup); add_option("odst", "Halo 3: ODST", og_optgroup); add_option("reach", "Halo: Reach", og_optgroup); add_option("hfr", "Halo: Fireteam Raven", og_optgroup); add_option("mcc", "Halo: The Master Chief Collection", og_optgroup); add_option("other", "Not listed", og_optgroup); game_tr = add_field("Game:", game_select, table); }

function create_film_list(table) { film_select = document.createElement("select"); film_select.name = "film"; film_select.onchange = update_fields; add_option("legends", "Halo Legends", film_select); add_option("h4fud", "Halo 4: Forward Unto Dawn", film_select); add_option("nightfall", "Halo: Nightfall", film_select); add_option("htts", "Halo: The Television Series", film_select); add_option("htfor", "Halo: The Fall of Reach", film_select); add_option("htcvc", "Halo: The Complete Video Collection", film_select); add_option("gamefilms", "Game tie-ins", film_select); add_option("other", "Other", film_select); film_tr = add_field("Film series:", film_select, table); }

function create_prerelease_source_list(table) { prerelease_source_select = document.createElement("select"); prerelease_source_select.name = "prerelease_source"; prerelease_source_select.onchange = handle_prerelease_source; //No prerelease images are being uploaded right now. //add_option("",  "",   prerelease_source_select); prerelease_source_tr = add_field("Exact source:", prerelease_source_select, table); }

function create_mode_list(table) { mode_select = document.createElement("select"); mode_select.name = "mode"; mode_select.onchange = handle_mode_choice; mode_tr = add_field("Version:", mode_select, table); }

function create_location_list(table) { location_select = document.createElement("select"); location_select.name = "location"; location_select.onchange = handle_location_choice; location_tr = add_field("In-game location:", location_select, table); }

function create_subject_list(table) { var subject_span = document.createElement("span"); subject_select = document.createElement("select"); subject_select.name = "subject"; subject_select.onchange = handle_subject_choice; add_option("none", "N/A", subject_select); var spec_optgroup = add_optgroup("A specific creature", subject_select); var collectible_optgroup = add_optgroup("A collectible", subject_select); var object_optgroup = add_optgroup("An in-game object", subject_select); add_option("character", "Character",           spec_optgroup); add_option("halo",      "Halo",                spec_optgroup); add_option("enemy",     "Enemy",               spec_optgroup); add_option("ship_part", "Ship part",           collectible_optgroup); add_option("treasure",  "Treasure",            collectible_optgroup); add_option("fruit",     "Fruit",               collectible_optgroup); add_option("onion",     "Onion",               object_optgroup); add_option("plant",     "Plant",               object_optgroup); add_option("obstacle",  "Obstacle",            object_optgroup); specific_subject_span = document.createElement("span"); var specific_subject_label = document.createTextNode(" Specifically what? "); specific_subject_span.appendChild(specific_subject_label); specific_subject_text = document.createElement("input"); specific_subject_text.style.width = "100px"; specific_subject_text.onchange = create_final_result; specific_subject_span.appendChild(specific_subject_text); subject_span.appendChild(subject_select); subject_span.appendChild(specific_subject_span); subject_tr = add_field("Main subject:", subject_span, table); }

function create_misc_list(table) { misc_select = document.createElement("select"); misc_select.name = "misc"; misc_select.onchange = update_fields; add_option("none",       "N/A",                  misc_select); add_option("glitch",     "Glitch",               misc_select); add_option("menu",       "In-game menu",         misc_select); add_option("cutscene",   "Cutscene",             misc_select); add_option("prerelease", "Prerelease content",   misc_select); add_option("promotional", "Promotional material", misc_select); misc_tr = add_field("Misc. categories:", misc_select, 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("none", "Please select a source...", source_select); add_option("web", "From a website", source_select); add_option("self", "I created the file myself", source_select); add_option("direct", "Direct from source files", source_select); specific_source_span = document.createElement("span"); source_span.appendChild(specific_source_span); specific_source_text = document.createElement("input"); specific_source_text.size = "53"; 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("unknown",   "I don't know...",                license_select); add_option("fairuse",   "Fair use",                       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); license_tr = add_field("License:", license_select, table); }

function handle_type_choice { handle_game_choice; handle_subject_choice; handle_source_choice; handle_creator_choice; update_fields; }

function handle_game_choice { clear_el(mode_select); var modes = []; var cur_game = get_option(game_select); if(cur_game == "hce") { modes = [ "Original", "PC", "Mac", "Custom edition" ]; } else if(cur_game == "h2") { modes = [ "Original", "PC" ]; } else if(cur_game == "h3") { modes = [ "Original", "Mythic" ]; } else if(cur_game == "h5g") { modes = [ "Original", "Forge" ]; } else if(cur_game == "hw") { modes = [ "Original", "Definitive edition" ]; } else if(cur_game == "mcc") { modes = [ "Halo: Combat Evolved Anniversary", "Halo 2: Anniversary", "Halo 3", "Halo 3: ODST", "Halo: Reach", "Halo 4" ]; }  for(m = 0; m < modes.length; m++) { add_option(modes[m], modes[m], mode_select); } has_mode = (modes.length > 0); handle_mode_choice; }

function handle_prerelease_source { update_fields; }

function handle_mode_choice { clear_el(location_select); var locations = []; var cur_game = get_option(game_select); var cur_mode = get_option(mode_select); if(cur_game == "p1" || cur_game == "npcp1") { locations = [ "The Impact Site", "The Forest of Hope", "The Forest Navel", "The Distant Spring", "The Final Trial" ]; } else if(cur_game == "p2" || cur_game == "npcp2") { locations = [ "Valley of Repose", "Awakening Wood", "Perplexing Pool", "Wistful Wild", "Story mode cave" ]; } else if(cur_game == "p3") { locations = [ "Tropical Wilds", "Garden of Hope", "Distant Tundra", "Twilight River", "Formidable Oak" ]; } else if(cur_game == "hp") { locations = [ "Brilliant Garden", "Verdant Waterfront", "Sparkling Labyrinth", "Ravaged Rustworks", "Leafswirl Lagoon", "Sweltering Parchlands", "Snowfall Field", "Lushlife Murk", "The Final Stretch" ]; }  locations.splice(0, 0, "N/A"); for(l = 0; l < locations.length; l++) { add_option(locations[l], locations[l], location_select); } has_location = (locations.length > 0); update_fields; }

function handle_location_choice { update_fields; }

function handle_subject_choice { var cur_subject = get_option(subject_select); if(cur_subject == "character" || cur_subject == "halo" || cur_subject == "enemy") { specific_subject_span.style.display = "inline"; } else { specific_subject_span.style.display = "none"; } update_fields; }

function handle_creator_choice { var cur_creator = get_option(creator_select); if(cur_creator == "artist") { specific_creator_span.style.display = "inline"; } else { specific_creator_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_creator = get_option(creator_select); var cur_media = get_option(media_select); var cur_game = get_option(game_select); var cur_film = get_option(film_select); var cur_prerelease_source = get_option(prerelease_source_select); var cur_mode = get_option(mode_select); var cur_source = get_option(source_select); has_creator = false; has_media = false; has_game = false; has_film = false; has_prerelease_source = false; has_mode = false; has_location = false; has_subject = false; has_misc = false; has_source = true; has_license = true;

if(   cur_type == "coverart" || cur_type == "comic" ||    cur_type == "concept" || cur_type == "asset" ||    cur_type == "document" || cur_type == "logo" ||    cur_type == "icon" || cur_type == "map" ||    cur_type == "audio"  ) { has_creator = true; } if(    cur_type == "screenshot" || cur_type == "audio" ||    cur_type == "concept" || cur_type == "asset"  ) { has_media = true; }

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

if(has_media && cur_media == "film") { has_film = true; } if(cur_type == "screenshot" && cur_media == "game") { if(get_game_has_location(cur_game)) { has_mode = true; has_location = true; has_subject = true; has_misc = true; }   if((cur_game == "p2" || cur_game == "npcp2") && cur_mode != "Story mode") { has_location = false; }   if(cur_game == "p3" && cur_mode != "Story mode") { has_location = false; }   if(cur_game == "hp" && cur_mode != "Story mode") { has_location = false; }   if(cur_mode == "N/A") { has_location = false; } } else if (cur_type == "concept") { has_location = get_game_has_location(cur_game); has_subject = true; has_misc = true; } else if (cur_type == "map") { has_location = get_game_has_location(cur_game); }

creator_tr.style.display = has_creator ? "table-row" : "none"; 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"; prerelease_source_tr.style.display = has_prerelease_source ? "table-row" : "none"; mode_tr.style.display = has_game && has_mode ? "table-row" : "none"; location_tr.style.display = "none"; subject_tr.style.display = "none"; misc_tr.style.display = "none"; source_tr.style.display = has_source ? "table-row" : "none"; license_tr.style.display = has_license ? "table-row" : "none"; create_final_result; }

function get_game_has_location(g) { var r = g == "hce" || g == "h5g" || g == "h2" || g == "hw" || g == "h3" || g == "mcc"; return r; }

function create_final_result { var t = ""; var cur_type = get_option(type_select); var cur_creator = get_option(creator_select); var cur_media = get_option(media_select); var cur_game = get_option(game_select); var cur_film = get_option(film_select); var cur_prerelease_source = get_option(prerelease_source_select); var cur_mode = get_option(mode_select); var cur_location = get_option(location_select); var cur_subject = get_option(subject_select); var cur_misc = get_option(misc_select); var cur_source = get_option(source_select); var cur_license = get_option(license_select); t += "\n\n" if(has_subject && cur_subject != "N/A") { if(cur_subject == "halo" || cur_subject == "character" || cur_subject == "enemy") { t += "\n"; } else if(cur_subject == "ship_part") { t += "\n"; } else if(cur_subject == "treasure") { t += "\n"; } else if(cur_subject == "fruit") { t += "\n"; } else if(cur_subject == "onion") { t += "\n"; } else if(cur_subject == "plant") { t += "\n"; } else if(cur_subject == "obstacle") { t += "\n"; } }  if(has_misc) { if(cur_misc == "glitch") { t += "\n"; } else if(cur_misc == "menu") { t += "\n"; } else if(cur_misc == "cutscene") { t += "\n"; } else if(cur_misc == "prerelease") { t += "\n"; } else if(cur_misc == "promotional") { t += "\n"; } }  if(has_prerelease_source) { //No prerelease images are being uploaded right now. } 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_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;

//