MediaWiki:Gadget-Pikan-pikipedia.js

//

function init_pikan {

pikan.wiki_url = "https://www.pikminwiki.com/"; pikan.help_link = "https://www.pikminwiki.com/User:Espyo/Pikan"; pikan.module_name = "Pikipedia"; pikan.module_version = "1.11.0";

pikan.types["Problem"] = { color:      "#600", background: "rgba(255, 128, 128, 0.8)", description: "General MediaWiki source or general article problems." }; pikan.types["Policy"] = { color:      "#400", background: "rgba(192, 128, 128, 0.8)", description: "Issues that break a policy, specific or implied." }; pikan.types["Style"] = { color:      "#206", background: "rgba(160, 128, 255, 0.8)", description: "Problems that do not affect the page, but when fixed, make the source easier to use." }; pikan.types["Question"] = { color:      "#420", background: "rgba(255, 192, 128, 0.8)", description: "Results that the analyzer cannot decide whether they're real problems or false-positives." };

pikan.find_problems = function{ var reg;

//Find "Wikia" -- we aren't involved with Wikia, so get rid of leftovers. reg = /wikia/igm; pikan.regex_check(reg, "Problem", "\"Wikia\" found. We moved from Wikia years ago, so make sure this isn't a leftover."); //Find "gamepad" reg = /[Gg]amepad/gm; pikan.regex_check(reg, "Problem", "\"Gamepad\" found. The correct spelling for the Wii U's controller is \"GamePad\"."); //Find "Nunchuck" reg = /Nunchuck/igm; pikan.regex_check(reg, "Problem", "\"Nunchuck\" found. The correct spelling of the Wii peripheral is \"Nunchuk\"."); //Find "Gamecube" reg = /Gamecube|Game [cC]ube/gm; pikan.regex_check(reg, "Problem", "\"Gamecube\" found. The correct spelling for the Nintendo console is \"GameCube\"."); //Find sub-optimal names for the Smash 4 games. reg = /(Super Smash Bros\.? for Wii U and 3DS|Super Smash Bros\.? for (Nintendo )?3DS & Wii U|Super Smash Bros\.? for Wii U & (Nintendo )?3DS|Super Smash Bros. 4)/igm; pikan.regex_check(reg, "Problem", "Sub-optimal name for the Smash game found. For consistency's sake, you should only use these names: \"Super Smash Bros. for Nintendo 3DS and Wii U\", \"Super Smash Bros. for Nintendo 3DS\", \"Super Smash Bros. for Wii U\"."); //Find bad names for the inhabitants of Hocotate/Koppai. reg = /(Hocotaitt?e|Kopp?aitt?i?an|Kopaitt?e|Kopp?aii?an)/igm; pikan.regex_check(reg, "Problem", "Bad inhabitant term found. Characters from Hocotate are \"Hocotatian(s)\", and those from Koppai are \"Koppaite(s)\".", "Category:Places"); //Find bad names for Shepherd. reg = /(Shepp?h?ard|Shepph?erd|Sheperd)/igm; pikan.regex_check(reg, "Problem", "Bad name for Shepherd found.", "Shepherd"); //Captions in thumbs that don't exist or lack a period. reg = /^\[\[File\:.+\|thumb.*\]\]/igm; pikan.regex_check(   reg, "Policy", "Image thumbs must have a caption, and it must end with a period.", "Pikipedia:General_content_guidelines#Frames_and_galleries",    function(r){      if(r[0][r[0].length - 3] != ".") return true;      return false;    }  ); //Captions in galleries that don't exist or lack a period. reg = /^.+$/igm; pikan.regex_check(   reg, "Policy", "Images in galleries must have a caption, and it must end in a period.", "Pikipedia:General_content_guidelines#Frames_and_galleries",    function(r){      if(!pikan.in_area(r, "<gallery", " ")) return false;      var slash_pos = r[0].indexOf("|");      if(slash_pos == -1 || slash_pos == r[0].length - 1) return true;      if(r[0][r[0].length - 1] != ".") return true;      return false;    }  ); //Find game names without italicization. reg = /(New Play Control! Pikmin 2|New Play Control! Pikmin|Pikmin 2|Pikmin 3 Deluxe|Pikmin 3|Pikmin 4|Hey! Pikmin|Pikmin Bloom|Pikmin Adventure|Nintendo Land|New Play Control!|Super Smash Bros\. for Nintendo 3DS and Wii U|Super Smash Bros\. (Melee|Brawl|Ultimate))/igm; pikan.regex_check(   reg, "Policy", "Game names should be in italics.", "Pikipedia:General_content_guidelines#Italicizing",    function(r){      if(pikan.is_common_exception(r)) return false;      if( pikan.before(r, 2) == "''" && pikan.after(r, 2) == "''" ){       return false;      }      //Check if the name is a link caption.      //Let's cheat a bit and assume that      //a) the link's text only contains the game name //(otherwise the editor would need the bold inside the link) //b) the italics are placed correctly before the link.     if(pikan.after(r, 4)  == "]]''") return false;      return true;    }  ); //Find "Pikmin 1" in text. reg = /Pikmin 1/igm; pikan.regex_check(   reg, "Policy", "\"Pikmin 1\" found; that's not what the first game is called, so change it to Pikmin.", "Pikipedia:General_content_guidelines#.22Pikmin_1.22",    function(r){      return !pikan.is_common_exception(r);    }  ); //Find "Pikmin 1" in links. reg = /\[\[Pikmin 1(\||\]\])/igm; pikan.regex_check(   reg, "Policy", "\"Pikmin 1\" found; that's not what the first game is called, so link the page to \"Pikmin (game)\".", "Pikipedia:General_content_guidelines#.22Pikmin_1.22"); //Find "Hey Pikmin" in text. reg = /Hey Pikmin/igm; pikan.regex_check(   reg, "Policy", "\"Hey Pikmin\" found; don't forget to add the exclamation mark (!) after the \"Hey\".",    function(r){      return !pikan.is_common_exception(r);    }  ); //Find "Pikmins". reg = /pikmins/igm; pikan.regex_check(reg, "Policy", "\"Pikmins\" found. The plural of \"Pikmin\" is \"Pikmin\".", "Pikmin_family#Naming",   function(r){      return !pikan.is_common_exception(r);    }  ); //Find lowercase "Pikmin". reg = /pikmin/gm; pikan.regex_check(   reg, "Policy", "\"pikmin\" with lowercase 'p' found. The official spelling is always with an uppercase 'P'.", "Pikipedia:General_content_guidelines#Capitalization",    function(r){      return !pikan.is_common_exception(r);    }  ); //Find lowercase Pikmin names. reg = /(red|yellow|blue|purple|white|rock|winged) Pikmin/gm; pikan.regex_check(   reg, "Policy", "Lowercase Pikmin name found. Pikmin type names should start in uppercase.", "Pikipedia:General_content_guidelines#Capitalization",    function(r){      return !pikan.is_common_exception(r);    }  ); //Find lowercase "Onion". reg = /onion/gm; pikan.regex_check(reg, "Policy", "\"onion\" with a lowercase 'o' found. The official spelling is with an uppercase 'O', unless you're talking about the real-world food.", "Pikipedia:General_content_guidelines#Capitalization",   function(r){      return !pikan.is_common_exception(r);    }  ); //Find lowercase "Poko". reg = /poko/gm; pikan.regex_check(reg, "Policy", "\"poko\" with a lowercase 'p' found. The official spelling is with an uppercase 'P'.", "Pikipedia:General_content_guidelines#Capitalization",   function(r){      return !pikan.is_common_exception(r);    }  ); //Find words that start in uppercase needlessly. reg = /\b(Area|Bitter|Bomb-?[Rr]ock|Bomb|Boulder|Bridge|Cardboard [Bb]ox|Cave|Climbing [Ss]tick|Clipboard|Clog|Crystal|Day|Dirt [Mm]ound|Egg|Electrode|Elevator [Pp]latform|Enemy|Fire [Gg]eyser|Fragment|Gate|Leader|Nectar|Nugget|Paper [Bb]ag|Reel|Spicy|Spray|Sublevel|Ultra|Wall|Leafling)\b/gm; pikan.regex_check(   reg, "Policy",    "Common word starting in uppercase found. This word should likely start in lowercase, as there is no reason for it to start with a capital mid-sentence. Check the surrounding words, too.",    "Pikipedia:General_content_guidelines#Capitalization",    function(r){      if((pikan.must_be_upper(r))) return false;      if(pikan.is_common_exception(r)) return false;      return true;    }  ); //Find "NTSC" and "PAL". reg = /\b(NTSC|PAL)\b/igm; pikan.regex_check(reg, "Policy", "\"NTSC\" or \"PAL\" found. Try \"US\" or \"Europe\" instead.", "Pikipedia:General_content_guidelines#Region",   function(r){      return !pikan.is_common_exception(r);    }  ); //Find "alpha" and "beta". reg = /\b(alpha|beta)\b/igm; pikan.regex_check(reg, "Policy", "\"Alpha\" or \"beta\" found. Try \"early\" or \"prototype\" instead.", "Pikipedia:General_content_guidelines#Prerelease",   function(r){      return !pikan.is_common_exception(r);    }  ); //Find P1 area names without the "The". reg = /(Impact Site|Forest of Hope|Forest Navel|Distant Spring|Final Trial)/igm; pikan.regex_check(reg, "Policy", "Bad area name found. Areas from the first Pikmin game should start with \"The\".", null,   function(r){      return !(pikan.before(r, 4) == "The ");    }  ); //Find links to Pikmin. reg = /\[\[Pikmin(\|.+)?\]\]/igm; pikan.regex_check(reg, "Policy", "Link to \"Pikmin\" found. Make this a direct link to the family, series, or game article."); //Find links to Challenge Mode. reg = /\[\[Challenge Mode(\|.+)?\]\]/igm; pikan.regex_check(reg, "Policy", "Link to \"Challenge Mode\" found. Make this a direct link to either the first or the second game's Challenge Mode article."); //Find links to Piklopedia. reg = /\[\[Piklopedia(\|.+)?\]\]/igm; pikan.regex_check(reg, "Policy", "Link to \"Piklopedia\" found. Make this a direct link to one of the specific game Piklopedia articles."); //References not using. reg = //igm; pikan.regex_check(reg, "Policy", "&lt;references/&gt; tag found. Use instead.", "Pikipedia:General_content_guidelines#General"); //Wikipedia link not using. reg = /\[\[wikipedia:/igm; pikan.regex_check(reg, "Policy", "Link to Wikipedia found. You should use template for this."); //Report if there is no "See also" section. reg = /= *See also *=/igm; if(reg.exec(pikan.text) === null) { pikan.save_problem(0, 0, "Policy", "\"See also\" section not found. You should add one if there are any relevant articles to link to.", "Pikipedia:General_content_guidelines#General"); }

//"Battle Strategy" sections should only be called "Strategy". reg = /^=+ +(Battle|Killing) Strategy +=+$/igm; pikan.regex_check(reg, "Policy", "Strategy sections should be called \"Strategy\".", "Pikipedia:General_content_guidelines#Order_for_common_sections"); //"External links" sections with bad names. reg = /^=+ +(Web Links|External Pages) +=+$/igm; pikan.regex_check(reg, "Policy", "External link sections should be called \"External links\".", "Pikipedia:General_content_guidelines#Order_for_common_sections"); //Links in section headers. reg = /==.*\[\[.+\]\].*==/gm; pikan.regex_check(reg, "Policy", "Section headers shouldn't have links.", "Pikipedia:General_content_policy#Headings"); //Bold in section headers. reg = /==.*.+.*==/gm; pikan.regex_check(reg, "Policy", "Section headers shouldn't have bold text.", "Pikipedia:General_content_policy#Headings"); //Title case section header. reg = /^\=+ ?[A-Z].+ +[A-Z].*\=+$/gm; pikan.regex_check(reg, "Question", "This section header seems to be in title case. Make sure you don't capitalize words unless they are a title.", "Pikipedia:General_content_policy#Headings"); //Find level 1 headers. reg = /^=[^=]+=$/gm; pikan.regex_check(reg, "Policy", "Level 1 section found. Only the page title should be a level 1 header, so downgrade this to level 2."); //Common section order. reg = /^==([^=]+)==$/gm; var sec = null; var secs = []; var order = ["Glitches", "Technical information", "Naming", "Gallery", "Trivia", "Names in other languages", "See also", "External links", "References"]; while((sec = reg.exec(pikan.text)) !== null){ var name = sec[1].trim; var is_common_section = false; for(var n = 0; n < order.length; n++){ if(name == order[n]) is_common_section = true; }   if(!is_common_section) continue; secs.push({     name: name,      pos:  sec.index,      len:  sec[0].length    }); } var cur_o = -1; var disorderer = -1; for(var s = 0; s < secs.length; s++){ do{ cur_o++; }while(cur_o < order.length && order[cur_o] != secs[s].name); if(!(cur_o < order.length && order[cur_o] == secs[s].name)){ disorderer = s;     break; } }  if(disorderer != -1){ pikan.save_problem(secs[disorderer].pos, secs[disorderer].len, "Policy", "Section \"" + secs[disorderer].name + "\" appears after section \"" + secs[disorderer - 1].name + "\"; it should appear before.", "Pikipedia:General_content_guidelines#Order_for_common_sections"); } //Report if there are no images. reg = /\.(png|jpg|jpeg|gif)/igm; if(reg.exec(pikan.text) === null) { reg = /\{\{image/igm; if(reg.exec(pikan.text) === null) { pikan.save_problem(0, 0, "Policy", "No image found; articles should have at least one image. Either add some or add the template .", "Pikipedia:General_content_guidelines#General"); } }  //Mention of the subject on the first paragraph in bold. //Let's assume a line is a paragraph of content if it starts //with ', ", a letter/number, or a link. reg = /^('|"|[a-z0-9]|\[).+$/igm; var done = false; while(!done){ first_paragraph_match = reg.exec(pikan.text); if(!first_paragraph_match) break; //If it's a template, skip this line. if(pikan.in_area(first_paragraph_match, "")) continue; //If it's an image, skip this line. if(first_paragraph_match[0].indexOf("[[File:") != -1) continue;   //First line of text found.    if(first_paragraph_match[0].indexOf("'") == -1){      pikan.save_problem(0, 0, "Question", "The first mention of the subject on the first paragraph should be in bold. It seems that this is not true. If it is, or this policy does not apply here, ignore this.", "Pikipedia:General_content_guidelines#General");      break;    }    done = true;  }  //"You" outside of guide sections.  reg = /\b(you|your|you're)\b/igm;  pikan.regex_check(    reg, "Question", "The player/reader is referred to as \"you\". This is only okay on guide sections, and it looks like this section isn't one, as it's missing the  template.", "Pikipedia:General_content_policy#Don.27t_use_.22you.22",    function(r){      if(pikan.in_area(r, "<ref", "/ref", false)) return false;      if(pikan.in_area(r, "", false)) return false;      if(pikan.in_area(r, "", false)) return false;      var guide_reg = /\{\{guide/igm;      var guide_tem_match = null;      var you_section_nr = pikan.get_section_nr(r);      while(guide_tem_match = guide_reg.exec(pikan.text)){        if(pikan.section_in_section(          you_section_nr,          pikan.get_section_nr(guide_tem_match)        )){          return false;        }      }      return true;    }  );  //Find "color".  reg = /colou?r/igm;  pikan.regex_check(reg, "Question", "\"Color\" found. If this refers to a Pikmin type, use \"type\" instead.", null,    function(r){      return !pikan.is_common_exception(r);    }  );  //Find transcripts not using .  reg = /("|"'')/igm;  pikan.regex_check(reg, "Question", "Italics and quote found. Is this a transcription? If so, you should likely use .");  //"Artwork" sections should be called "Gallery".  reg = /^=+ *(Artwork|Images) *=+$/igm;  pikan.regex_check(reg, "Question", "Gallery section found. For the sake of consistency, name this section \"Gallery\". However, if this particular gallery only has artwork, you may call it \"Artwork\".");  //Find "font-family", as it is likely a Wikia visual editor leftover.  reg = /font\-family/igm;  pikan.regex_check(reg, "Question", "Font family tampering found. Possibly a Wikia visual editor leftover. Remove it if so.");  //Find tags, which are possible Wikia leftovers.  reg = /<p/igm;  pikan.regex_check(reg, "Question", "&lt;p&gt; tag found. There is normally no reason to use them, meaning this could be a Wikia visual editor leftover. Remove it if so.");  //Find black text colors, which are possible Wikia leftovers.  reg = /[ ;"]color: ?(black|#000[000]?)/igm;  pikan.regex_check(reg, "Question", "Black text color style found. Because it is normally useless to force the text to be black, this is likely a Wikia visual editor leftover. Remove it if so.");  //Report if there is no .  reg = /\{\{game icons/igm;  if(reg.exec(pikan.text) === null) {    reg = /\{\{infobox/igm; //Infoboxes typically place icons automatically.    if(reg.exec(pikan.text) === null) {      pikan.save_problem(0, 0, "Question", " template not found. If this page doesn't have game icons on the top right, but should, add the template manually.", "Pikipedia:General_content_guidelines#General");    }  }  //Point out the use of the term "captain".  reg = /captain/igm;  pikan.regex_check(reg, "Question", "\"Captain\" found. Not all leaders are captains, so use the term \"leader\" whenever possible.", "Leader",    function(r){      if(pikan.after(r, 7) == " Olimar") return false;      if(pikan.after(r, 8) == " Charlie") return false;      if(pikan.is_common_exception(r)) return false;      return true;    }  );  //Find gendered nouns; enemies should be "it", and players should be "they".  reg = /\b(his|him|her|he|she)\b/igm;  pikan.regex_check(reg, "Question", "Gendered noun found. If this is an enemy, treat it as an \"it\", and if it's the player, treat them as \"they\". Otherwise, ignore this.", "Pikipedia:General_content_guidelines#General");  //Suggest  templates instead of tags.  reg = /"));    }  );  //Find "image:" (it should be "file:").  reg = /\[\[Image\:/igm;  pikan.regex_check(reg, "Style", "Image being called with \"Image:\" found. \"File:\" is better.");  reg = /Image:/igm;  pikan.regex_check(reg, "Style", "Image being called with \"Image:\" found. \"File:\" is better.", null,    function(r){      return pikan.in_area(r, "");    }  );  //Find redundant "Template:".  reg = /\{\{Template\:/igm;  pikan.regex_check(reg, "Style", "\"\" and \"\" are the same, so use the latter form, which is simpler.");  //Reference tags with a space before them.  reg = / (<ref|\{\{cite)/igm;  pikan.regex_check(reg, "Style", "References shouldn't have spaces before them.");  //Find trailing spaces.  reg = /(^ .+$|^.+ $)/igm;  pikan.regex_check(    reg, "Style", "Trailing space found.", null,    function(r){      if(r[0].match(/^\|.+= */)) return false; //Template parameter -- not eligible.      return true;    }  );  //Find double spaces.  reg = /  /igm;  pikan.regex_check(    reg, "Style", "Double spaces found. Just one is enough.", null,    function(r){      return !pikan.in_area(r, "|", "="); //Template parameter -- not eligible.    }  );  //Find two empty lines in a row.  reg = /(\n\n\n|\r\r\r|\r\n\r\n\r\n)/igm;  pikan.regex_check(reg, "Style", "Double empty lines found. Just one is enough. If you want to add vertical spacing, try the

template. (If you can't see the selection, just press a letter key.)"); //Empty line at the start.  if(pikan.text.length > 2){    if(pikan.text[0] == "\n" || pikan.text[0] == "\r"){      pikan.save_problem(0, 1, "Style", "Empty line at the start found. There's no reason for it to exist, so remove it.");   }  }  //Missing empty line before section.  reg = /([^\n=]\n|[^\r=]\r|[^(\r\n)=]\r\n)=.+=/gm;  pikan.regex_check(reg, "Style", "Add an empty line before section headers, to make it easier to read.");

//Files share their line with other text. reg = /((\[\[File.+\]\][^\n\r\[\]]+$)|(^[^\n\r\[\]]+\[\[File.+\]\]))/igm; pikan.regex_check(reg, "Style", "Image has more than just its code on its line; add a line break between it and the text, to make it easier to read.");

//Underscores in file names. reg = /\File:.+_.+/igm; pikan.regex_check(reg, "Style", "File name with underscores found; spaces are more human-readable."); //Underscores in gallery file names. reg = /.+_.+\|/gm; pikan.regex_check(   reg, "Style", "File name with underscores found; spaces are more human-readable.", "",    function(r){      return pikan.in_area(r, "<gallery", "/gallery");    }  ); //Underscores in links. reg = /\[\^|\*_[^|\]]*(\||\]\])/gm; pikan.regex_check(reg, "Style", "Link with underscores found; spaces are more human-readable."); //Underscores in template names. reg = /\{\{[^\|\}]+_.+(\r|\n|\|\}\})/gm; pikan.regex_check(reg, "Style", "Template name with underscores found; spaces are more human-readable."); //Links like A|A. reg = /\[\[([^\|\]]+)\|\1\]\]/gm; pikan.regex_check(reg, "Style", "Link with the same page and name found. Just simplify it like this: Apple &rarr; Apple."); //Links like A|AB. reg = /\[\[([^\|\]]+)\|\1[^ ]+\]\]/gm; pikan.regex_check(reg, "Style", "Link with a name that contains the page name found. Simplify it like this: Apples &rarr; Apples."); }

/* * * * * * * * * * * * * * * * * * * * * * * * * * Is common exception * * * * * * * * * * * * * * * * * * * * * * * * * * Returns whether a regex match belongs to a * "common exception". Use this to ignore capitalization, * spelling, etc. problems on things like template * parameter names. * reg: regex match. */ pikan.is_common_exception = function(reg){ //Is it in a template? if(pikan.in_area(reg, "")) return true; //Is it a page link or image? var in_internal_link = (pikan.in_area(reg, "", "")); if(in_internal_link){ var in_left_half = pikan.in_area(reg, "", ""); //A|B format. if(in_left_half) return true; } //Is it a categorization? if(pikan.in_area(reg, "")) return true; if(pikan.in_area(reg, "")) return true; //Is it a file name in a gallery? if(pikan.in_area(reg, "<gallery", "/gallery")){ if(pikan.in_area(reg, "\n", "|")) return true; } //Is it in an external link? if(!in_internal_link){ if(     (pikan.in_area(reg, "[http", "]") || pikan.in_area(reg, "[www", "]")) &&     pikan.in_area(reg, "[", " ")    ){ return true; } }  return false; }

}

if(typeof(pikan) != "undefined") { init_pikan; pikan.setup; }

//