Content deleted Content added
Pathoschild (talk | contribs) migrate to TemplateScript |
Pathoschild (talk | contribs) switch to now-updated MOSNUM utils script |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7:
$.when(
$.ajax("//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js", { dataType: "script", cache: true }),
$.ajax("//en.wikipedia.org/w/index.php?title=User:
).then(function() {
pathoschild.TemplateScript.add(
Line 53:
*/
function ohc_extend_editor(editor) {
editor.ohc_regex = function(rg, sub, func) {
var text = editor.get();
text = ohc.dateutil.regex(text, rg, sub, func);
Line 98 ⟶ 97:
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/([^-\d/:\.])@MM[-–]@DD[-–]@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/(\| ?)@MM\/@DD\/@YYNN(?=\s*\|)/gi,
.ohc_regex(/(\| ?)@MM\.@DD\.@YYNN(?=\s*\|)/gi,
//.ohc_regex(/(\| ?)@MM[-–]@DD[-–]@YYNN(?=\s*\|)/gi,
}
Line 115 ⟶ 114:
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/([^-\d/:\.])@DD[-–]@MM[-–]@YYNN(?=[^-–/\w&])/gi,
.ohc_regex(/(\| ?)@DD\/@MM\/@YYNN(?=\s*\|)/gi,
.ohc_regex(/(\| ?)@DD\.@MM\.@YYNN(?=\s*\|)/gi,
//.ohc_regex(/(\| ?)@DD[-–]@MM[-–]@YYNN(?=\s*\|)/gi,
}
Line 134 ⟶ 133:
editor
// add missing space between wikilinks
.replace(/(\]\])(\[\[)/gi,
// rem redundant quote marks and parentheses
Line 163 ⟶ 162:
// remove nowrap template from dm and md dates
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]| )@Month)( @yyyy|)\}\}/gi,
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi,
// delink single dm or 'dth the m'
Line 190 ⟶ 189:
// century
.replace(/\[\[((?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first[\s\-])centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?)\]\]/gi,
.replace(/\[\[(?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first)[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?\|([^\]]{1,30})\]\]/gi,
.replace(/\[\[(\d{1,2}(?:st|[nr]d|th))[\s\-_](centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi,
.ohc_regex(/\[\[\d{1,2}@th[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi,
// months
Line 200 ⟶ 199:
// decades and years
.replace(/(\d{1,3}0)[‘`´’′]?s/g,
.replace(/\[\[(\d{1,3}0)\'?s\]\]/g,
.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g,
.replace(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi,
.replace(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi,
.replace(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi,
.ohc_regex(/([-–])\[\[\s?@yyyy\s?\|\s?(\d{2,4})\s?\]\]/gi,
.replace(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi,
.replace(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi,
.replace(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi,
// month+year
Line 224 ⟶ 223:
// removed piped years when in full date (excepting disambiguated parentheses - updated 24/2/2012)
//.ohc_regex(/\[\[[^|\]\(\)]{1,32}\|@YYYY\]\]/gi,
// Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
.ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth")
.ohc_regex(/\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi,
// month and day piped
Line 236 ⟶ 235:
// years piped
.replace(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi,
}
function ohc_fix_common_errors(editor) {
editor
.ohc_regex(/(\d)<sup>@th<\/sup>/gi,
// remove dashbot comment from dates
.replace(/<!-- ?DASHBot ?-->/gi, '')
.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*c(?:irca|a\.)?\s?((?:@day |)@month @year)(?=[\s\n]*[<|}])/gi,
// common cs1 errors
.replace(/(\|\s*(?:date|year)\s*=)\s*(1[7-9]\d|20[0-1])\?(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date|year)\s*=\s*(1[7-9])\d{2})[-–](\d{2})(?=[\s\n]*[<|}])/gi,
//.replace(/(\|\s*(?:date|year)\s*=\s*(20)[0-1]\d)[-–]([0-2]\d)(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYNN(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date)\s*=)\s*s(pring|ummer),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date)\s*=)\s*a(utumn),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date)\s*=)\s*f(all),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date)\s*=)\s*w(inter),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date)\s*=)\s*(Spring|Summer|Autumn|Fall|Winter)[-–](S(?:pring|ummer)|Autumn|Fall|Winter) ?/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*(@month @year)(?=[\s\n]*[<|}])/gi,
//.ohc_regex(/(\|\s*date\s*=\s*)@year\?(?=[\s\n]*[<|}])/gi,
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*@year\?(?=[\s\n]*[<|}])/gi,
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*(@month @year)\?(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*@month @day, (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*@day @month.? (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*31( (?:April|June|September|November) @year)(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*29( February (?:200[1235679]|201[1345789]))(?=[\s\n]*[<|}])/gi,
.ohc_regex(/(\|\s*access-?date\s*=)\s*(?:3[01])( February @yyyy)(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*access-?date\s*=)\s*(\d{4})(?=[\s\n]*[<|}])/gi, '') // common cs1 error
Line 272 ⟶ 271:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@YYYY-@DD-@Mon/gi, "$1 @DD @FullMonth @YYYY")
.replace(/(\|\s*(?:date|year)\s*=)\s*(?:(?:date |)unknown|(?:not? |non-|un)date[ds])(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*(?:date|year)\s*=)\s*n\.?d(?=[\s\n]*[<|}])/gi,
.replace(/(\|\s*)year(\s*=\s*)(?=n\.?d\.)(?=[\s\n]*[<|}])/gi,
// remove parasitic metadata - days of the week/descriptives
Line 288 ⟶ 287:
// remove deprecated parameters (|day= and |month)
.ohc_regex(/(\|\s*)day(?:\s*=\s*)@DD ?\| ?month(?:\s*=\s*)@Month ?\| ?year(?:\s*=\s*)@YYYY(?=[|}\s])/gi,
.ohc_regex(/(\|\s*)year(?:\s*=\s*)@YYYY ?\| ?month(?:\s*=\s*)@Month ?\| ?day(?:\s*=\s*)@DD(?=[|}\s])/gi,
// typos
.ohc_regex(/(date *= *)@Day @Month ?@th/gi,
.ohc_regex(/(date *= *)@Day @Month\w(?= \d{3,4})/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )J[anu]{3,5}r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d) )Febua?r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )M\w{2,3}ch(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30) )A[bpv\[]\w{2,3}l\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Ma[tui](?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\wn\w(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\w{1,2}e(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Jul\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )A[oug]{2,3}\w{1,4}t(?:\w|us)?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30) )S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )O\w{0,2}t\w{1,3}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30) )[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)@Month\w(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)J[anu]{3,5}r\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)Febua?r\w{0,2}(?=(?: (?:[12]?\d),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)M\w{2,3}ch(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)A[bpv\[]\w{2,3}l\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)Ma[tui](?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)J\wn\w(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)J\w{1,2}e(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)Jul\w{1,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)A[oug]{2,3}\w{1,4}t(?:\w|us)?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)O\w{0,2}t\w{1,3}[er]{2,3}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
.ohc_regex(/(date *= *)D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi,
// insert comma to separate date from army unit
Line 350 ⟶ 349:
// remove extraneous bracket //from Batty
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:archive-?|access-?|publication-?)?date\s*=\s*)([\w\s-]+)\](?=\s*[\|}<])/gi,
// fix bda template redirect
//.replace(/\{\{bda\|([^}]+)\}\}/gi,
//.replace(/\{\{dda\|([^}]+)\}\}/gi,
// zap redundant {{date}}, {{accessdate}} {{retrieved}}, {{monthname}} and {{#dateformat}}
Line 360 ⟶ 359:
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:[^\}]*)}}/gi, "@Day @Month @YYYY")
.replace(/{{#formatdate:([^}]+)}}/gi, "$1")
.replace(/\{\{#dateformat:([^}\|]+)(?:\|dmy|\|mdy)?\}\}/gi,
//.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:Start|End) ?date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\|@DD(?:\|df=y(?:es|)|)\}\}/gi,
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:\|(?:[dmy]{3}|iso)|)}}/gi, "@Day @Month @YYYY")
.ohc_regex(/\|\s*(?:archive|access|air)-?date\s*=\s*\{\{date\}\}(?=\s*[|}])/gi, "") //remove {{date}} template without parameters that inappropriately return crrent date
Line 367 ⟶ 366:
.ohc_regex(/\{\{date\|@YYYY\/@MM\/@DD\}\}/gi, "@YYYY-@MM-@DD") //remove {{date}} template while rectifying slash dates within the template
.ohc_regex(/\{\{date\|(@DD[\-\s]@Mon|@Mon[\-\s]@DD)\}\}/gi, "@Day @Month")
.replace(/\{\{date\|([^}\|]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi,
.ohc_regex(/[ ]*\{\{accessdate\|@YYYY-@MM-@DD[ ]*\}\}/gi, " Retrieved @YYYY-@MM-@DD")
.ohc_regex(/[ ]*\{\{retrieved[ ]*\|[ ]accessdate=([\-\w, ]*)\}\}/gi, " Retrieved $1")
//.ohc_regex(/(date[ ]*=[ ]*|\w{2,}[ ]*)\{\{(?:start|end).date[^|}]*(?:\|df=y(?:es|)|)\|@YYYY(?:\|df=y(?:es|)|)\}\}/gi,
//.ohc_regex(/\{\{(?:Start|End) date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\}\}/gi,
//.ohc_regex(/<!--(?:Use)? \{\{(?:Start|End) date\|@YYYY\|@MM\|@DD\}\} -->/gi, '') // stripping start/end template notes
.ohc_regex(/(\{\{MONTHNAME\|@MM\}\})/gi, "@Month")
// expand one and two-digit years in ranges
.replace(/(\()@Month @YYYY[-–]@Month @YYNN(\))/gi,
.replace(/(\(1[789])(\d)(1)[-–]([2-9]\))/gi,
.replace(/(\(1[789])(\d)(2)[-–]([3-9]\))/gi,
.replace(/(\(1[789])(\d)(3)[-–]([4-9]\))/gi,
.replace(/(\(1[789])(\d)(4)[-–]([5-9]\))/gi,
.replace(/(\(1[789])(\d)(5)[-–]([6-9]\))/gi,
.replace(/(\(1[789])(\d)(6)[-–]([7-9]\))/gi,
.replace(/(\(1[789])(\d)(7)[-–]([8-9]\))/gi,
.replace(/(\(1[789])(\d)(8)[-–](9\))/gi,
.replace(/(\(20)([01])(1)[-–]([2-9]\))/gi,
.replace(/(\(20)([01])(2)[-–]([3-9]\))/gi,
.replace(/(\(20)([01])(3)[-–]([4-9]\))/gi,
.replace(/(\(20)([01])(4)[-–]([5-9]\))/gi,
.replace(/(\(20)([01])(5)[-–]([6-9]\))/gi,
.replace(/(\(20)([01])(6)[-–]([7-9]\))/gi,
.replace(/(\(20)([01])(7)[-–]([8-9]\))/gi,
.replace(/(\(20)([01])(8)[-–](9\))/gi,
.ohc_regex(/(\W)@DD@th?, @DD@th?((?:[ ]| )(?:and|&|to|or)(?:[ ]| ))@DD@th?(?:\sof\s?)?([ ]| )@Month(?=\W)/gi,
.ohc_regex(/(\W)@DD@th?((?:[ ]| )(?:and|&|to|or)(?:[ ]| ))@DD@th?(?:\sof\s?|)([ ]| )@Month(?=\W)/gi,
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month,? @YYYY(?=\W\D)/g,
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month(?=\W\D)/g,
.ohc_regex(/(\W)@Day@th?(?:\sof|)([ _]| |{{(?:break|nbsp)}})@Month(?=[^|\]\w])/gi,
.ohc_regex(/(\W)@Month\s(?:the\s)?@DD@th?,(?:\sthe\s)?(?: | )@DD@th?(\s(?:and|&|to|or)(?:[ _]| ))(?:the\s)?@DD@th?(?=[^|\]\w])/gi,
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?:,?(?:[ _]| )|\sof\s)?(\d{3,4}\W\D)/gi,
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?=\W\D)/gi,
.ohc_regex(/(\W)@Month([ _]| |{{(?:break|nbsp)}})(?:the\s)?@DD@th?,? @Year/gi,
.ohc_regex(/(\W)@Month @Day(?:\sof|,|)([ _]| |{{(?:break|nbsp)}})@Year(?=[^|\]\w])/gi,
// consolidating/amalgamating date fields
Line 412 ⟶ 411:
// eliminating dates and time placed in author parameter
// removing artefacts from Indian news sites (TNN Aug 30, 2012, 05.46AM)
.ohc_regex(/(\|\s*author\s*=\s*(?:[A-Z]{2,3}\b))(?:[^|}]*)\d{4}, [\d\.:]{4,5}( |)[AP]M IST(?=[ ]*\|)/g,
//.ohc_regex(/(\|\s*author=(?:[^\[\]|{}]*))(TNN|PTI) @day @month @yyyy, [\d\.:]{4,5}( |)[AP]M IST(?=[ ]*\|)/g,
.ohc_regex(/(\|\s*author\s*=\s*)@month @day,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*| )(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1")
Line 452 ⟶ 451:
.ohc_regex(/([ =|])@DD\.@MM\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @MM @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=\s*[|}\n])/gi,
//convert yyyy-dd-mm to yyyy-mm-dd
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:publication|archive|access|air|)-?date\s*=\s*(?:1[0-9]|20)\d{2})[-/\.=\s](1[3-9]|2\d|3[01])[-/\.=\s](0?\d|1[0-2])(\s*[\|}<])/gi,
// eliminating other errant formats
Line 462 ⟶ 461:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month ?@Day,? ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Month @Day, 20$2")
.ohc_regex(/([ ]\()@DD-@MM-@YYYY(\)\W)/gi,
.ohc_regex(/([ ]\()@DD-@Month-@YYYY(\)\W)/gi,
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@Month, @DD, @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@DD[\.,] @Month,? @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
Line 491 ⟶ 490:
.ohc_regex(/(\W)@FullMonth\s@DD(\s+|\s*,)/gi, "$1@FullMonth @Day$2")
.ohc_regex(/(\W)@Mon\s@DD(\s+|\s*,)/gi, "$1@Mon @Day$2")
.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g,
//.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ \-][A-Z]\w*|''|")/g,
//spaces and commas - in date formats
Line 548 ⟶ 547:
editor
// multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
}
Line 557 ⟶ 556:
editor
// multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi,
}
Line 567 ⟶ 566:
editor
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g,
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi,
.ohc_regex(/(\{\{dts\|format=)mdy\|/gi,
}
Line 577 ⟶ 576:
editor
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g,
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi,
.ohc_regex(/(\{\{dts\|)format=(?:mdy|dmy|) ?\|/gi,
}
Line 586 ⟶ 585:
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(@year)\}\}/gi, "$1") // disabled 3/5/21 discussion at https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Baseball&oldid=1021203365#Links_to_baseball_year_articles_in_infobox?
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|@year\|(@year)\}\}/gi, "$1")
.ohc_regex(/\[\[@yyyy\sin\s[^|\]]+\|((?:(?:@day |)@month |)@yyyy)\]\]/gi,
.replace(/\[\[(?:\d{4}[-–]\d{2} in English football)\|((?:(?:@Day |)@Month |)@YYYY)\]\]/gi,
.replace(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi,
}
Line 598 ⟶ 597:
// dts - format=dmy in this case (per D12000)
// per {{dts}} doc, remove the obsolete link=off param
.replace(/(\{\{dts[^}]*)(?:\|link=off)/gi,
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\|\s*format=)(?:dmy|mdy)(\}\})/gi,
.ohc_regex(/(\{\{dts\s*\|\s*format=)(?:dmy|mdy)(\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\}\})/gi,
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*)(\}\})/gi,
// stripping – {{dts}} serves no purpose inside date parameters
Line 615 ⟶ 614:
// GR - date formatting parameter
// per {GR} doc, insert date formatting param
.replace(/(\{\{GR\|\d\d?)(?!\|date)/gi,
}
Line 621 ⟶ 620:
editor
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|format=mdy/gi,
// change start and end templates; vgrelease new v=2 or mdy is default
.replace(/(\{\{(?:start date|end date)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi,
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=1\||)([A-Z]{2,3}\|)/g,
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY") // spotted at [[Template:Infobox recurring event]]
// change birth and death templates
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start)[^}]*\|)m(f=ye?s?)/gi,
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+)(\}\})/gi,
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+\|)df=ye?s?\|([^}]*df=ye?s?)/gi,
.replace(/(\{\{(?:start date|end date)\|)df=ye?s?\|((?:1[789]|20)\d{2}\}\})/gi,
// convert date ranges (md,d,d-dy to d,d,d-dmy; md,d,d-d to d,d,d-dm; md,d,d to d,d,dm)
Line 655 ⟶ 654:
//dates with embedded nbsp
.ohc_regex(/(\D\W)@Month([ _]| )(\d{1,2},(?: | )\d{1,2}(?:\s(?:and|&|to|or)(?:[ _]| ))\d{1,2})(?=[^|\]\w])/gi,
.ohc_regex(/(\D\W)@Month([ _]| |{{(?:break|nbsp)}})@Day,([ _]| |{{(?:break|nbsp)}})@YYYY(?=[^|\]\w])/gi,
//remove comma
Line 673 ⟶ 672:
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|df=y(?:es|)(?=[|}\s])/gi, '')
.replace(/(mf=y(?:es|)\|[^}]*\|)(?:mf=y(?:es|)\|)/gi,
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=2\||)([A-Z]{2,3}\|)/g,
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY")
Line 744 ⟶ 743:
function ohc_expand_all_dates(editor) {
editor
.ohc_regex(/([^-\w/])@Month @YYYY(?=[^-\w/])/gi,
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi,
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi,
.ohc_regex(/([^-\w/])((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=[^-\w/])/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
Line 771 ⟶ 770:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@Mon @Day, @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber) ([12]?\d|30|31),( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3,$4")
.ohc_regex(/([^-\w\/])@Month @Day, @YYYY([^-\w\/])/gi,
}
Line 777 ⟶ 776:
function ohc_abbrev_all_dates(editor) {
editor
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi,
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi,
}
Line 803 ⟶ 802:
editor
// Add a tag to the summary box
.replace(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\|[^\}\|]+\}\})/gi,
}
Line 816 ⟶ 815:
var curryear = currentDate.getFullYear();
var myMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var curryyyymm = myMonths[currmonth] +
// step 1: normalize redirect template names to canonical template names 'Use dmy dates' or 'Use mdy dates' according to 'format' argument
editor
// rename redirects 'dmy', 'mdy', 'usedmydates', 'usemdydates' ('usedmydates' and 'usemdydates' are not currently listed as redirects but might be encountered?)
.replace(/\{\{ *(?:use(?:dmy|mdy)dates|dmy|mdy) *([\|\}])/gi,
// rename redirects 'usedmy', 'usemdy', 'use dmy', 'use mdy' to canonical form
.replace(/\{\{ *use *(?:dmy|mdy) *([\|\}])/gi,
// strip leading / trailing whitespace from 'use xxx dates'
.replace(/\{\{ *use (?:dmy|mdy) dates *([\|\}])/gi,
// step 2: look for a canonical template name (the above might not have had anthing to work on) ; if found continue, write new template else
Line 833 ⟶ 832:
var dflagfound = editor.get().search(rxpdd);
if (dflagfound === -1) {
editor.prepend(
return; // and done
}
Line 839 ⟶ 838:
// step 3: rewrite existing canonical templates; add or refresh |date= to current month year; preserve |cs1-dates= as is
editor
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|]*\| *cs1\-dates *= *([^\|\}]*?) *\}\}/gi,
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) *\| *date *=[^\}]*\}\}/gi,
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|\}]*\}\}/gi,
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) \}\}/gi,
.replace(/(\{\{use (?:dmy|mdy) dates)\}\}/gi,
.replace(/(\{\{[\t_ ]*use[\t_ ]+(?:dmy|mdy)[\t_ ]+dates[^{}]*\}\})([\r\n\t ]*)(\{\{[\t ]*short description[^{}]*\}\})/gi,
}
Line 899 ⟶ 898:
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi,
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi,
.replace(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi,
.replace(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi,
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
Line 1,010 ⟶ 1,009:
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi,
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi,
.ohc_regex(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi,
.ohc_regex(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi,
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
Line 1,141 ⟶ 1,140:
editor
.options({ minor: true })
.appendEditSummary(
.clickDiff();
}
Line 1,149 ⟶ 1,148:
editor
.options({ minor: true })
.appendEditSummary(
.clickDiff();
}
Line 1,157 ⟶ 1,156:
editor
.options({ minor: true })
.appendEditSummary(
.clickDiff();
}
Line 1,165 ⟶ 1,164:
editor
.options({ minor: true })
.appendEditSummary(
.clickDiff();
}
Line 1,173 ⟶ 1,172:
editor
.options({ minor: true })
.appendEditSummary(
.clickDiff();
}
Line 1,188 ⟶ 1,187:
/** ------------------------------------------------------------------------ **/
function ohc_body_dates_to_dmy(editor) {
ohc_use_dates_template(editor,
ohc_fix_common_errors(editor);
ohc_fix_dts_template(editor,
ohc_fix_gr_template(editor,
ohc_dates_to_dmy(editor);
ohc_remove_leading_zeroes(editor);
Line 1,199 ⟶ 1,198:
function ohc_body_dates_to_mdy(editor) {
ohc_use_dates_template(editor,
ohc_fix_common_errors(editor);
ohc_fix_dts_template(editor,
ohc_fix_gr_template(editor,
ohc_dates_to_mdy(editor);
ohc_remove_leading_zeroes(editor);
|