MediaWiki:PikipediaUpload.js

From Pikipedia, the Pikmin wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//<nowiki>

//TODO instead of a "misc" category for concept art, have a checkbox for "shows prerelease content"?
//TODO allow the user to add multiple subjects?
//TODO subjects should be in a select box?

var description_textarea;
var type_select;
var game_select;
var version_text;
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 game_tr;
var version_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_game = 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;
  if (mw.config.get('wgMFMode'))
    table = document.getElementById("mw-htmlform-description");
  else
    table = document.getElementById("mw-htmlform-description").firstChild;
  
  if(document.getElementById("wpUploadDescription") &&
     document.getElementById("wpUploadDescription").value != "{{file info\n|summary = \n|type = \n|game = \n}}") {
    //Hold on, there's already custom text here! Chances are this is the warning page.
    //Let's just hide the license box and quit.
    hide_license(table);
    return;
  }

  create_description_textarea(table);
  create_type_list(table);
  create_artwork_list(table);
  create_game_list(table);
  create_version_field(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);
  replace_uploadtext();
  create_script_notification();
  
  handle_type_choice();
  
}


function create_description_textarea(table) {
  description_textarea = document.createElement("textarea");
  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("artwork", "Artwork", type_select);
  add_option("boxart", "Box art", type_select);
  add_option("texture", "Texture", type_select);
  add_option("audio", "Audio", type_select);
  add_option("logo", "Logo", type_select);
  add_option("map", "Map", type_select);
  add_option("icon", "Handmade icon", type_select);
  add_option("merch", "Merchandise image", type_select);
  add_option("promo", "Promotional material", type_select);
  add_option("real", "Real world image", type_select);
  add_option("user", "Non-wiki user image", type_select);
  add_option("wiki", "Pikipedia special image", type_select);
  
  type_tr = add_field("Type of file:", type_select, table);
}


function create_game_list(table) {
  game_select = document.createElement("select");
  game_select.name = "game";
  game_select.onchange = handle_game_choice;
  
  var gc_optgroup =     add_optgroup("GameCube",                game_select);
  var wii_optgroup =    add_optgroup("Wii",                     game_select);
  var wiiu_optgroup =   add_optgroup("Wii U",                   game_select);
  var n3ds_optgroup =   add_optgroup("Nintendo 3DS",            game_select);
  var switch_optgroup = add_optgroup("Nintendo Switch",         game_select);
  var smash_optgroup =  add_optgroup("Super Smash Bros. games", game_select);
  var misc_optgroup =   add_optgroup("Other",                   game_select);
  
  add_option("p1",    "<i>Pikmin</i>",                     gc_optgroup);
  add_option("p2",    "<i>Pikmin 2</i>",                   gc_optgroup);
  add_option("npcp1", "<i>New Play Control! Pikmin</i>",   wii_optgroup);
  add_option("npcp2", "<i>New Play Control! Pikmin 2</i>", wii_optgroup);
  add_option("p3",    "<i>Pikmin 3</i>",                   wiiu_optgroup);
  add_option("pa",    "<i>Pikmin Adventure</i>",           wiiu_optgroup);
  add_option("hp",    "<i>Hey! Pikmin</i>",                n3ds_optgroup);
  add_option("p4",    "<i>Pikmin 4</i>",                   switch_optgroup);
  add_option("p3d",   "<i>Pikmin 3 Deluxe</i>",            switch_optgroup);
  add_option("p1s",   "<i>Pikmin 1 (Nintendo Switch)</i>", switch_optgroup);
  add_option("p2s",   "<i>Pikmin 2 (Nintendo Switch)</i>", switch_optgroup);
  add_option("p1+2",  "<i>Pikmin 1+2 bundle</i>",          switch_optgroup);
  add_option("ssbb",  "<i>Super Smash Bros. Brawl</i>",    smash_optgroup);
  add_option("ssb4",  "<i>Super Smash Bros. for Nintendo 3DS and Wii U</i>", smash_optgroup);
  add_option("ssbu",  "<i>Super Smash Bros. Ultimate</i>", smash_optgroup);
  add_option("pb",    "<i>Pikmin Bloom</i>",               misc_optgroup);
  add_option("psm",   "<i>Pikmin</i> Short Movies",        misc_optgroup)
  add_option("other", "Other game",                        misc_optgroup);
  add_option("none",  "N/A",                               misc_optgroup, true);
  
  game_tr = add_field("Game:", game_select, table);
}

function create_artwork_list(table) {
  artwork_select = document.createElement("select");
  artwork_select.name = "artwork";
  artwork_select.onchange = handle_artwork_choice;
  
  add_option("artwork", "General", artwork_select);
  add_option("render", "Render", artwork_select);
  add_option("diorama", "Diorama", artwork_select);
  add_option("sketch", "Sketch", artwork_select);
  add_option("flatart", "Flat art", artwork_select);
  add_option("clayart", "Clay art", artwork_select);
  add_option("enemyart", "Enemy art", artwork_select);
  add_option("treasureart", "Treasure art", artwork_select);
  add_option("conceptart", "Concept art", artwork_select);
  add_option("wallpaper", "Wallpaper", artwork_select);
  
  artwork_tr = add_field("Artwork type:", artwork_select, table);
}


function create_version_field(table) {
  version_text = document.createElement("input");
  version_text.style.width = "100px";
  version_text.onchange = create_final_result;
  version_tr = add_field("Version (optional):", version_text, 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("Game mode:", 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("pikmin",     "Pikmin",              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(" What's the full subject name? ");
  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", "N/A", source_select);
  add_option("self", "I made this myself", source_select);
  add_option("web",  "Off a website", source_select);
  
  specific_source_span = document.createElement("span");
  source_span.appendChild(specific_source_span);
  
  specific_source_text = document.createElement("input");
  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 by-sa 1.0",    "CC Attribution-ShareAlike 1.0",               license_select);
  add_option("cc by-sa 2.1 jp", "CC Attribution-ShareAlike 2.1 Japan",         license_select);
  add_option("cc by 2.0",       "CC Attribution 2.0",                          license_select);
  add_option("cc by-sa 2.0",    "CC Attribution-ShareAlike 2.0",               license_select);
  add_option("cc by-nc-sa 2.0", "CC Attribution-NonCommercial-ShareAlike 2.0", license_select);
  add_option("cc by 2.5",       "CC Attribution 2.5",                          license_select);
  add_option("cc by-sa 2.5",    "CC Attribution-ShareAlike 2.5",               license_select);
  add_option("cc by 3.0",       "CC Attribution 3.0",                          license_select);
  add_option("cc by-sa 3.0",    "CC Attribution-ShareAlike 3.0",               license_select);
  add_option("cc by 4.0",       "CC Attribution 4.0",                          license_select);
  add_option("cc by-sa 4.0",    "CC Attribution-ShareAlike 4.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();
  update_fields();
}


function handle_artwork_choice() {
  update_fields();
}


function handle_game_choice() {
  clear_el(mode_select);
  
  var modes = [];
  var cur_game = get_option(game_select);
  
  if(cur_game == "p1" || cur_game == "npcp1" || cur_game == "p1s") {
    modes = [
      "Story mode",
      "Challenge Mode"
    ];
  } else if(cur_game == "p2" || cur_game == "npcp2" || cur_game == "p2s") {
    modes = [
      "Story mode",
      "Challenge Mode",
      "2-Player Battle"
    ];
  } else if(cur_game == "p3" || cur_game == "p3d") {
    modes = [
      "Story mode",
      "Side Stories",
      "Mission Mode",
      "Bingo Battle"
    ];
  } else if(cur_game == "hp") {
    modes = [
      "Story mode",
      "Pikmin Park"
    ];
  }
  
  if(modes.length > 0) {
    add_option("N/A", "N/A", mode_select);
    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" || cur_game == "p1s") {
    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" || cur_game == "p2s") {
    locations = [
      "Valley of Repose",
      "Awakening Wood",
      "Perplexing Pool",
      "Wistful Wild",
      "Story mode cave"
    ];
  } else if(cur_game == "p3" || cur_game == "p3d") {
    locations = [
      "Tropical Wilds",
      "Garden of Hope",
      "Distant Tundra",
      "Twilight River",
      "Formidable Oak"
    ];
  } else if(cur_game == "p4") {
    locations = [
      "Rescue Command Post",
      "Sun-Speckled Terrace",
      "Blossoming Arcadia",
      "Serene Shores",
      "Hero's Hideaway",
      "Giant's Hearth",
      "Primordial Thicket",
      "Cave",
      "Dandori Challenge",
      "Dandori Battle"
    ];
  } 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 == "pikmin" || cur_subject == "enemy") {
    specific_subject_span.style.display = "inline";
  } else {
    specific_subject_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_artwork = get_option(artwork_select);
  var cur_game = get_option(game_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_artwork = false;
  has_game = false;
  has_version = false;
  has_prerelease_source = false;
  has_location = false;
  has_subject = false;
  has_misc = false;
  has_source = false;
  has_license = false;
  
  if(
    cur_type == "screenshot" || cur_type == "artwork" || cur_type == "boxart" || cur_type == "promo" ||
    cur_type == "texture" || cur_type == "audio" || cur_type == "logo" || cur_type == "map"
  ) {
    has_game = true;
  }
  
  if(cur_type == "screenshot") {
    if(get_game_has_location(cur_game)) {
      has_location = true;
      has_subject = true;
      has_misc = true;
    }
    if(cur_game == "p3" || cur_game == "p3d" || cur_game == "pb") {
      has_version = true;
    }
    if(cur_game == "pb") {
      has_subject = true;
      has_misc = true;
    }
    if((cur_game == "p2" || cur_game == "npcp2" || cur_game == "p2s") && cur_mode != "Story mode") {
      has_location = false;
    }
    if((cur_game == "p3" || cur_game == "p3d") && cur_mode != "Story mode") {
      has_location = false;
    }
    if(cur_game == "hp" && cur_mode != "Story mode") {
      has_location = false;
    }

    if(cur_game == "p4") {
      //Let it show locations.
    } else if(cur_mode == "N/A") {
      has_location = false;
    }
    
  } else if (cur_type == "artwork") {
    has_artwork = true;
    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);
    has_source = true;
    has_license = true;
    
  } else if (cur_type == "icon") {
    has_source = true;
    has_license = true;
    
  } else if (cur_type == "merch" || cur_type == "promo" || cur_type == "real" || cur_type == "user" || cur_type == "wiki") {
    has_source = true;
    has_license = true;
    
  }

  if (mw.config.get('wgMFMode'))
    var show = "block";
  else
    var show = "table-row";

  artwork_tr.style.display =
    has_artwork ? show : "none";
  game_tr.style.display =
    has_game ? show : "none";
  version_tr.style.display =
    has_version ? show : "none";
  prerelease_source_tr.style.display =
    has_prerelease_source ? show : "none";
  mode_tr.style.display =
    has_game && has_mode ? show : "none";
  location_tr.style.display =
    has_game && has_location ? show : "none";
  subject_tr.style.display =
    has_subject ? show : "none";
  misc_tr.style.display =
    has_misc ? show : "none";
  source_tr.style.display =
    has_source ? show : "none";
  license_tr.style.display =
    has_license ? show : "none";
  
  create_final_result();
}


function get_game_has_location(g) {
  var r =
    g == "p1" || g == "npcp1" || g == "p1s" ||
    g == "p2" || g == "npcp2" || g == "p2s" ||
    g == "p3" || g == "p3d" ||
    g == "p4" ||
    g == "hp";
  return r;
}


function create_final_result() {
  var t = "";
  var cur_type = get_option(type_select);
  var cur_game = get_option(game_select);
  var cur_artwork = get_option(artwork_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 += "{{file info\n";
  t += "|summary = " + description_textarea.value + "\n";

  if(cur_type == "artwork") {
    t += "|type = " + cur_artwork + "\n";
  } else {
    t += "|type = " + cur_type + "\n";
  }
  
  if(has_game && cur_game != "none") {
    t += "|game = " + cur_game + "\n";
  }

  if(has_version && version_text.value != "") {
    t += "|version = " + version_text.value + "\n";
  }
  
  if(has_location && cur_location != "N/A") {
    t += "|location = " + cur_location + "\n";
  }
  
  if(has_source && cur_source != "N/A") {
    t += "|source = " + (cur_source == "self" ? "self" : specific_source_text.value) + "\n";
  }
  
  if(has_license) {
    t += "|license = " + cur_license + "\n";
  }
  
  t += "}}\n\n"
  
  if(has_mode) {
    if(cur_mode != "N/A" && cur_mode != "Story mode") {
      var mode_str = cur_mode;
      if(cur_mode == "Challenge Mode" && (cur_game == "p1" || cur_game == "npcp1"  || cur_game == "p1s")) {
        mode_str = "Pikmin 1 Challenge Mode";
      } else if(cur_mode == "Challenge Mode" && (cur_game == "p2" || cur_game == "npcp2" || cur_game == "p2s")) {
        mode_str = "Pikmin 2 Challenge Mode";
      } 
      t += "[[Category:" + mode_str + " images]]\n";
    }
  }
  
  if(has_subject && cur_subject != "N/A") {
    if(cur_subject == "pikmin" || cur_subject == "character" || cur_subject == "enemy") {
      if(specific_subject_text.value != "") {
        t += "[[Category:" + specific_subject_text.value + " images]]\n";
      }
    } else if(cur_subject == "ship_part") {
      t += "[[Category:Ship part images]]\n";
    } else if(cur_subject == "treasure") {
      t += "[[Category:Treasure images]]\n";
    } else if(cur_subject == "fruit") {
      t += "[[Category:Fruit images]]\n";
    } else if(cur_subject == "onion") {
      t += "[[Category:Onion images]]\n";
    } else if(cur_subject == "plant") {
      t += "[[Category:Vegetation images]]\n";
    } else if(cur_subject == "obstacle") {
      t += "[[Category:Obstacle images]]\n";
    }
  }
  
  if(has_misc) {
    if(cur_misc == "glitch") {
      t += "[[Category:Glitch images]]\n";
    } else if(cur_misc == "menu") {
      t += "[[Category:Menu images]]\n";
    } else if(cur_misc == "cutscene") {
      t += "[[Category:Cutscene images]]\n";
    } else if(cur_misc == "prerelease") {
      t += "[[Category:Prerelease images]]\n";
    } else if(cur_misc == "promotional") {
      t += "[[Category:Promotional material]]\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 = "64px";
  
  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 replace_uploadtext() {
  var uploadtext = document.getElementById("uploadtext");
  clear_el(uploadtext);
  
  uploadtext.innerHTML =
    "<p>Use this form to upload new files. Please follow every step in the form. " +
    "Also, use a descriptive name, like <code>Pikmin 3 Burgeoning Spiderwort closeup.jpg</code> " +
    "instead of <code>xGFW34.JPG</code>, and make sure " +
    "your file does not <a href=\"/Special:ListFiles\">already exist</a>.</p>" +
    "<p>Useful links:</p>" +
    "<ul><li><a href=\"/Help:Files\">Help with files</a></li>" +
    "<li><a href=\"/Special:Log/upload\">Upload log</a></li>" +
    "<li><a href=\"/Special:Log/delete\">Deletion log</a></li></ul>";
}


function create_script_notification() {
  var notification_div = document.createElement("div");
  notification_div.style.float = "right";
  notification_div.style.margin = "10px";
  notification_div.style.border = "1px solid";
  notification_div.style.padding = "2px";
  notification_div.style.fontSize = "75%";
  notification_div.style.fontStyle = "italic";
  notification_div.innerHTML = "This page is running the <a href=\"/User:Espyo/PikipediaUpload\">PikipediaUpload</a> script.";
  
  var upload_text = document.getElementById("uploadtext");
  upload_text.parentNode.insertBefore(notification_div, upload_text);
}


function toggle_final() {
  if(final_tr.style.display == "none") {
    if (mw.config.get('wgMFMode'))
      var show = "block";
    else
      var show = "table-row";
    final_tr.style.display = show;
    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) {
  if (mw.config.get('wgMFMode')) {
    var tr = document.createElement("div");
    tr.className = "mw-htmlform-field-HTMLTextField";
    var td1 = document.createElement("div");
    td1.className = "mw-label";
    td1.innerHTML = label;
    tr.appendChild(td1);
    var td2 = document.createElement("div");
    td2.className = "mw-input";
    td2.appendChild(content);
    tr.appendChild(td2);
  } else {
    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();

//</nowiki>