User:Ohconfucius/test/MOSNUM dates.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Ohconfucius/test/MOSNUM dates. |
// This script aligns dates into one of two formats allowed by [[WP:MOSNUM]].
// PLEASE READ THE DOCUMENTATION at [[User:Ohconfucius/script/MOSNUM dates]] (click on the link above) before using.
// Feedback and constructive criticism are welcome
/* global $, mw, pathoschild */
/**
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:pathoschild/templatescript.js]]
*/
// <pre>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
// load date utils
if( $.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
$.ajax('//en.wikipedia.org/w/index.php?title=User:Ohconfucius/test/MOSNUM_utils.js&action=raw&ctype=text/javascript', { dataType:'script', cache:true }).then(function() {
var apply = ohc.dates.apply_driver;
pathoschild.TemplateScript.add([
{ name:'ALL dates to dmy', tooltip: 'Align all dates to dmy', script: apply(ohc.dates.all_to_dmy_driver) },
{ name:'ALL dates to mdy', tooltip: 'Align all dates to mdy', script: apply(ohc.dates.all_to_mdy_driver) },
{ name:'Body dates to dmy', tooltip: 'day month', script: apply(ohc.dates.body_to_dmy_driver) },
{ name:'Body dates to mdy', tooltip: 'month day', script: apply(ohc.dates.body_to_mdy_driver) },
{ name:'Body+pub dates to dmy', tooltip: 'Body and publication dates to dmy', script: apply(ohc.dates.dmy_publication_dates_driver) },
{ name:'Body+pub dates to dmy', tooltip: 'Body and publication dates to dmy', script: apply(ohc.dates.mdy_publication_dates_driver) },
{ name:'ISO to dmy', tooltip: 'ISO day month', script: apply(ohc.dates.iso_to_dmy_driver, false/*don't show diff*/) },
{ name:'ISO to mdy', tooltip: 'ISO month day', script: apply(ohc.dates.iso_to_mdy_driver, false/*don't show diff*/) },
{ name:'access 2 ISO', tooltip: 'access dates to ISO', script: apply(ohc.dates.iso_access_dates_driver, false/*don't show diff*/) },
{ name:'Del year-in-X dates', tooltip: 'Year in X', script: apply(ohc.dates.delink_year_in_x_driver, false/*don't show diff*/) },
{ name:'Expand ref dates', tooltip: 'Expand month names within refs', script: apply(ohc.dates.expand_ref_dates_driver) },
{ name:'Expand all dates', tooltip: 'Expand month names throughout', script: apply(ohc.dates.expand_all_dates_driver) },
{ name:'Abbrev ref dates', tooltip: 'Abbreviate month names within refs', script: apply(ohc.dates.abbrev_ref_dates_driver) },
//{ name:'unambiguous dates', tooltip: 'resolves slash date format', script: apply(ohc.dates.unambiguous_dates_driver) },
{ name:'US-slash dates', tooltip: 'US-slash', script: apply(ohc.dates.us_slash_dates_driver) },
{ name:'UK-slash dates', tooltip: 'UK-slash', script: apply(ohc.dates.uk_slash_dates_driver) },
], { category: 'date fixes' });
});
}
});
var ohc = ohc || {};
ohc.dates = {
fix_unambiguous_dates: function(text) {
// resolvable ambiguous date formats
return text
// UK style
.ohc_regex(/([^-\w/:\.])@DD\.@MM\.@YYYY(?=[^-–/\w])/gi, "$1@Day @Month @YYYY", function(d) {
return d.d == d.m || d.d > 12;
})
.ohc_regex(/([^-\w/:\.])@DD\/@MM\/@YYYY(?=[^-–/\w])/gi, "$1@Day @Month @YYYY", function(d) {
return d.d == d.m || d.d > 12;
})
// US style
.ohc_regex(/([^-\w/:\.])@MM\.@DD\.@YYYY(?=[^-–/\w])/gi, "$1@Month @Day, @YYYY", function(d) {
return d.d > 12;
})
.ohc_regex(/([^-\w/:\.])@MM\/@DD\/@YYYY(?=[^-–/\w])/gi, "$1@Month @Day, @YYYY", function(d) {
return d.d > 12;
});
},
us_slash_dates_to_mdy: function(text) {
return text
//ranges
.ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\/@DD\/@YYNN(?=[^-–/\w])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
.ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\.@DD\.@YYNN(?=[^-–/\w])/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
.ohc_regex(/(\| ?)@MM\/@DD\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon2 @Day2, @Year2")
.ohc_regex(/(\| ?)@MM\.@DD\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, "$1@Mon1 @Day1, @Year1$2 – @Mon @Day2, @Year2")
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN(?=[^-–/\w])/gi, '$1@Month @Day, @YYYY')
.ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN(?=[^-–/\w])/gi, '$1@Month @Day, @YYYY')
.ohc_regex(/([^-\d/:\.])@MM[-–]@DD[-–]@YYNN(?=[^-–/\w])/gi, '$1@Month @Day, @YYYY')
.ohc_regex(/(\| ?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY')
.ohc_regex(/(\| ?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY');
//.ohc_regex(/(\| ?)@MM[-–]@DD[-–]@YYNN(?=\s*\|)/gi, '$1@Month @Day, @YYYY');
},
uk_slash_dates_to_dmy: function(text) {
return text
//ranges
.ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\/@MM\/@YYNN(?=[^-–/\w])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
.ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\.@MM\.@YYNN(?=[^-–/\w])/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
.ohc_regex(/(\| ?)@DD\/@MM\/@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
.ohc_regex(/(\| ?)@DD\.@MM\.@YYNN( |\s)?(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2")
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN(?=[^-–/\w])/gi, '$1@Day @Month @YYYY')
.ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN(?=[^-–/\w])/gi, '$1@Day @Month @YYYY')
.ohc_regex(/([^-\d/:\.])@DD[-–]@MM[-–]@YYNN(?=[^-–/\w])/gi, '$1@Day @Month @YYYY')
.ohc_regex(/(\| ?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY')
.ohc_regex(/(\| ?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY');
//.ohc_regex(/(\| ?)@DD[-–]@MM[-–]@YYNN(?=\s*\|)/gi, '$1@Day @Month @YYYY');
},
remove_leading_zeroes: function(text) {
return text
.ohc_regex(/(\D[^\w\/])@Month\s@ZD@th?,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @LYear")
.ohc_regex(/(\D[^\w\/])@Month\s@ZD@th?(?=\W\D)/gi, "$1@LMonth @Day")
.ohc_regex(/(\D[^\w\/])@ZD@th?\s@Month\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @LYear")
.ohc_regex(/(\D[^\w\/])@ZD@th?\s@Month(?=\W\D)/gi, "$1@Day @LMonth");
},
delink_dates: function(text) {
return text
//add missing space between wikilinks
.replace(/(\]\])(\[\[)(?!file:)/gi, '$1 $2')
// rem redundant quote marks and parentheses
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\'\'\'([^|}\[\]]*)\'\'\'(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\'\'([^|}\[\]]*)\'\'(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\"([^|}\[\]]*)\"(?=\s*[|}])/gi, "$1$2")
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\(([^|}\[\]]*)\)(?=\s*[|}])/gi, "$1$2")
//rem linking date parameters
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\[\[([^|\]]+?)\]\](?=\s*[|}])/gi, '$1$2')
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\[\[[^|\]]+?\|([^\]]+?)\]\](?=\s*[|}])/gi, '$1$2')
.replace(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\]([^|\[]*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\](?:([^|\[]*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\]|)(?=\s*[|}])/gi, '$1$2$3$4$5$6')
//delink piped md|dm, md|dd and my|m dates
.ohc_regex(/\[\[@month @dd(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1")
.ohc_regex(/\[\[@dd @month(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1")
.ohc_regex(/\[\[@month @yyyy(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1")
// remove nowrap template from dm and md dates
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]| )@Month)( @yyyy|)\}\}/gi, '$1@DD @Month$2')
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi, '$1@Month @DD$2')
//delink yyyy-mm-dd dates
.ohc_regex(/\[\[@YYYY(?:\]\]-\[\[|-)@MM-@DD\]\]/gi, "@YYYY-@MM-@DD")
.ohc_regex(/@YYYY-\[\[@MM-@DD\]\]/gi, "@YYYY-@MM-@DD")
//delink dates from automated templates
.replace(/\[\[(\{\{CURRENTDAY\}\} \{\{CURRENTMONTHNAME\}\})\]\]/gi, "$1")
.replace(/\[\[(\{\{CURRENTYEAR\}\})\]\]/gi, "$1")
//delink full dates
.ohc_regex(/\[\[@Day[\s_](?:of[\s_])?@Month(?:\]\]\s?\[\[\| )@YYYY\]\]/gi, "@Day @LMonth @YYYY")
.ohc_regex(/\[\[@Month (?:the\s)?@Day(?:\]\],? \[\[|, )@YYYY\]\]/gi, "@LMonth @Day, @YYYY")
//delink single dm or 'dth the m'
.ohc_regex(/(?:the\s)?\[\[@Day[\s_](?:of[\s_])?@Month\]\]/gi, "@Day @LMonth")
//delink single md or 'm the dth'
.ohc_regex(/\[\[@Month[\s_](?:the[\s_])?@Day\]\](?=\W)/gi, "@LMonth @Day")
//Month+day_number "[[March 7]]th" -> "March 7"
.ohc_regex(/\[\[@Month\s@DD\]\]@th/gi, "@LMonth @Day")
//month+day+year pseudo-ISO dates
.ohc_regex(/(\|\s*(?:date|archivedate|accessdate)\s*=\s*@dd)-@Mon-@YYYY/gi, "$1 @FullMonth @YYYY")
.ohc_regex(/(\|\s*(?:date|archivedate|accessdate)\s*=\s*)@YYYY-@DD-@Mon/gi, "$1 @DD @FullMonth @YYYY")
.ohc_regex(/\[\[@Month @DD\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @Month @YYYY")
.ohc_regex(/\[\[@DD\s@Month\|\d\d-\d\d\]\]-(?:\[\[)?(?:@yyyy[^|]*\|)?@YYYY(?:\]\])/gi, "@Day @Month @YYYY")
//month+day piped
.ohc_regex(/(?:the\s)?\[\[@day[\s_](?:of[\s_])?@month\|([^\]]{1,30})\]\]/gi, "$1")
//'[[month day|xxXxx]]Xyyyy ' to 'month day, year'
.ohc_regex(/\[\[@Month\s@Day\|@dd.@dd\]\].@YYYY/gi, "@LMonth @Day, @YYYY")
//'[[day month|xxXxx]]Xyyyy' to 'day month year'
.ohc_regex(/\[\[@Day\s@Month\|@dd.@dd\]\].@YYYY/gi, "@Day @LMonth @YYYY")
// 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, '$1')
.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, '$1')
.replace(/\[\[(\d{1,2}(?:st|[nr]d|th)[\s\-_])(centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi, '$1$2$3')
.replace(/\[\[\d{1,2}(?:st|[nr]d|th)[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi, '$1')
// months
.ohc_regex(/\[\[@Month\]\]/gi, "@Month")
.ohc_regex(/\[\[@FullMonth\|([^\]]{1,30})\]\]/gi, "$1")
// decades and years
.replace(/(\d{1,3}0)[‘`´’′]?s/g, '$1s')
.replace(/\[\[(\d{1,3}0)\'?s\]\]/g, '$1s')
.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, '$1')
.replace(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3')
.replace(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi, '$1$2')
.replace(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi, '$1$2$3')
.ohc_regex(/([-–])\[\[\s?@yyyy\s?\|\s?(\d{2,4})\s?\]\]/gi, '$1$2') //piped year
.replace(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi, '$1')
.replace(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, '$1')
.replace(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi, '$1')
//month+year
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
.ohc_regex(/\[\[@yyyy in[^|\]]+\|@Day @Month @YYYY\]\]/gi, "@Day @Month @YYYY")
.ohc_regex(/\[\[@yyyy in[^|\]]+\|@Month @Day,? @YYYY\]\]/gi, "@Month @Day, @YYYY")
.ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month\s|)(@yyyy)\]\]/gi, "$1$2")
.ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month|@yyyy)\]\]/gi, "$1")
.ohc_regex(/\[\[(@month\s@yyyy)\]\]/gi, "$1")
.ohc_regex(/\[\[@month\s@yyyy\|([^\]]{1,30})\]\]/gi, "$1")
.ohc_regex(/(\[\[@yyyy[^|\]]+\|@yyyy)(\]\])( season)/gi, "$1$3$2")
.ohc_regex(/@Month\s\[\[@yyyy[^|\]]+\|@YYYY\]\]/gi, "@LMonth @Year")
//removed piped years when in full date
.ohc_regex(/\[\[@DD\s@Month\]\],?\s?\[\[[^|\]]{1,32}\|@Year\]\]/gi, '@DD @LMonth @Year')
.ohc_regex(/\[\[@Month\s@DD\]\],?\s?\[\[[^|\]]{1,32}\|@Year\]\]/gi, '@LMonth @DD, @Year')
//Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
.ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth")
.ohc_regex(/@DD\s@Month,?\s?\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '@DD @LMonth @Year')
.ohc_regex(/@Month\s@DD,?\s?\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '@LMonth @DD, @Year')
// month and day piped
.ohc_regex(/@YYYY-\[\[@month[\s_]@day\|@MM-@DD\]\]/gi, "@YYYY-@MM-@DD")
.ohc_regex(/\[\[@month[\s_]@day\|([^\]]{1,30})\]\]/gi, "$1")
.ohc_regex(/\[\[@day(?:\s|_|@th )(?:of[\s_]|)?@month\|([^\]]{1,30})\]\]/gi, "$1")
//years piped
.replace(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, '$1');
},
fix_common_errors: function(text) {
return text
.ohc_regex(/(\d)<sup>@th<\/sup>/gi, '$1@th')
// remove dashbot comment from dates
.replace(/<!-- ?DASHBot ?-->/gi, '')
.replace(/(\|\s*(?:date|year)\s*=\s*)ca?\.(\w)(?=[|}\s])/gi, '$1c. $2') //add space
// disabling as pointless per discussion .replace(/(\|\s*)(?:date|year)(\s*=\s*(?:c\. |)@year)(?=[|}\s])/gi, '$1year$2') //general fix
.replace(/(\|\s*(?:date|year)\s*=\s*)(1[7-9]\d|20[0-1])\?(?=[|}\s])/gi, '$1c. $20') //common cs1 error
.replace(/(\|\s*(?:date|year)\s*=\s*)((?:@month |)@year)\?(?=[|}\s])/gi, '$1c. $2') //common cs1 error
.replace(/(\|\s*(?:date|year)\s*=\s*)(?:not? |non-|un)date[ds]?\s*(?=[|}\s])/gi, '$1n.d.') //common cs1 error
.replace(/(\|\s*(?:date|year)\s*=\s*)n\.?d\s*(?=[|}\s])/gi, '$1n.d.') //common cs1 error
.replace(/(\|\s*)year(\s*=\s*)(?=n\.?d\.[|}\s])/gi, '$1date$2') //common cs1 error
// remove parasitic metadata - days of the week/descriptives
.replace(/(\|\s*author\s*=\s*)(?:posted|published)(?: by\b| on\b|)[\s:](?=\w)/gi, "$1")
.replace(/(\|\s*(?:date|archivedate|accessdate|author|year)\s*=\s*)(?:accessed|retrieved|entered|posted|published|(?:last |)updated?|©)(?: by\b| on\b|)[\s:]*(?=\w)/gi, "$1")
.replace(/(\|\s*(?:date|archivedate|accessdate|author|year)\s*=\s*)(?:by\b|on\b)[\s:]*(?=\w)/gi, "$1")
.replace(/(\|\s*(?:date|archivedate|accessdate|author)\s*=\s*)(?:(?:Mo?n|Tue?s|W\w{2,5}s|Th\w{,3}s|Fri|Sat\w{3,5}|Sun)day,?)\s/gi, "$1")
.replace(/(\|\s*(?:date|archivedate|accessdate|author)\s*=\s*)(?:(?:Mon|Tues?|Wed|Thur?|Fri|Sat)[\.,]?)\s/gi, "$1") //<!-- rem "Sun" - false positives -->
// typos
.ohc_regex(/(date *= *)@Day @Month ?@th/gi, '$1@Day @Month')
.ohc_regex(/(date *= *)@Day @Month\w(?= \d{3,4})/gi, '$1@Day @Month')
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Jan|Febr)[\w ]?[aur]{3,4}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2uary')
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )J[anu]{3,5}r\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1January')
.ohc_regex(/(date *= *(?:[12]?\d) )Febua?r\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1February')
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )M\w{2}ch(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1March')
.ohc_regex(/(date *= *(?:[12]?\d|30) )A[bpv\[]\w{2,3}l\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1April')
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Ma[tui](?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1May')
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\wn\w(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1June')
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\w{1,2}e(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1June')
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Jul\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1July')
.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, '$1August')
.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, '$1$2ember')
.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, '$1September')
.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, '$1October')
.ohc_regex(/(date *= *(?:[12]?\d|30) )[MN]o[bv] ?\w{1,3}b[er]{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '$1November')
.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, '$1December')
.ohc_regex(/(date *= *)@Month\w(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1@Month') //rem stray digit at the end of year string
.ohc_regex(/(date *= *)(Jan|Febr)[\w ]?[aur]{3,4}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1$2uary')
.ohc_regex(/(date *= *)J[anu]{3,5}r\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1January')
.ohc_regex(/(date *= *)Febua?r\w{1,2}(?=(?: (?:[12]?\d),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1February')
.ohc_regex(/(date *= *)M\w{2}ch(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1March')
.ohc_regex(/(date *= *)A[bpv\[]\w{2,3}l\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1April')
.ohc_regex(/(date *= *)Ma[tui](?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1May')
.ohc_regex(/(date *= *)J\wn\w(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1June')
.ohc_regex(/(date *= *)J\w{1,2}e(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1June')
.ohc_regex(/(date *= *)Jul\w{1,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1July')
.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, '$1August')
.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, '$1$2ember')
.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, '$1September')
.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, '$1October')
.ohc_regex(/(date *= *)[MN]o[bv] ?\\w{1,3}b[er]{1,2}(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '$1November')
.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, '$1December')
//insert comma to separate date from army unit
.ohc_regex(/@FullMonth ((?:the |)\d\d*@th (?:Air(?:borne|)|Arm(?:ou?red|y)|Artillery|Battalion|Brigade|Co(?:mpan|)y|Division|Fleet|Group|Infantry|Land|Panzer|Regiment|Squadron|Sqn)\b)/g, "@Month, $1")
// remove nowrap template from dm and md dates
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|nowrap)\|(?:@DD(?:[ _]| )@Month)\}\}/gi, '$1@DD @Month')
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|nowrap)\|(?:@Month(?:[ _]| )@DD)\}\}/gi, '$1@Month @DD')
// remove parasitic metadata - time
.ohc_regex(/(\|\s*\w*date\s*=\s*@yyyy-@mm-@dd)\s?(?:T[0-2]\d:[0-5]\d:\d\d(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|Z))(?=\s*[|}])/g, "$1")
.ohc_regex(/(\|\s*\w*date\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")
.ohc_regex(/(\|\s*\w*date\s*=\s*@day @month,? @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")
.ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\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")
.ohc_regex(/(\|\s*\w*date\s*=\s*\w[\w\s]+@day @month,? @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")
// remove redundant parentheses from dm and md dates (equivalent also exists in Sources script, line 71)
.ohc_regex(/(=[ ]*)\((?:@DD(?:[ _]| )@Month,? @Year)\)/gi, '$1@DD @Month @Year')
.ohc_regex(/(=[ ]*)\((?:@Month(?:[ _]| )@DD,? @Year)\)/gi, '$1@Month @DD, @Year')
// add back spaces or comma or remove other single artefact after date string
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)(?:on |)@Day\s{,2}@Month\s{,2}@YYYY(\s)?[^a-z|}]?(?=\s*[|}\n])/gi, "$1@Day @Month @YYYY$2")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)(?:on |)@Month\s{,2}@Day,?\s{,2}@YYYY(\s)?[^a-z|}]?(?=\s*[|}\n])/gi, "$1@Month @Day, @YYYY$2")
//long-hand palliative for observed failure to insert spaces
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)(?:on |)([0-2]?\d|30|31)\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s*((?:19\d|20[0-1])\d\s?)[^|{}\s<>]*(?=\s*[|}])/gi, "$1$2 $3 $4")
//remove extraneous bracket //from Batty
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:archive|access|publication-?)?date\s*=\s*)([\w\s-]+)\](?=\s*[|}<])/gi, '{{$1$2$3$4')
//fix bda template redirect
.replace(/\{\{bda\|([^}]+)\}\}/gi, '{{birth date and age|$1}}')
.replace(/\{\{dda\|([^}]+)\}\}/gi, '{{death date and age|$1}}')
//zap redundant {{date}}, {{accessdate}} {{retrieved}} and {{#dateformat}}
.replace(/{{#formatdate:([^}]+)}}/gi, "$1")
.replace(/\{\{#dateformat:([^\}\|]+)(?:\|dmy|\|mdy)?\}\}/gi, '$1')
.replace(/\{\{date\|([^\}\|]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi, '$1')
// .ohc_regex(/(date[ ]*=[ ]*)\{\{(?:Start|End) ?date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\|@DD(?:\|df=y(?:es|)|)\}\}/gi, '$1@Month @DD, @YYYY') //stripping start/end template notes inside "|date=" parameter (line 72)
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:\|(?:[dmy]{3}|iso)|)}}/gi, "@Day @Month @YYYY")
.ohc_regex(/\{\{date\|@YYYY-@MM-@DD\}\}/gi, "@Day @Month @YYYY")
.ohc_regex(/\{\{date\|(@DD[\-\s]@Mon|@Mon[\-\s]@DD)\}\}/gi, "@Day @Month")
.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, '$1@YYYY') //stripping start/end template
.ohc_regex(/<!--(?:Use)? \{\{(?:Start|End) date\|@YYYY\|@MM\|@DD\}\} -->/gi, '') //stripping start/end template notes
//underscore and nbsp in linked dates
.ohc_regex(/\[\[@DD(?:_| )@Month\]\]/gi, "@Day @LMonth")
.ohc_regex(/\[\[@Month(?:_| )@DD\]\]/gi, "@LMonth @Day")
//remove leading zero and links from linked date
.ohc_regex(/\[\[@Month(?:[ _]| )@ZD@th\]\]/gi, "@LMonth @Day")
.ohc_regex(/\[\[@ZD@th(?:[ _]| )@Month\]\]/gi, "@Day @LMonth")
//expand one and two-digit years in ranges
.replace(/(\()@Month @YYYY[-–]@Month @YYNN(\))/gi, '$1@Month1 @YYYY1 – @Month2 @YYYY2$2')
.replace(/(\(1[789])(\d)(1)[-–]([2-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(2)[-–]([3-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(3)[-–]([4-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(4)[-–]([5-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(5)[-–]([6-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(6)[-–]([7-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(7)[-–]([8-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(1[789])(\d)(8)[-–](9\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(1)[-–]([2-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(2)[-–]([3-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(3)[-–]([4-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(4)[-–]([5-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(5)[-–]([6-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(6)[-–]([7-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(7)[-–]([8-9]\))/gi, '$1$2$3–$2$4')
.replace(/(\(20)([01])(8)[-–](9\))/gi, '$1$2$3–$2$4')
//remove unlinked ordinal date formats
.ohc_regex(/(\Wthe |)@DD@th?(?:\sof|)\s@Month,? @YYYY (concert|deadline|edition|show|performance)/gi, '$1$2 of @Day @LMonth @YYYY')
.ohc_regex(/(\Wthe |)@Month @DD@th?,?\s@YYYY (concert|deadline|edition|show|performance)/gi, '$1$2 of @LMonth @Day, @YYYY')
.ohc_regex(/(\Wthe |)@DD@th?(?:\sof|)\s@Month (concert|deadline|edition|show|performance)/gi, '$1$2 of @Day @LMonth')
.ohc_regex(/(\Wthe |)@Month @DD@th? (concert|deadline|edition|show|performance)/gi, '$1$2 of @LMonth @Day')
.ohc_regex(/(\W)@DD@th?, @DD@th?(\s(?:and|&|to|or)\s)@DD@th?(?:\sof\s?)?(?:[ ]| )@Month(?=\W)/gi, '$1@Day1, @Day2$2@Day3 @LMonth')
.ohc_regex(/(\W)@DD@th?(\s(?:and|&|to|or)\s|[-–])@DD@th?(?:\sof\s?)?(?:[ ]| )@Month(?=\W)/gi, '$1@Day1$2@Day2 @LMonth')
.ohc_regex(/(\W)(?:the |)@DD@th?(?:\sof|)\s@Month,? @YYYY(?=\W\D)/g, '$1@Day @LMonth @YYYY')
.ohc_regex(/(\W)(?:the |)@DD@th?(?:\sof|)\s@Month(?=\W\D)/g, '$1@Day @LMonth')
.ohc_regex(/(\W)@Day(?:\sof|)(?:[ _]| |{{(?:break|nbsp)}})@Month(?=[^|\]\w])/gi, '$1@Day @LMonth')
.ohc_regex(/(\W)@Month\s(?:the\s)?@DD@th?,(?:\sthe\s)?(?: | )@DD@th?(\s(?:and|&|to|or)(?:[ _]| ))(?:the\s)?@DD@th?(?=[^|\]\w])/gi, '$1@LMonth @Day1, @Day2$2@Day3')
.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, '$1$2 $3$4$5@Day, $6')
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?=\W\D)/gi, '$1$2 $3$4$5@Day')
.ohc_regex(/(\W)@Month(?:[ _]| |{{(?:break|nbsp)}})(?:the\s)?@DD@th?(?=[^|\]\w]\D)/gi, '$1@LMonth @Day')
.ohc_regex(/(\W)@Month @Day(?:\sof|,|)(?:[ _]| |{{(?:break|nbsp)}})@Year(?=[^|\]\w])/gi, '$1@Month @Day, @Year')
// consolidating/amalgamating date fields
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day)\s*\|[ ]*month=[ ]*(@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2 $3")
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@day.?@month)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2")
.ohc_regex(/(\|[ ]*date[ ]*=[ ]*@month.?@day)\s*\|[ ]*year=[ ]*(@yyyy[ ]*)(?=[|}\s])/gi, "$1 $2")
// 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, '$1$2')
//.ohc_regex(/(\|\s*author=(?:[^\[\]|{}]*))(TNN|PTI) @day @month @yyyy, [\d\.:]{4,5}( |)[AP]M IST(?=[ ]*\|)/g, '$1$2')
.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")
.ohc_regex(/(\|\s*author\s*=\s*)@day @month,? @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")
.ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@month @day,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*\w[\w\s]+)@day @month,? @yyyy(?:[^\[\]|{}]*)(?=[|}])/g, "$1")
.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@dd-@mm-@yyyy/gi, "$1")
.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)@YYYY-@MM-@DD ?/gi, "$1")
.replace(/(\|\s*(?:date|archivedate|accessdate|author)\s*=\s*(?:\w[\w\s]+)?)[0-2]\d:[0-5]\d(?:[ ]| )?(?:[ap]m|[ap]\.m\.|)(?: ?(?:[A-Z]{1,2}T|UTC)[\.,]?|)/gi, "$1")
//.ohc_regex(/(\|\s*author\s*=\s*(?:\w[\w\s]+)?)\s*[0-2]\d[\.:][0-5]\d(?:[\.:][0-5]\d|)/gi, "$1") //let's see later if we need this
// eliminating mm-dd-yyyy dates
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Mon[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY/gi, "$1@Month $2, @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)( on|:?)[ ]@MM[-–\/\.=\s](1[3-9]|2\d|3[01])[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Month $2, @YYYY")
//.ohc_regex(/[ ](?:Accessed|Retrieved)(?: on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY")
.ohc_regex(/([ =|])@Mon[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@Mon (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM[-–](1[3-9]|2\d|3[01])[-–]@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM\/(1[3-9]|2\d|3[01])\/@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM\.(1[3-9]|2\d|3[01])\.@YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
.ohc_regex(/([ =|])@MM (1[3-9]|2\d|3[01]) @YYYY(?=[^-–\d/])/gi, "$1@Mon $2, @YYYY")
// eliminating dd-mm-yyyy dates (assumed default)
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@DD[-–\/\.=\s]@Mon[-–\/\.=\s]@YYYY/gi, "$1@Day @Month @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)( on|:?)[ ]@DD[-–\/\.=\s]@MM[-–\/\.=\s]@YYYY(?=\D)/gi, " Retrieved @Day @Month @YYYY")
.ohc_regex(/[ ](?:Accessed|Retrieved)(?: on|:?)[ ]@YYYY,? @Month @DD(?=\D)/gi, " Retrieved @Day @Month @YYYY")
.ohc_regex(/([ =|])@DD[-–]@Mon[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\/@Mon\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\.@Mon\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @Mon @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD[-–]@MM[-–]@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD\/@MM\/@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.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|)date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=\s*[|}\n])/gi, '$1@Day @Month @YYYY')
//convert yyyy-dd-mm to yyyy-mm-dd
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:access|archive|)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, '{{$1$2$3-$5-$4$6') //from Batty
// eliminating other errant formats
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)([0-2]?\d|30|31) @Month \2,? @YYYY(?=\s*[|}])/gi, "$1$2 @Month @YYYY") //repeated digits
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Day ?@Month ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Day @Month 20$2")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month ?@Day,? ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Month @Day, 20$2")
.ohc_regex(/([ ]\()@DD-@MM-@YYYY(\)\W)/gi, '$1@Day @Month @YYYY$2')
.ohc_regex(/([ ]\()@DD-@Month-@YYYY(\)\W)/gi, '$1@Day @Month @YYYY$2')
.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")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month @DD(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @DD @Month(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/[ ]\(@YYYY,? @Month @DD\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/[ ]\(@YYYY @MM @DD\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/[ ]\(@YYYY, @DD @Month\)/gi, " (@Day @Month @YYYY)")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY,? @Month(?=\s*[|}])/gi, "$1@Month @YYYY")
.ohc_regex(/[ ]\(@YYYY, @Month\)/gi, " (@Month @YYYY)")
.ohc_regex(/[ ]\(@Mon@YYYY\)/gi, " (@Mon @YYYY)")
//CS1 errors ISO-like dates (too few or too many digits)
.ohc_regex(/(date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][–—‐]\[\[|[–—‐])@MM[\-–—‐]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD") //ndashes and emdashes
.ohc_regex(/(\|\s*accessdate\s*=\s*)@YYYY-0[–—]@DD(?=\s*[|}])/gi, "") //rem nonsense access date
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[-–—]@MM[-–—]@DD(?=\s*[|}])/gi, "$1@YYYY-@ZM-@ZD") //ndashes and emdashes
//.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@YYYY[\-–—‐]@MM(?=\s*[|}])/gi, "$1@Month @YYYY") //transform "yyyy-mm" to "month year"
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[–—]@MM[–—]@DD([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3")
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-]@MM[-]([1-9])([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2$3 @Month @YYYY$4")
// spaces and commas between month and year
.ohc_regex(/@Month(?:,\s+|\s+of\s+|,? )@YYYY(\D)/gi, "@LMonth @YYYY$1")
// fix month names (capitalize, remove dots)
.ohc_regex(/(\W)@DD\s@FullMonth(\s+|\s*,)/gi, "$1@Day @FullMonth$2")
.ohc_regex(/(\W)@DD\s@Mon(\s+|\s*,)/gi, "$1@Day @Mon$2")
.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, '$1c$2')
//.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ \-][A-Z]\w*|''|")/g, '$1c$2')
//spaces and commas - in date formats
.ohc_regex(/(\D\W\[?\[?@dd)[ ]+(@month)(\]\])?[ ]*,[ ]*(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1 $2$3 $4")
.ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)(?:[ ]*,[ ]*)(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5")
.ohc_regex(/(\D\W\[?\[?)(@month)[ ]+(@dd)(\]?\]?)[ ]+(\[?\[?@yyyy(\sAD|\sBC|\sCE|\sBCE|)\]?\]?\W\D)/gi, "$1$2 $3$4, $5")
.ohc_regex(/(@month)(?:, | of )(@yyyy\w)/gi, "$1 $2") //repeat after delinking
// spaces and commas - md-md and dm-dm date ranges
.ohc_regex(/(\D\W)@Month\s@DD( |\s)(?:[-–—]|&[mn]dash;)(?: |\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1$2– @LMonth2 @Day2")
.ohc_regex(/(\D\W)@Month\s@DD(?:[-–—]|&[mn]dash;)(?: |\s)?@Month\s@DD(?=\W\D)/gi, "$1@LMonth1 @Day1 – @LMonth2 @Day2")
.ohc_regex(/(\D\W)@DD\s@Month( |\s)(?:[-–—]|&[mn]dash;)(?: |\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1$2– @Day2 @LMonth2")
.ohc_regex(/(\D\W)@DD\s@Month(?:[-–—]|&[mn]dash;)(?: |\s)?@DD\s@Month(?=\W\D)/gi, "$1@Day1 @LMonth1 – @Day2 @LMonth2")
// spaces and commas - d-dm and md-d date ranges
.ohc_regex(/(\D\W)@Month\s@DD(?:(?:\s*| )[-–]\s*)@DD(?=\W\D)/gi, "$1@LMonth1 @Day1–@Day2")
.ohc_regex(/(\D\W)@DD(?:(?:\s*| )[-–]\s*)@DD\s@Month(?=\W\D)/gi, "$1@Day1–@Day2 @LMonth1")
//reformat dmy-dmy and mdy-mdy (birth-death ranges)
.ohc_regex(/(\D\W)@DD\s@Month,? @Year( |\s)(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\s@Month,? @Year(?=\D\W)/gi, "$1@Day1 @LMonth1 @Year1$2– @Day2 @LMonth2 @Year2")
.ohc_regex(/(\D\W)@Month\s@DD,? @Year( |\s)(?:(?:[-–—]|&[mn]dash;)(?: |\s)?)@Month\s@DD,? @Year(?=\D\W)/gi, "$1@LMonth1 @Day1, @Year1$2– @LMonth2 @Day2, @Year2")
.ohc_regex(/(\D\W)@DD\s@Month,? @Year(?:,?(?:[-–—]|&[mn]dash;)(?: |\s)?)@DD\s@Month,? @Year(?=\D\W)/gi, "$1@Day1 @LMonth1 @Year1 – @Day2 @LMonth2 @Year2")
.ohc_regex(/(\D\W)@Month\s@DD,? @Year(?:,?(?:[-–—]|&[mn]dash;)(?: |\s)?)@Month\s@DD,? @Year(?=\D\W)/gi, "$1@LMonth1 @Day1, @Year1 – @LMonth2 @Day2, @Year2")
//nbsp in publication archive & access dates
.ohc_regex(/(\|\s*(?:date|archivedate|accessdate)\s*=\s*@dd) (@month)/gi, '$1 $2')
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month @DD(, @yyyy|)(?=[ ]*[|}])/gi, '$1@Month $2')
// spaces and commas between month and year (again)
.ohc_regex(/@Month(?:,\s+|\s+of\s+)@YYYY(\w)/gi, "@LMonth @YYYY$1");
},
/** ------------------------------------------------------------------------- */
/// ISO to long format
iso_to_dmy_in_citations: function(text) {
return text
//ISO dates within single citation
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY");
},
iso_to_mdy_in_citations: function(text) {
return text
//ISO dates within single citation
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY");
},
iso_to_dmy_in_references: function(text) {
return text
//multiple calls for multiple dates within single citation
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3")
//.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3")
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
},
iso_to_mdy_in_references: function(text) {
return text
//multiple calls for multiple dates within single citation
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3")
//.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD([^-\w/%,<][^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3")
.ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3");
},
// currently unused
iso_to_dmy_anywhere: function(text) {
return text
//multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2')
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2')
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Day @Month @YYYY$2');
},
// currently unused
iso_to_mdy_anywhere: function(text) {
return text
//multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2')
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2')
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '$1@Month @Day, @YYYY$2');
},
delink_iso_to_dmy: function(text) {
text = ohc.dates.iso_to_dmy_in_citations(text);
text = ohc.dates.iso_to_dmy_in_references(text);
return text
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Day @Month @Year$2')
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '$1{{dts|format=dmy|@YYYY|@MM|@DD}}$2') //dts template for sortable tables
.ohc_regex(/(\{\{dts\|format=)mdy\|/gi, '$1dmy|'); //flip dts template formats
},
delink_iso_to_mdy: function(text) {
text = ohc.dates.iso_to_mdy_in_citations(text);
text = ohc.dates.iso_to_mdy_in_references(text);
return text
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Month @Day, @Year$2')
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '$1{{dts|@YYYY|@MM|@DD}}$2') //dts template for sortable tables (mdy is default)
.ohc_regex(/(\{\{dts\|)format=(?:mdy|dmy|) ?\|/gi, '$1'); //flip dts template formats
},
delink_year_in_x: function(text) {
return text
.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(@year)\}\}/gi, "$1")
.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, '$1')
.replace(/\[\[(?:\d{4}[-–]\d{2} in English football)\|((?:(?:@Day |)@Month |)@YYYY)\]\]/gi, '$1')
.replace(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi, '$1$2');
},
// format parameter must be 'dmy' or 'mdy'
fix_dts_template: function(text, format) {
return text
// dts - format=dmy in this case (per D12000)
// per {{dts}} doc, remove the obsolete link=off param
.replace(/(\{\{dts[^}]*)(?:\|link=off)/gi, '$1')
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\|\s*format=)(?:dmy|mdy)(\}\})/gi, '$1'+format+'$2')
.ohc_regex(/(\{\{dts\s*\|\s*format=)(?:dmy|mdy)(\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\}\})/gi, '$1'+format+'$2')
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*)(\}\})/gi, '$1|format='+format+'$2')
// stripping – {{dts}} serves no purpose inside date parameters
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*([|}]*)\}\}(?=\s*[|}])/gi, "$1$2")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*([|}]*)(?:\|\s*format=(?:dmy|mdy)\s*|)\}\}(?=\s*[|}])/gi, "$1$2")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*format=(?:dmy|mdy)\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)\{\{dts\s*\|\s*@YYYY(\s*\|\s*|-)@MM(\s*\|\s*|-)@DD\s*\|\s*format=(?:dmy|mdy)\s*\}\}(?=\s*[|}])/gi, "$1@YYYY-@MM-@DD ");
},
// format parameter must be 'dmy' or 'mdy'
fix_gr_template: function(text, format) {
return text
// GR - date formatting parameter
// per Template:GR/doc, insert date formatting param
.replace(/(\{\{GR\|\d\d?)(?!\|date)/gi, '$1|dateform=' + format);
},
dates_to_dmy: function(text) {
return text
.replace(/([dm]f) ?(=) ?(?=[ny])/gi, '$1$2')
.replace(/\|format=mdy/gi, '|format=dmy')
//change start and end templates; vgrelease new v=2 or mdy is default
.replace(/(\{\{(?:start.date|end.date)[^|}]*\|)df=y(?:es|)\|([^}]*df ?= ?y(?:es|))/gi, '$1$2')
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=1\||)([A-Z]{2,3}\|)/g, '$1v=2|$2')
//change deprecated birth and death templates
.replace(/(\{\{(?:Birth|Death date|launch|release|start|end)[^}]*)\|mf=y(?:es|)/gi, '$1') //rem pipe symbol to treat cases where mf is at the end
.replace(/(\{\{(?:Birth|Death date|launch|release|start|end|film date|Wayback)[^|}]*\|)/gi, '$1df=yes|') //lookahead for df or mf parameter
.replace(/(\{\{(?:Birth|Death date|launch|release|start|end|film date|Wayback)[^|}]*\|)df=y(?:es|)\|([^}]*df=y(?:es|))/gi, '$1$2')
.replace(/(\{\{(?:start.date|end.date)\|)df=y(?:es|)\|((?:1[789]|20)\d{2}\}\})/gi, '$1$2')
//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)
.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)@Day,?\s(?:of\s)?(@yyyy\W\D)/gi, "$1$2$3@Day @LMonth $4")
.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)@Day(?=\W\D)/gi, "$1$2$3@Day @LMonth")
//.ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}) @Day(?=\W\D)/gi, "$1$2 @Day @LMonth"); //disabling as unlikely and ungrammatical constructions causing false positives
//'md, md,' to 'dm, dm,'
.ohc_regex(/(\D\W)@Month @Day, @Month @Day(?=[,\.]\W\D)/gi, "$1@Day1 @LMonth1, @Day2 @LMonth2")
//convert simple mdy dates to dmy
.ohc_regex(/(\D\W)@Month\s@Day,?\s@Year(\s?(?:AD|BC|CE|BCE)\W\D)/gi, "$1@Day @LMonth @Year$2")
.ohc_regex(/(\D\W)@Month\s@Day,?\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year")
.ohc_regex(/(\D\W)@Month\s@Day(?=\W\D)/gi, "$1@Day @LMonth")
//Month+day_number " 7th March" -> "7 March"
.ohc_regex(/(\D\W)@Day\s@Month\s@YYYY(?=\W\D)/gi, "$1@Day @LMonth @Year")
.ohc_regex(/(\D\W)@Day\s@Month(?=\W\D)/gi, "$1@Day @LMonth")
//remove comma
.ohc_regex(/(\D\W)@Day\s@Month,\s?@Year(?=\W\D)/gi, "$1@Day @LMonth @Year")
//remove "the" from "on the dd month"
.ohc_regex(/(on |by )the @Day\s@Month(?=[ ,\)\.])/gi, "$1@Day @LMonth")
//remove space from date range conversion
.ohc_regex(/(\D ) @Day(\/|\s?(?:[-–]|–)\s?|(?:[ _]| )(?:and|&|to|or)(?:[ _]| )+?)/gi, "$1@Day$2");
},
dates_to_mdy: function(text) {
return text
//change birth and death templates – mf=y is the default; vgrelease new v=2 or mdy is default
.replace(/\|df=y(?:es|)/gi, '')
.replace(/(mf=y(?:es|)\|[^\}]*\|)(?:mf=y(?:es|)\|)/gi, '$1')
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=2\||)([A-Z]{2,3}\|)/g, '$1$2')
//convert date ranges (d,d,d-dmy to md,d,d-dy; d,d,d-dm to md,d,d-d; dm,d,d to md,d,d)
.ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|–)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2, @YYYY")
.ohc_regex(/(\D\W)@Day((?:, @day){0,5})(\/|\s?(?:[-–]|–)\s?|\s(?:and|&|to|or)\s+?)@Day\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2$3@Day2")
//.ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month,? @YYYY(?=\W\D)/gi, "$1@LMonth @Day1$2, @YYYY") //disabling as unlikely and ungrammatical constructions causing false positives
//.ohc_regex(/(\D\W)@Day((?:, @day){0,5})\s@Month(?=\W\D)/gi, "$1@LMonth @Day1$2") //disabling as unlikely and ungrammatical constructions causing false positives
//'dm, dm,' to 'md, md,'
.ohc_regex(/(\D\W)@Day @Month, @Day @Month(?=[,\.]?\W\D)/gi, "$1@LMonth1 @Day1, @LMonth2 @Day2")
//convert simple dmy dates to mdy
.ohc_regex(/(\D\W)@Day[\s]{1,3}@Month,?\s@Year(\s?(?:AD|BC|CE|BCE)\W\D)/gi, "$1@LMonth @Day, @Year$2")
.ohc_regex(/(\D\W)@Day[\s]{1,3}@Month,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @Year")
.ohc_regex(/(\D\W)@Day[\s]{1,3}@Month(?=\W\D)/gi, "$1@LMonth @Day")
//Month+day_number "March 7th" -> "March 7"
.ohc_regex(/(\D\W)@Month\s@Day,?\s@YYYY(?=\W\D)/gi, "$1@LMonth @Day, @YYYY")
.ohc_regex(/(\D\W)@Month\s@Day(?=\W\D)/gi, "$1@LMonth @Day")
//add comma where missing
.ohc_regex(/(\D\W)@Month\s@Day(?=\s@yyyy\W\D)/gi, "$1@LMonth @Day,")
//rem superfluous comma where applicable
.ohc_regex(/(\D[^\w\/])@Month\s@ZD,,(?=\W\D|\b)/gi, "$1@LMonth @Day,");
},
fix_dmy_redundancies: function(text) {
return text
//month-range redundancies (repeating month names)
.ohc_regex(/([\D]@dd) @Month[ ]{1,2}((?:to|and|-|–)[ ]{1,2}@dd) @Month/, "$1 $2 @LMonth", function(d1, d2) {
return d1.m == d2.m;
});
},
//not currently used
fix_mdy_redundancies: function(text) {
return text
//month-range redundancies (repeating month names)
.ohc_regex(/(@Month[ ]{1,2}@dd) (to|and|-|–)[ ]{1,2}@Month[ ]{1,2}@DD/, "$1 $2 @LDay", function(d1, d2) {
return d1.m == d2.m;
});
},
expand_ref_dates: function(text) {
return text
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month @YYYY(?=\s*[|}])/gi, "$1@FullMonth @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @FullMonth @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth @Day, @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=\s*[|}])/gi, "$1$2 @FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=\s*[|}])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=\s*[|}])/gi, "$1@$2 – @FullMonth @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|–) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 – @FullMonth @YYYY");
},
expand_all_dates: function(text) {
return text
.ohc_regex(/([^-\w/])@Month @YYYY(?=[^-\w/])/gi, '$1@FullMonth @YYYY')
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '$1@Day @FullMonth @YYYY')
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '$1@FullMonth @Day, @YYYY')
.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")
.ohc_regex(/([^-\w/])@Month @Day(, (?:19|20)\d\d) ?(?:-|–|–) ?@Month @Day, @YYYY(?=[^-\w/])/gi, "$1@FullMonth1 @Day1$2 – @FullMonth2 @Day2, @YYYY")
.ohc_regex(/([^-\w/])@Day @Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Day @Month @YYYY(?=[^-\w/])/gi, "$1@Day1 @FullMonth1$2 – @Day2 @FullMonth2 @YYYY")
.ohc_regex(/([^-\w/])@Month,?( (?:19|20)\d\d) ?(?:-|–|–) ?@Month,? @YYYY(?=[^-\w/])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY")
.ohc_regex(/([^-\w/])((?:19|20)\d\d) ?(?:-|–|–) ?@Month @YYYY(?=[^-\w/])/gi, "$1$2 – @FullMonth @YYYY")
.ohc_regex(/([ ]\(|\|\s*)@Day @Month @YYYY(?=\)\W|\s*[|\n])/gi, "$1@Day @FullMonth @YYYY")
.ohc_regex(/([ ]\(|\|\s*)@Month @Day,? @YYYY(?=\)\W|\s*[|\n])/gi, "$1@FullMonth @Day, @YYYY")
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–| ) ?@Day @Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @Day @FullMonth2 @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 @YYYY1 – @FullMonth2 @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@YYYY ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@YYYY1 – @FullMonth @YYYY2")
.ohc_regex(/([ ]\((?:c\. |))@Month ?(?:-|–| ) ?@Month @YYYY(?=\)\W)/gi, "$1@FullMonth1 – @FullMonth2 @YYYY")
.ohc_regex(/([ ]\((?:c\. |))@Month @YYYY(?=\)\W)/gi, "$1@FullMonth @YYYY");
},
abbrev_ref_dates: function(text) {
return text
.ohc_regex(/(\|\s*(?:date|archivedate|accessdate)\s*=\s*)@Day @Month @YYYY(?=\s*[|}])/gi, "$1@Day @Mon @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))([12]?\d|30|31) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber)( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3$4")
.ohc_regex(/([ ]\()@Day @Month @YYYY([^-\w\/])/gi, "$1@Day @Mon @YYYY$2")
.ohc_regex(/(\|\s*(?:date|archivedate|accessdate)\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, '$1@Mon @Day, @YYYY$2');
},
//not currently used
abbrev_all_dates: function(text) {
return text
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '$1@Day @Mon @YYYY')
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '$1@Mon @Day, @YYYY');
},
//not currently used
dmy_publication_dates: function(text) {
return text
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Month @Day,? @YYYY/gi, "$1@Day @Month @YYYY") // conversion of dates in references outside of the protection loop (eg for quotations etc.)
.ohc_regex(/(\|\s*(?:publication-|archive|)date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
//replace ISO dates (within parentheses) only within refs
.ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3$4");
},
mdy_publication_dates: function(text) {
return text
.ohc_regex(/(\|\s*(?:publication-|archive|access|)date\s*=\s*)@Day @Month @YYYY/gi, "$1@Month @Day, @YYYY") // conversion of dates in references outside of the protection loop (eg for quotations etc.)
.ohc_regex(/(\|\s*(?:publication-|archive|)date\s*=\s*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\s*[|}])/gi, "$1@Month @Day, @YYYY")
//replace ISO dates (within parentheses) only within refs
.ohc_regex(/(<ref[^>]*>[^<]+?)([ ]\()@YYYY-@MM-@DD(\))(\W[^<]*?<\/ref>)/gi, "$1$2@Month @Day, @YYYY$3$4");
},
iso_access_dates: function(text) {
return text
// Add a tag to the summary box
.ohc_regex(/(\|\s*(?:accessdate))\s*=\s*@Day @Month,? @YYYY(?=[\s]*[|}])/gi, "$1=@YYYY-@MM-@DD")
.ohc_regex(/(\|\s*(?:accessdate))\s*=\s*@Month @Day,? @YYYY(?=[\s]*[|}])/gi, "$1=@YYYY-@MM-@DD")
.ohc_regex(/(?:Retrieved |Accessed)[ ]*(?:on |)@Day @Month,? @YYYY(?=\s*[|}])/gi, "Retrieved @YYYY-@MM-@DD")
.ohc_regex(/(?:Retrieved |Accessed)[ ]*(?:on |)@Month @Day,? @YYYY(?=\s*[|}])/gi, "Retrieved @YYYY-@MM-@DD");
},
/** ------------------------------------------------------------------------ **/
/// EDIT SUMMARIES & USE DMY TEMPLATE
// format parameter must be 'dmy' or 'mdy'
use_dates_template: function(text, format) {
// current month-year
var currentDate = new Date();
var currmonth = currentDate.getMonth();
var curryear = currentDate.getFullYear();
var myMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var curryyyymm = myMonths[currmonth] + ' ' + curryear;
// insert the uses dates template
text = text
.replace(/\{\{(?:use (?:dmy|mdy) dates|dmy|mdy)[ ]*(?:\|[^{}}]*)?\}\}/gi, '{{Use '+format+' dates|date='+curryyyymm+'}}')
.replace(/\{\{(?:dmy|mdy)[ ]*(?:\|[^{}]*)?\}\}/gi, '{{Use '+format+' dates|date='+curryyyymm+'}}');
var rxpdd = new RegExp("{{Use "+format+" dates\\|date="+curryyyymm+"}}", "gi");
var dflagfound = text.search(rxpdd);
if (dflagfound == -1) {
text = '{{Use '+format+' dates|date='+curryyyymm+'}}\r\n'+text;
}
return text;
},
/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION
protect_dates: function(text, linkmap) {
// protects dates within links, 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;
};
return text
.replace(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function)
.replace(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function)
.replace(/(<ref)([^>]+)(>)/gi, protect_function)
.replace(/((?:Category|Image|File):)([^|\]]*)([|\]])/gi, protect_function)
.replace(/(\{(?:See ?also|Main))(\|[^}]*)(\})/gi, protect_function)
.replace(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:harvnb|wikisource)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function)
.replace(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function)
//.replace(/(https?:|ftp:)([^\s\]]*)([\s\]])/gi, protect_function)
.replace(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function)
.replace(/(\{[^\{]{0,6}(?:quot[^|]{1,7}\s?|sic)\|)([^}]+)(\})/gi, protect_function)
.replace(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|image[ _]file|img|pic)\s*=)([^|}]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)([^|\}⍍]*)([|}])/gi, protect_function)
.replace(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([|}])/gi, protect_function)
.replace(/(\{\{navsource\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{singlechart\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{defaultsort:)([^}]+)(\})/gi, protect_function)
.replace(/([\s\(>]")([^"\n]*)(")/gi, protect_function)
.replace(/([\s\(>]“)([^”\n]*)(”)/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function)
.replace(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function)
//retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, '$1Jiusan Society$2')
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, '$1Tiananmen Square protests of 1989$2')
.ohc_regex(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2')
.ohc_regex(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, '$1Overthrow of Slobodan Milošević$2')
//protect alternate meanings of 'may' and 'march' (note: not case insensitive)
.ohc_regex(/([^\w])(@day,?\s{0,3}may)([^\w][^\d])/g, protect_function)
.ohc_regex(/([^\w])(march\s@day)(\s(?:mile|kilomet|met))/g, protect_function)
//protect all links containing a date and some text
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth(?:,? @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
.ohc_regex(/(\[\[)(\s*\w[^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\|)/gi, protect_function)
.ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day(?:, @year|) \D[^\]\|\n]+\w\s*)(\]\]|\|)/gi, protect_function)
//protects certain dates
.replace(/(\[\[)(4AD)([\s\S])/gi, protect_function)
.replace(/([\s\S])(March (?:8|14) Alliance)([\s\S])/gi, protect_function)
.replace(/([\s\S])(23rd March 1931: Shaheed)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Long March [1-7])([\s\S])/gi, protect_function)
.replace(/([\s\S])(Bombay March 12)([\s\S])/gi, protect_function)
.replace(/([\s\S])(movement 2 June)([\s\S])/gi, protect_function)
.replace(/([\s\S])(6th\sof October City)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Party Workers' Liberation Front 30th of May)([\s\S])/gi, protect_function)
.replace(/([\s\S])(4th\sof August regime)([\s\S])/gi, protect_function)
.replace(/([\s\S])(19th\sof April movement)([\s\S])/gi, protect_function)
.replace(/([\s\S])(June 4th incident)([\s\S])/gi, protect_function)
.replace(/([\s\S])(The Battle Of Marston Moor \(July 2nd,? 1644\))([\s\S])/gi, protect_function)
.replace(/([\s\S])(Night of January 16th)([\s\S])/gi, protect_function)
.replace(/([\s\S])(Observance of 5th November Act)([\s\S])/gi, protect_function)
.replace(/(\[\[)(13 May incident)(\|)/gi, protect_function)
.replace(/(\[\[|\'\'\')(22nd\sof May)([|\]\'])/gi, protect_function)
.replace(/(\[\[)(November 1828)(\]\])/gi, protect_function)
.replace(/(.)(4th\sof July)(.)/gi, protect_function)
.replace(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function)
.replace(/(\[\[)(29 February)(\]\])/gi, protect_function)
.replace(/(\[\[)(February 29)(\]\])/gi, protect_function)
// works names
//.replace(/(.)(protect string)(.)/gi, protect_function)
.replace(/(.)(11\/22\/63)(.)/gi, protect_function)
.replace(/(.)(1\.1\.1994)(.)/gi, protect_function)
.replace(/([\s\S])(2\.13\.61)([\s\S])/gi, protect_function)
//.replace(/(.)(4th of July, Asbury)(.)/gi, protect_function) //protected above globally
.replace(/(.)(26 October 1993)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(June 1, 1974)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(July 15, 1972)(.)/gi, protect_function)
.replace(/(\[\[|\'\')(August 1914)(.)/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@fullmonth @dd@th? \((?:@yyyy |)film\)(?:\|@fullmonth @dd@th?|))([\s\S])/gi, protect_function)
.ohc_regex(/(\[\[|\'\')(@dd@th? @fullmonth \((?:@yyyy |)film\)(?:\|@dd@th? @fullmonth|))([\s\S])/gi, protect_function)
//.replace(/(Les Bains Douches 18)( December 1979)(.)/gi, protect_function)
.replace(/(August)( 7, 4:15)(.)/gi, protect_function)
.replace(/(In Concert, Zürich, October)( 28, 1979)(.)/gi, protect_function)
.replace(/(CBGB OMFUG Masters: Live June)( 29, 2001)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? [1-3]\d)( @fullmonth)(.)/gi, protect_function)
.ohc_regex(/(Live at [\w ]*,? @fullmonth)( @dd)(.)/gi, protect_function)
.ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function)
.replace(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d dec(?:l\.?|))(\W)/gi, protect_function)
.replace(/(\W)((?:\d{2,3})\/\d dec(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
},
unprotect_dates: function(text, linkmap) {
return text
//unprotect all dates
.replace(/[♫]/g, '')
.replace(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
var res = linkmap[n];
res = res.replace(/⍌([0-9]+)⍍/g, function(x, n) {
return linkmap[n];
});
return res;
});
return res;
});
return res;
});
},
mosnum_edit_summary: function() {
var $minorEdit = $('#wpMinoredit'), $summary = $('#wpSummary');
//Add a tag to the summary box
$minorEdit.attr('checked', true);
$summary.val(($summary.val() + ', date formats per [[MOS:DATEFORMAT]] by [[WP:MOSNUMscript|script]]').replace(/^, /, ''));
},
slash_edit_summary: function() {
var $minorEdit = $('#wpMinoredit'), $summary = $('#wpSummary');
//Add a tag to the summary box
$minorEdit.attr('checked', true);
$summary.val(($summary.val() + ', resolved [[WP:MOSNUM|ambiguous date formats]]').replace(/^, /, ''));
},
expand_edit_summary: function() {
var $minorEdit = $('#wpMinoredit'), $summary = $('#wpSummary');
//Add a tag to the summary box
$minorEdit.attr('checked', true);
$summary.val(($summary.val() + ', expand month names').replace(/^, /, ''));
},
abbrev_edit_summary: function() {
var $minorEdit = $('#wpMinoredit'), $summary = $('#wpSummary');
//Add a tag to the summary box
$minorEdit.attr('checked', true);
$summary.val(($summary.val() + ', abbrev month names').replace(/^, /, ''));
},
/** ------------------------------------------------------------------------ **/
/// CUSTOMIZATION POINTS
customize_all_to_dmy: function(text) { return text; },
customize_all_to_mdy: function(text) { return text; },
customize_body_to_dmy: function(text) { return text; },
customize_body_to_mdy: function(text) { return text; },
customize_iso_to_dmy: function(text) { return text; },
customize_iso_to_mdy: function(text) { return text; },
/** ------------------------------------------------------------------------ **/
/// DRIVER FUNCTIONS
/**
* Builds a TemplateScript callback that applies a driver function to the text.
* @param {function} callback A driver function that modifies the text. The first argument passed is the text to change.
* @param {boolean} showDiff Whether to show the edit diff after applying the changes.
*/
apply_driver: function(callback, showDiff) {
return function(editor) {
var text = callback(editor.get(), []);
editor.set(text);
if(showDiff !== false)
editor.clickDiff();
};
},
body_dates_to_dmy: function(text) {
text = ohc.dates.use_dates_template(text, 'dmy');
text = ohc.dates.fix_common_errors(text);
text = ohc.dates.fix_dts_template(text, 'dmy');
text = ohc.dates.fix_gr_template(text, 'dmy');
text = ohc.dates.dates_to_dmy(text);
text = ohc.dates.remove_leading_zeroes(text);
text = ohc.dates.fix_dmy_redundancies(text);
return text;
},
body_dates_to_mdy: function(text) {
text = ohc.dates.use_dates_template(text, 'mdy');
text = ohc.dates.fix_common_errors(text);
text = ohc.dates.fix_dts_template(text, 'mdy');
text = ohc.dates.fix_gr_template(text, 'mdy');
text = ohc.dates.dates_to_mdy(text);
text = ohc.dates.remove_leading_zeroes(text);
text = ohc.dates.fix_mdy_redundancies(text);
return text;
},
fix_unambiguous_dates_driver: function(text) {
return ohc.dates.fix_unambiguous_dates(text);
},
iso_access_dates_driver: function(text) {
return ohc.dates.iso_access_dates(text);
},
all_to_dmy_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.fix_unambiguous_dates(text);
text = ohc.dates.body_dates_to_dmy(text);
text = ohc.dates.delink_iso_to_dmy(text);
text = ohc.dates.delink_year_in_x(text);
text = ohc.dates.customize_all_to_dmy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
text = ohc.dates.iso_to_dmy_in_citations(text);
ohc.dates.mosnum_edit_summary();
return text;
},
all_to_mdy_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.fix_unambiguous_dates(text);
text = ohc.dates.body_dates_to_mdy(text);
text = ohc.dates.delink_iso_to_mdy(text);
text = ohc.dates.delink_year_in_x(text);
text = ohc.dates.customize_all_to_mdy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
text = ohc.dates.iso_to_mdy_in_citations(text);
ohc.dates.mosnum_edit_summary();
return text;
},
dmy_publication_dates_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.body_dates_to_dmy(text);
text = ohc.dates.customize_body_to_dmy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
text = ohc.dates.dmy_publication_dates(text);
ohc.dates.mosnum_edit_summary();
return text;
},
mdy_publication_dates_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.body_dates_to_mdy(text);
text = ohc.dates.customize_body_to_mdy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
text = ohc.dates.mdy_publication_dates(text);
ohc.dates.mosnum_edit_summary();
return text;
},
body_to_dmy_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.body_dates_to_dmy(text);
text = ohc.dates.customize_body_to_dmy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.mosnum_edit_summary();
return text;
},
body_to_mdy_driver: function(text, linkmap) {
text = ohc.dates.delink_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.body_dates_to_mdy(text);
text = ohc.dates.customize_body_to_mdy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.mosnum_edit_summary();
return text;
},
iso_to_dmy_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.delink_iso_to_dmy(text);
text = ohc.dates.customize_iso_to_dmy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
// ohc.dates.mosnum_edit_summary();
return text;
},
iso_to_mdy_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.delink_iso_to_mdy(text);
text = ohc.dates.customize_iso_to_mdy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
// ohc.dates.mosnum_edit_summary();
return text;
},
delink_year_in_x_driver: function(text) {
return ohc.dates.delink_year_in_x(text);
},
unambiguous_dates_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.fix_unambiguous_dates(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.slash_edit_summary();
return text;
},
us_slash_dates_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.us_slash_dates_to_mdy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.slash_edit_summary();
return text;
},
uk_slash_dates_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.uk_slash_dates_to_dmy(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.slash_edit_summary();
return text;
},
expand_ref_dates_driver: function(text, linkmap) {
text = ohc.dates.expand_ref_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.expand_edit_summary();
return text;
},
expand_all_dates_driver: function(text, linkmap) {
text = ohc.dates.expand_ref_dates(text);
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.expand_all_dates(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.expand_edit_summary();
return text;
},
abbrev_ref_dates_driver: function(text, linkmap) {
text = ohc.dates.protect_dates(text, linkmap);
text = ohc.dates.abbrev_ref_dates(text);
text = ohc.dates.unprotect_dates(text, linkmap);
ohc.dates.abbrev_edit_summary();
return text;
}
};