importScript('User:Ohconfucius/script/Sources.js'); //[[User:Ohconfucius/script/Sources.js]]
importScript("User:GregU/dashes.js");
importScript('User:Dr_pda/prosesize.js'); //[[User:Dr_pda/prosesize.js]]
importScript('User:Ohconfucius/script/MOSNUM dates.js'); //[[User:Ohconfucius/script/MOSNUM dates.js]]
/*************
*** regex menu framework
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>
*** - adds a sidebar menu of user-defined scripts.
*************/
mw.loader.load('https://meta.wikimedia.org/?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
function Ohc_formats() {
var txt=document.editform.wpTextbox1;
//superscripted ordinals
regex(/\[\[[\w]*_\d{4}#\d{4}_[\w]*_\d\d?\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( \d\d?)\]\]/g, '$1$2');
regex(/(\d)(?:<(?:small|sup)>){2}(th|st|nd|rd)(?:<\/(?:small|sup)>){2}/gi, '$1$2');
regex(/(\d)<(?:small|sup)>(th|st|nd|rd)<\/(?:small|sup)>/gi, '$1$2');
//rem linking within section headings
regex(/(==[ ]{0,1})\[\[([^\|\]]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3');
regex(/(==[ ]{0,1})\[\[[^\|\]]+?\|([^\]]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3');
regex(/(==[ ]{0,1})\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)([ ]{0,1}==)/gi, '$1$2$3$4$5$6');
//rem empty parameters
// regex(/\|[\n]*[ ]*[a-zA-Z][a-z0-9_ ]*=[ ]*[\n]?[ ]*(?=[\|\}])/g, "");
//add correct hyphenation
regex(/\b(\d\d?|half|quarter|two|three|four|five|six|seven|eight|nine|ten) (minute|hour|day|week|month|year|degree|inch|foot|yard|mile|metre|metre|man|page|point|word|dollar|cent)\b/g, "$1-$2");
regex(/(\bnon) ([A-Z]?[a-z]+)/g, "$1-$2");
//improper capitalisation within section headings
regex(/(==[ ]*External )(Links)(?=[ ]*=)/g, '$1links');
regex(/(==[ ]*See )(Also)(?=[ ]*=)/g, '$1also');
regex(/(==[ ]*)Notable ([A-Z]\w*?)/g, '$1$2');
regex(/(==[ ]*[\w]+? and )A(wards?|chievements?)(?=[ ]*=)/g, '$1a$2');
regex(/(==[ ]*[\w\s]+? )C(areer|hampionships|haracters|ompositions)(?=[ ]*=)/g, '$1c$2');
regex(/(==[ ]*[\w\s]+? )E(ducation)(?=[ ]*=)/g, '$1e$2');
regex(/(==[ ]*[\w\s]+? )G(roup)(?=[ ]*=)/g, '$1g$2');
regex(/(==[ ]*[\w\s]+? )H(istory|onou?rs)(?=[ ]*=)/g, '$1h$2');
regex(/(==[ ]*[\w\s]+? )L(ife)(?=[ ]*=)/g, '$1l$2');
regex(/(==[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)(?=[ ]*=)/g, '$1q$2');
regex(/(==[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )R(ound)(?=[ ]*=)/g, '$1r$2');
regex(/(==[ ]*(?:CFL|N[BFH]L) )C(oaching )[Rr](ecords?)(?=[ ]*=)/g, '$1c$2r$3');
regex(/(==[ ]*[\w\s]+? )R(ankings?|esults?|ecords?|eception|ecognition)(?=[ ]*=)/g, '$1r$2');
regex(/(==[ ]*[\w\s]+? )S(eason|tyle|tage|tatistics)(?=[ ]*=)/g, '$1s$2');
regex(/(==[ ]*[\w\s]+? )T(ournaments?)(?=[ ]*=)/g, '$1t$2');
regex(/(==[ ]*[\w\s]+? )Y(ears)(?=[ ]*=)/g, '$1y$2');
regex(/(==[ ]*Exhibition )Schedule(?=[ ]*=)/g, '$1schedule');
regex(/(==[ ]*Regular )Season Schedule(?=[ ]*=)/g, '$1season schedule');
regex(/(==[ ]*Terminated )(Destinations)(?=[ ]*=)/g, '$1destinations');
regex(/(==[ ]*Twin )(Towns)(?=[ ]*=)/g, '$1towns');
regex(/(==[ ]*Twin )(Towns [Aa]nd [Ss]ister [Cc]ities)(?=[ ]*=)/g, '$1towns and sister cities');
regex(/(==[ ]*Heraldic )(Items)(?=[ ]*=)/g, '$1items');
regex(/(==[ ]*Campaign )(Credits)(?=[ ]*=)/g, '$1credits');
regex(/(==[ ]*Combat )(Chronicle)(?=[ ]*=)/g, '$1chronicle');
//other improper capitalisation
// regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, '$1c$2'); //transferring to MOSNUM script
// regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ -]*(?:Fox|[A-Z]\w*))/g, '$1c$2');
regex(/\b(st|nd|rd|th) G(rade)\b/g, '$1 g$2');
regex(/(Official )S(ite)/g, '$1s$2');
// regex(/([A-Z][a-z]+ )O(fficial )W(ebsite\])/g, '$1o$2w$3');
regex(/(\w )A(nd|t) A(n? \w)/g, '$1a$2 a$3');
regex(/(\w )A(nd|t) (My \w)/g, '$1a$2 $3');
regex(/(\w )A(nd|t) T(he \w)/g, '$1a$2 t$3');
regex(/(\w )By A(n? \w)/g, '$1by a$2');
regex(/(\w )By (My \w)/g, '$1by $2');
regex(/(\w )By T(he \w)/g, '$1by t$2');
regex(/(\w )For A(n? \w)/g, '$1for a$2');
regex(/(\w )For (My \w)/g, '$1for $2');
regex(/(\w )For T(he \w)/g, '$1for t$2');
regex(/(\w )In A(n? \w)/g, '$1in a$2');
regex(/(\w )In (My \w)/g, '$1in $2');
regex(/(\w )In T(he \w)/g, '$1in t$2');
regex(/(\w )O(f|n|r) A(n? \w)/g, '$1o$2 a$3');
regex(/(\w )O(f|n|r) (My \w)/g, '$1o$2 $3');
regex(/(\w )O(f|n|r) T(he \w)/g, '$1o$2 t$3');
regex(/(\w )To A(n? \w)/g, '$1to a$2');
regex(/(\w )To (My \w)/g, '$1to m$2');
regex(/(\w )To T(he \w)/g, '$1to t$2');
regex(/(\w )With A(n? \w)/g, '$1with a$2');
regex(/(\w )With M(y \w)/g, '$1with m$2');
regex(/(\w )With T(he \w)/g, '$1with t$2');
// regex(/(\s*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)(?=[ ]*)/g, '$1q$2');
// regex(/(\s*(?:First|Second|Third|Fourth|\d(?:st|nd|rd|th)) )R(ound)(?=[ ]*)/g, '$1r$2');
//remove flagicons from birth and death
regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flagicon\|([^\}]+)\}\}/gi, '$1');
regex(/((?:nationality|residence)\s*=\s*)\{\{flag(?:country|icon|)\|([^\}]+)\}\}/gi, '$1');
//remove scroll bar for reflists
regex(/(References ?={1,4}[\n\r])[\r\n\s]*(?:<div class="\w*" [^>]*)>([^<]*)<\/div>/g, '$1$2');
regex(/((?:Notes ?|References ?)={2,4}\s?[\n\r])[\r\n\s]*(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/g, '$1{{reflist|colwidth=30em}}');
//rem redundant spaces underlining and punctuation
regex(/′s/g, '\'s'); // replace prime symbol with straight apostrophe
regex(/[ ]{1,3}(<\s?ref(?:>| >| n))/gi, '$1');
regex(/([\w\d\,\.\]\)>] )[ ]+([\[\w\d\(])/gi, '$1 $2');
regex(/(U\.)[ ]+((?:S|K)\.)/gi, '$1$2'); //U. S. and U. K. to U.S. and U.K.
regex(/(<\/?ref(?: name=[^\>\/]*?|)\/?>)[ ,\.]*(<\s?ref)/gi, '$1$2');
regex(/[ ]+(\n|\r)/g, '$1'); //removes multiple spaces preceding line break
regex(/(\d), ([12]\d{3}\b)+/g, '$1, $2'); //removes nbsp preceding year
regex(/(\d)(?: | )%/g, '$1%'); //removes nbsp preceding '%'
regex(/( )[ ](–|–)/g, '$1$2'); //Palliative for dashes script insertion of space after nbsp
//rem bolding from linked AND bolded terms
// regex(/'''(\[\[)([^\|\]]+?\||)([^\]]+?\]\][:-–]?)'''/g, '$1$2$3');
//rem linked copyright symbol
regex(/(\[\[copyright\|©\]\] ?|©)/g, '');
//rem leading and lagging spaces within wikilinks
regex(/(\[\[)[ ]+([^\[\]]*?\]\])/g, '$1$2');
regex(/(\[\[[^\[\]\|]*?)[ ]+(\]\])/g, '$1$2');
regex(/(\[\[[^\[\]\|]*?[ ])[ ]+([^\[\]]*?\]\])/g, '$1$2');
regex(/(\[\[[^\[\]\|]*?)[ ]+(\|[^\[\]]*?\]\])/g, '$1$2');
regex(/(\[\[[^C\[\]\|]*?\|)[ ]+([^\[\]]+?\]\])/g, '$1$2');
//symbol for 'times' and dashes
// regex(/×/gi, '×');
// regex(/([ \.][\d]+)x([\d]+(?:\.[\d]+|)\s)/gi, '$1 × $2'); //disabling - never ending false positives
regex(/(\d) x (\d )/gi, '$1 × $2');
// regex(/–/gi, '–');
// regex(/([^<][^!] *)--( *[^>])/gi, '$1–$2'); //disabling - causes false positives with urls and some images
regex(/—/gi, '—');
regex(/([\w\d]) — (?=[\w\d])/gi, '$1 – '); // tweak to avoid replacing emdashes in strings that are in non-roman unicode characters
regex(/(\b7\d7)–(\d00\b)/gi, '$1-$2'); //airplane model numbers taking hyphen
//add missing space between wikilinks
regex(/(\]\])(\[\[)(?!file:)/gi, '$1 $2');
//remove redundant piping
regex(/(\[\[)([\w\s]*)\|\2([\w]*)(\]\])/gi, '$1$2$4$3');
//hash fixes
regex(/([^=] )#(\d{1,3},?\s)/g, '$1No. $2');
//full stop and nbsp fixes
//protection for strings within wikilinks
regex(/(\[(?:[^\|\]]*)\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})([ ]*(?:[cgkm])[^\|\]]*?[\|\]])/gi, '$1♭$2');
regex(/(\[(?:[^\|\]]*)(?:\d?\d[:\.]\d?\d| \d?\d))([ ]*(?:[ap]\.m\.|[ap]m)[^\|\]]*?[\|\]])/gi, '$1♭$2');
regex(/(Ph)(?:\.\s?|\s)(D)\.?/g, '$1$2');
regex(/((?:\d?\d[:\.]\d?\d| \d?\d) [ap])(?:\.m\.)([^\w\-])/gi, '$1m$2');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)[ ]*(?:a\.m\.|am)([^\w\-])/gi, '$1 am$2');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)[ ]*(?:p\.m\.|pm)([^\w\-])/gi, '$1 pm$2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kw)\b/gi, '$1 kW');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:khz)\b/gi, '$1 kHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m[Hh]z)\b/gi, '$1 MHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:g[Hh]z)\b/gi, '$1 GHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kph|kphr|kmh|kmhr|kmph|kmphr|km\/hr)\b/gi, '$1 km/h');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m\.p\.h\.)\b/gi, '$1 mph');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(gm|kg|km)s?\b/g, '$1 $2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/g, '$1 k$2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1 cm');
// regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1 $2illion$3');
//turn letter 'x' into symbol '×'
regex(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in (');
regex(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');
// Convert degree symbols into ° symbol, ensure preceding space
regex(/°/g, '°');
// regex(/º/g, '°');
// Celsius spelling errors
regex(/(?:celsius|celcius|centigrade)/gi, 'Celsius');
//Fix common naming error (be careful with this one)
// regex(/centigrade/gi, 'Celsius');
//Celsius or Fahrenheit
regex(/(\d) (?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
regex(/(\d)(?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
regex(/(\d) (?:°|deg|degree|degrees)([CF]\W)/g, '$1 °$2');
regex(/(\d)(?:\s|)(?:°|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1 °$2');
regex(/(\d) (\[\[Celsius|°C\]\])/gi, '$1 $2');
regex(/(\d)(?:\s|)(\[\[Celsius|°C\]\])/gi, '$1 $2');
regex(/(\d) (\[\[Fahrenheit|°F\]\])/gi, '$1 $2');
regex(/(\d)(?:\s|)(\[\[Fahrenheit|°F\]\])/gi, '$1 $2');
regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)°F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1{{convert|$2|°F|°C|abbr=on}}$3');
regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)(?:deg|degree|degrees)(?:\s|-| |)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1{{convert|$2|°F|°C}}$3');
// Convert &sup to superscript
// regex(/(m)(?:²|²);/g, '$1<sup>2</sup>');
// regex(/(m)(?:³|³);/g, '$1<sup>3</sup>');
//remove commas from numerical values in convert template
regex(/(\{convert\|\d+),(\d)/g, '$1$2');
regex(/(\{convert\|\d+),(\d)/g, '$1$2');
regex(/(\{convert\|\d+),(\d)/g, '$1$2');
regex(/(\{convert\|\d+),(\d)/g, '$1$2');
regex(/(\{convert\|\d+),(\d)/g, '$1$2');
//remove leading zeros from convert template
regex(/(\{convert\|)0(\d)/g, '$1$2');
regex(/(\{convert\|)0(\d)/g, '$1$2');
regex(/(\{convert\|)0(\d)/g, '$1$2');
//Remove surprise or 'Easter egg' diversions linking unit name to orders of magnitude articles
regex(/\[\[1\s?_?E\s?[\-\+]?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1');
regex(/\[\[Orders\sof\smagnitude\s\([^\)]+\)\|([^\]]{1,50})\]\]/gi, '$1');
regex(/(\d)♭(\w| )/g, '$1$2');
//remove useless comments
regex(/<!-- Metadata: see \[\[Wikipedia:Persondata\]\]\. -->/g, '');
//Deleted image cleanup
regex(/<!-- Deleted image removed:[^>]*? -->\n*/g, '');
//rem bolding from linked AND bolded terms
regex(/'''(\[\[)([A-Z]\w+?)(\|[\w\- ]+|)(\]\])'''/g, '$1$2$3$4');
// setoptions(minor='true'); //removed ",watch='false'" in response to user notification 13 Nov. 2010
// setreason('remove bold formatting', 'append');
}
function make_dates_bold(){
//**********************************************************************************************
// This script was originally written by Lightmouse to make dates bold - for timelines, etc.
// For use mainly with timelines, it makes dates after bullet points into bold type
var txt=document.editform.wpTextbox1;
//process date ranges containing a hyphen '* month dd - month dd:'
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');
//process date ranges containing a hyphen '* month dd dd:'
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?\d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');
//protect date ranges containing a hyphen
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1xx$2');
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?\d\d?)\s?:\s?/gi, '$1xx$2');
//process dates containing a hyphen
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–]\s?/gi, '* \'\'\'$1:\'\'\' ');
//unprotect date ranges containing a hyphen
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1–$2');
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?\d\d?)\s?:\s?/gi, '$1–$2');
//process other dates
regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?(?:,\s?\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' ');
regex(/\*\s?(\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December)(?:\s\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' ');
// edit_summary();
}
function ohc_change_type(){
//update syntax of 'File'
regex(/\[\[(file|[Ii]mage):/g, '[[File:');
//update file names that are supposed to include dashes instead of hyphens
regex(/(\[\[\d{4})-(\d{2} in [\w ]*football\|)/gi, '$1–$2');
regex(/(\[\[\d{4})-(\d{2} [A-Z]* season\|)/gi, '$1–$2');
}
/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
var linkmap=[];
function ohc_protect_fmt()
{
// protects categories, templates, link pipings, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var protect_function = function(s, begin, replace, end) {
linkmap.push(replace);
return begin + "⍌"+(linkmap.length-1)+"⍍" + end;
}
regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/((?:[a-z]{2,3}):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/(\{(?:See ?also|Main))(\|[^\}]*)(\})/gi, protect_function);
regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
// regex(/(.)(The (?:Times|Independent|Guardian|Wall Street Journal))(.)/gi, protect_function);
}
function ohc_unprotect_fmt()
{
//removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
regex(/[♫]/g, '');
regex(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmapn];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmapn];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmapn];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
return linkmapn];
});
return res;
});
return res;
});
return res;
});
}
/** ------------------------------------------------------------------------ **/
function Ohc_formatgeneral() {
ohc_change_type();
ohc_protect_fmt();
Ohc_formats();
ohc_unprotect_fmt();
}
function Ohc_run_formatgeneral() {
Ohc_formatgeneral();
setoptions(minor='true');
setreason('General [[WP:MOS|formatting]]', 'append');
}
addOnloadHook(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral()', 'General formatting', 't-addmetric', 'Fixes some unit formatting', '', '');
mw.util.addPortletLink('p-tb', 'javascript:make_dates_bold()', 'BOLD dates', 'ca-unitfixer', 'Fixes some unit formatting', '', '');
mw.util.addPortletLink('p-tb', 'javascript:unbold_word()', 'UNBOLD single words', 'ca-unitfixer', 'Removed bold formatting from single words', '', '');
}
});