MediaWiki:Gadget-pikan-inkipedia.js

//

function init_pikan {

pikan.wiki_url = "https://splatoonwiki.org/"; pikan.help_link = "https://splatoonwiki.org/wiki/User:Espyo/Pikan"; pikan.module_name = "Inkipedia"; pikan.module_version = "1.3.4";

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, 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\"."); //Check "Joy-Con" reg = /joy(\s)?con/igm; pikan.regex_check(reg, "Problem", "\"Joycon\" found. The correct spelling for the Switch controller is \"Joy-Con\"."); //Find "Nunchuck" reg = /Nunchuck/igm; pikan.regex_check(reg, "Problem", "\"Nunchuck\" found. The correct spelling of the Wii peripheral is \"Nunchuk\"."); //Find game names without italicization. reg = /(Splatoon( \d)?|Octo Expansion)/igm; pikan.regex_check(   reg, "Policy", "Game and series names should be in italics. If this is the Twitter account, use an @ sign", null,    function(r){      if(pikan.is_common_exception(r)) return false;      if( pikan.before(r, 2) == "''" && pikan.after(r, 2) == "''" ){       return false;      }      if (pikan.before(r, 1) == "@") return false; // ignore Twitter handles      if (pikan.before(r, 2) == "r/") return false; // ignore Reddit board      //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;      //Special cases: if it's part of "Squidbeak Splatoon", "Splatoon Global Testfire",      //"Splatoon Testfire", then ignore.      if(pikan.before(r, 10) == "Squidbeak ") return false;      if(pikan.after(r, 16) == " Global Testfire") return false;      if(pikan.after(r, 9) == " Testfire") return false;      return true;    }  ); //Find lowercase game name. reg = /(splatoon( \d)?|octo expansion)/gm; pikan.regex_check(   reg, "Policy", "Game name with lowercase 's' found. The official spelling is always with an uppercase 'S'.", null,    function(r){      if (pikan.is_common_exception(r)) return false;      if (pikan.before(r, 1) == "@") return false; // ignore Twitter      if (pikan.before(r, 2) == "r/") return false; // ignore Reddit board      return true;    }  ); //Find lowercase "Inkling", "Octoling", "Octarian", etc. reg = /(inkling|octoling|octarian|octotrooper)/gm; pikan.regex_check(   reg, "Policy", "Species name starting with a lowercase letter found. It should start with an uppercase letter.", null,    function(r){      return !pikan.is_common_exception(r);    }  ); //Find button names that aren't using the button template. reg = /\b((press(ing)?\s*(the)?\s*)([ABLRXYZ]{1,2})|([ABLRXYZ]{1,2})(\s*buttons?))\b/igm; pikan.regex_check(   reg, "Policy", "Button being referred to by name. It should be displayed using  instead.", null,    function(r){      return !pikan.is_common_exception(r);    }  ); //Suggest ❌ and instead of manually-written tags. reg = /\((NA|US|EU\W?(OC|AU)|Europe|North America)\)/igm; pikan.regex_check(   reg, "Question", "Region in parenthesis found. If possible, use ❌,  or  instead."  ); //"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 this doesn't look like one. If it is, ignore this, otherwise use the third person.", "Inkipedia:Policy#Perspective",    function(r){      if(pikan.is_common_exception(r)) return false;      if(pikan.in_area(r, "<ref", "/ref", false)) return false;      var walkthrough_sec_reg = /^=+ *Walkthrough/igm;      var walkthrough_sec_match = null;      var you_section_nr = pikan.get_section_nr(r);      while(walkthrough_sec_match = walkthrough_sec_reg.exec(pikan.text)){        if(pikan.section_in_section(          you_section_nr,          pikan.get_section_nr(walkthrough_sec_match)        )){          return false;        }      }      return true;    }  ); //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. Probably not desired."); //Find tags, which are possible Wikia leftovers. reg = /]/igm; pikan.regex_check(reg, "Question", "&lt;p&gt; tag found. There is normally no reason to use them. Use for a break."); //Find raw colors. reg = /((?:[^&])#\s*(?:[\da-fA-F]{3,4}|[\da-fA-F]{6}|[\da-fA-F]{8}).*?[\";])|((?:rgba?|hsla?)\(\d+)|((?:\s|-|;|^)(?:color|background)\s*:(?!\s*(?:{{|var|rgba?\({{))+[^-]+?[\";])/gm; pikan.regex_check(reg, "Policy", "Raw color style found. Consider using a CSS variable or the Site Color template instead to support light/dark mode and skins."); //Find gendered nouns; players should be "they". reg = /\b((s?he)|(hi[m|s])|hers?)\b/igm; pikan.regex_check(   reg, "Question", "Gendered noun found. If this is the player, treat them as \"they\". Otherwise, ignore this.", "Inkipedia:Policy#Pronouns",    function(r){      return !pikan.is_common_exception(r);    }  ); //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 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.)"); //Find redundant "Template:". reg = /\{\{Template\:/igm; pikan.regex_check(reg, "Style", "\"{{Template:abc}}\" and \"{{abc}}\" are the same, so use the latter form, which is simpler."); //Find trailing spaces. reg = /(^.+ $)/igm; pikan.regex_check(reg, "Style", "Trailing space found."); //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 illegible.    }  ); //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.");

//Image files share their line with other text. // Slate: This version ignores lines that start with nowiki/pre/code or a | like in a table, //       and lines that end with those closing tags. reg = /((^(?!\s*( | | |\|)).+?\{2})|(\{2}(?!\s*(<\/nowiki>|<\/pre>|<\/code>)).+?$))/igm; pikan.regex_check(reg, "Style", "The file has more than just its code on one line; add a line break between it and 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 = /\{{2}[^\|\}]+_.+($|\|\})/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 in a comment? 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_right_half = pikan.in_area(reg, "|", "]]", "[["); if(in_right_half) return false; return true; // Else left half or raw link } //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; }

//