Jump to content

User:1exec1/dates.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* <syntaxhighlight lang="javascript"> */

/**
 * 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/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');

importScript("User:1exec1/date_utils.js");

function ohc_fix_unambiguous_dates()
{
    // UK style
    ohc_regex(/([^\d][^\w\/-:♫])@DD[\/\.]@MM[\/\.]@YYYY(?=[^\w-–\/][^\d])/gi, "$1@Day @Month @YYYY", function(d) {
        if (d.d == d.m) return true;
        if (d.d > 12) return true;
        return false;
        });

    // US style
    ohc_regex(/([^\d][^\w\/-:♫])@MM[\/\.]@DD[\/\.]@YYYY(?=[^\w-–\/][^\d])/gi, "$1@Month @Day, @YYYY", function(d) {
        if (d.d > 12) return true;
        return false;
        });
}

function ohc_US_slash_dates_to_mdy()
{
    // resolvable ambiguous date formats
    ohc_regex(/([^\d][^\w\/-:♫])@MM\/@DD\/@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Month @Day, @YYYY');
    ohc_regex(/([^\d][^\w\/-:♫])@MM\.@DD\.@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Month @Day, @YYYY');
    ohc_regex(/([^\d][^\w\/-:♫])@MM[-–]@DD[-–]@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Month @Day, @YYYY');
}

function ohc_UK_slash_dates_to_dmy()
{
    // resolvable ambiguous date formats
    ohc_regex(/([^\d][^\w\/-:♫])@DD\/@MM\/@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Day @Month @YYYY');
    ohc_regex(/([^\d][^\w\/-:♫])@DD\.@MM\.@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Day @Month @YYYY');
    ohc_regex(/([^\d][^\w\/-:♫])@DD[-–]@MM[-–]@YYNN(?=[^\w-–\/][^\d])/gi, '$1@Day @Month @YYYY');
}

function ohc_remove_leading_zeroes()
{
    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");
}

function ohc_delink_dates()
{
    //delink piped md|dm, md|dd and my|m dates
    ohc_regex(/\[\[@month @dd\|@DD @Month\]\]/gi, "@LDay @LMonth");
    ohc_regex(/\[\[@month @dd\|@DD\]\]/gi, "@LDay");
    ohc_regex(/\[\[@month @yyyy\|@Month\]\]/gi, "@LMonth");

    //delink ISO8601 dates
    ohc_regex(/\[\[@YYYY(?:\]\]-\[\[|-)@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
    ohc_regex(/@YYYY-\[\[@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");

    //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 piped pseudo-ISO dates
    ohc_regex(/\[\[@Month @DD\|@dd-@dd\]\]-(?:\[\[)?@YYYY(?:\|@yyyy)?(?:\]\])/gi, "@Day @Month @YYYY");
    ohc_regex(/\[\[@DD\s@Month\|@dd-@dd\]\]-(?:\[\[)?@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
    regex(/\[\[((?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first(?:\s|-))(century|centuries)(\sAD|\sBC|\sCE|\sBCE|))\]\]/gi, '$1');
    regex(/\[\[(?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|twenty(?:\s|-)first)[\s-_](?:century|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|([^\]]{1,30})\]\]/gi, '$1');
    regex(/\[\[(\d{1,2}(?:st|nd|rd|th)[\s-_])(century|centuries)(\sAD|\sBC|\sCE|\sBCE|)\]\]/gi, '$1$2$3');
    regex(/\[\[\d{1,2}(?:st|nd|rd|th)[\s-_](?:century|centuries)(?:\sAD|\sBC|\sCE|\sBCE|)\|([^\]]{1,30})\]\]/gi, '$1');

    // months
    ohc_regex(/\[\[@Month\]\]/gi, "@Month");
    ohc_regex(/\[\[@FullMonth\|([^\]]{1,30})\]\]/gi, "$1");

    // decades and years
    regex(/\[\[(\d{1,3}0)\'?s\]\]/g, '$1s');
    regex(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, '$1');
    regex(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '$1$2 $3');
    regex(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi, '$1$2');
    regex(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi, '$1');
    regex(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, '$1');
    regex(/\[\[\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#[^\|\]]+\|(@month\s@yyyy)\]\]/gi, "$1");
    ohc_regex(/\[\[(@month\s@yyyy)\]\]/gi, "$1");
    ohc_regex(/\[\[@month\s@yyyy\|([^\]]{1,30})\]\]/gi, "$1");

    //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 articles.
    ohc_regex(/\[\[\d{1,4}#[^\|\]]+\|@Month\]\]/gi, "@LMonth");

    // 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
    regex(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, '$1');
}

function ohc_fix_common_errors()
{
    //insert comma to separate date from army unit
    ohc_regex(/@FullMonth (the \d\d*@th (?:Armou?red|Artillery|Battalion|Brigade|Company|Group|Infantry|Regiment|Squadron))/gi, "@Month, $1");

    // remove nowrap template from dm and md dates
    ohc_regex(/(date=)\{\{nowrap\|(@dd(?:_|&nbsp;)@month)\}\}/gi, '$1$2');
    ohc_regex(/(date=)\{\{nowrap\|(@month(?:_|&nbsp;)@dd)\}\}/gi, '$1$2');

    //fix bda template redirect
    regex(/{{bda\|([^}]+)}}/gi, '{{birth date and age|$1}}');
    regex(/{{dda\|([^}]+)}}/gi, '{{death date and age|$1}}');

    //zap redundant {{date}}, {{accessdate}} and {{#dateformat}}
    ohc_regex(/\{\{date\|@YYYY-@MM-@DD\}\}/gi, "@Day @Month @YYYY");
    regex(/\{\{date\|([^\}\|\-]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi, '$1');
    ohc_regex(/[ ]*\{\{accessdate\|@YYYY-@MM-@DD[ ]*\}\}/gi, " Retrieved @YYYY-@MM-@DD");
    regex(/\{\{#dateformat:♫?([^\}\|]+)(?:\|dmy|\|mdy)?}}/gi,'$1');

    //underscore and nbsp in linked dates
    ohc_regex(/\[\[@DD(?:_|&nbsp;)@Month\]\]/gi, "@Day @LMonth");
    ohc_regex(/\[\[@Month(?:_|&nbsp;)@DD\]\]/gi, "@LMonth @Day");

    //remove leading zero and links from linked date
    ohc_regex(/\[\[@Month(?:[ _]|&nbsp;)@ZD@th\]\]/gi, "@LMonth @Day");
    ohc_regex(/\[\[@ZD@th(?:[ _]|&nbsp;)@Month\]\]/gi, "@Day @LMonth");

    //remove unlinked ordinal date formats
    ohc_regex(/([^\w])@Day, @Day(\s(?:and|&|to|or)\s)@Day(?:\sof\s?)?(?:_|&nbsp;)@Month(?=[^\w][^\d])/gi, '$1@Day1, @Day2$2@Day3 @LMonth');
    ohc_regex(/([^\w])@Day(\s(?:and|&|to|or)\s)@Day(?:\sof\s?)?(?:_|&nbsp;)@Month(?=[^\w][^\d])/gi, '$1@Day1$2@Day2 @LMonth');
    ohc_regex(/([^\w])@Day(?:\sof\s?)(?:_|&nbsp;)@Month(?=[^\|\]\w])/gi, '$1@Day @LMonth');
    ohc_regex(/([^\w])@DD<sup>@th?<\/sup>(?:\sof\s?)?\s(@Month)(?=[^\w][^\d])/gi, '$1@Day @LMonth');
    ohc_regex(/([^\w])@Month\s(?:the\s)?@Day,(?:\sthe\s)?(?:[ _]|&nbsp;)@Day(\s(?:and|&|to|or)(?:[ _]|&nbsp;))(?:the\s)?@Day(?=[^\]\|\w][^\d])/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(?:,?(?:[ _]|&nbsp;)|\sof\s)?(\d{3,4}[^\w][^\d])/gi, '$1$2 $3$4$5@Day, $6');
    ohc_regex(/([^\w])@Month(?:_|&nbsp;)(?:the\s)?@Day(?=[^\]\|\w][^\d])/gi, '$1@LMonth @DD');
    ohc_regex(/([^\w])@Month(?:_|&nbsp;)(?:the\s)?@DD<sup>@th<\/sup>(?=[^\]\|\w][^\d])/gi, '$1@LMonth @DD');

    // eliminating days of the week
    regex(/(\|[ ]*(?:date|archivedate|accessdate|author)[ ]*=[ ]*)(?:(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,?)\s/gi, "$1");
    regex(/(\|[ ]*(?:date|archivedate|accessdate|author)[ ]*=[ ]*)(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)[\.,])\s/gi, "$1");

    // eliminating dates placed in author parameter
    ohc_regex(/(\|\s*author\s*=\s*)@month @day,? @yyyy\s?(?:,? \d\d:\d\d(?:\s*|&nbsp;)(?:PM\s*|AM\s*|)(?:GMT\s*|UTC\s*|EST\s*|BST\s*|)|)\|/gi, "|");
    ohc_regex(/(\|\s*author\s*=\s*)@day @month,? @yyyy\s?(?:,? \d\d:\d\d(?:\s*|&nbsp;)(?:PM\s*|AM\s*|)(?:GMT\s*|UTC\s*|EST\s*|BST\s*|)|)\|/gi, "|");

    // eliminating dd-mm-yyyy dates
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@DD(?:\]\]-\[\[|-)@MM-@YYYY(?:\]\])?/gi, "$1@Day @Month @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@DD(?:\]\]-\[\[|-)@Mon-@YYYY(?:\]\])?/gi, "$1@Day @Month @YYYY");

    // eliminating other errant formats
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@YYYY, @Month @DD(\D)/gi, "$1@Day @Month @YYYY$2");
    ohc_regex(/ \(@YYYY, @Month @DD\)/gi, " (@Day @Month @YYYY)");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@YYYY,? @Month([ ]?\D)/gi, "$1@Month @YYYY$2");
    ohc_regex(/ \(@YYYY, @Month\)/gi, " (@Month @YYYY)");

    // spaces and commas between month and year
    ohc_regex(/@Month(?:,\s+|\s+of\s+)@YYYY([^\w])/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");
    regex(/(\d)[ ]?(?:-|–|&ndash;)[ ]?Present\b/g, '$1 – present');
    //regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, '$1c$2');
    //regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ -]*(?:Fox|[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*[-–]\s*)@Month\s@DD(?=[^\w][^\d])/gi, "$1@LMonth1 @Day1 – @LMonth2 @Day2");
    ohc_regex(/([^\d][^\w])@Month\s@DD&nbsp;(?:\s*[-–]\s*)@Month\s@DD(?=[^\w][^\d])/gi, "$1@LMonth1 @Day1&nbsp;– @LMonth2 @Day2");
    ohc_regex(/([^\d][^\w])@DD\s@Month(?:\s*[-–]\s*)@DD\s@Month(?=[^\w][^\d])/gi, "$1@Day1 @LMonth1 – @Day2 @LMonth2");
    ohc_regex(/([^\d][^\w])@DD\s@Month&nbsp;(?:\s*[-–]\s*)@DD\s@Month(?=[^\w][^\d])/gi, "$1@Day1 @LMonth1&nbsp;– @Day2 @LMonth2");

    // spaces and commas - d-dm and md-d date ranges
    ohc_regex(/([^\d][^\w])@Month\s@DD(?:(?:\s*|&nbsp;)[-–]\s*)@DD(?=[^\w][^\d])/gi, "$1@LMonth1 @Day1–@Day2");
    ohc_regex(/([^\d][^\w])@DD(?:(?:\s*|&nbsp;)[-–]\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?(?:[-–—]|&ndash;)(?:&nbsp;|\s)?)@DD\s@Month,? @Year(?=[^\d][^\w])/gi, "$1@Day1 @LMonth1 @Year1 – @Day2 @LMonth2 @Year2");
    ohc_regex(/([^\d][^\w])@DD\s@Month,? @Year&nbsp;(?:\s?(?:[-–—]|&ndash;)(?:&nbsp;|\s)?)@DD\s@Month,? @Year(?=[^\d][^\w])/gi, "$1@Day1 @LMonth1 @Year1&nbsp;– @Day2 @LMonth2 @Year2");
    ohc_regex(/([^\d][^\w])@Month\s@DD,? @Year(?:\s?(?:[-–—]|&ndash;)(?:&nbsp;|\s)?)@Month\s@DD,? @Year(?=[^\d][^\w])/gi, "$1@LMonth1 @Day1, @Year1 – @LMonth2 @Day2, @Year2");
    ohc_regex(/([^\d][^\w])@Month\s@DD,? @Year&nbsp;(?:\s?(?:[-–—]|&ndash;)(?:&nbsp;|\s)?)@Month\s@DD,? @Year(?=[^\d][^\w])/gi, "$1@LMonth1 @Day1, @Year1&nbsp;– @LMonth2 @Day2, @Year2");

    //nbsp in publication archive & access dates
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*@dd)&nbsp;(@month)/gi, '$1 $2');
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(@month)&nbsp;(@dd)(, @yyyy|)(?=[ ]*[\|\}])/gi, '$1$2 $3$4');

    ohc_regex(/([ =]+)@DD-@Mon-@YYYY(?![-–\d\/])/gi, "$1@Day @Month @YYYY");
    ohc_regex(/([ =]+)@DD-@MM-@YYYY(?![-–\d\/])/gi, "$1@Day @Month @YYYY");

    //'Accessed' -> 'Retrieved'
    ohc_regex(/(<ref[^>]*>[^<]+?)[,\.] Accessed(?: on(?:line|)|):?\s*(@month|@dd)([^<]*?<\/ref>)/gi, "$1. Retrieved $2$3");
    ohc_regex(/(<ref[^>]*>[^<]+?)[,\.] Retrieved(?: on(?:line|)|)(:|)\s*(@month|@dd)([^<]*?<\/ref>)/gi, "$1. Retrieved$2 $3$4");
    ohc_regex(/(<ref[^>]*>[^<]+?)\s*\(Accessed(?: on(?:line|)|):?\s*((?:@month|@dd)[^)]{4,20})\)([^<]*?<\/ref>)/gi, "$1. Retrieved $2$3");
    ohc_regex(/(<ref[^>]*>[^<]+?)\s*\(Retrieved(?: on(?:line|)|)(:|)\s*((?:@month|@dd)[^)]{4,20})\)([^<]*?<\/ref>)/gi, "$1. Retrieved$2 $3$4");

    // 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

function ohc_ISO_to_dmy_in_citations()
{
    //multiple calls for multiple dates within single citation
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Day @Month @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Day @Month @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Day @Month @YYYY");
}

function ohc_ISO_to_mdy_in_citations()
{
    //multiple calls for multiple dates within single citation
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Month @Day, @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Month @Day, @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Month @Day, @YYYY");
}

function ohc_ISO_to_dmy_in_references()
{
    //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([^\w\/\-%,<][^<]*?<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
    ohc_regex(/(<ref[^>]*>[^<]+?)([\s\(])@YYYY[-–]@MM[-–]@DD(<\/ref>)/gi, "$1$2@Day @Month @YYYY$3");
}

function ohc_ISO_to_mdy_in_references()
{
    //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
function ohc_ISO_to_dmy_anywhere()
{
    //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
function ohc_ISO_to_mdy_anywhere()
{
    //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');
}

function ohc_delink_ISO_to_dmy()
{
    ohc_ISO_to_dmy_in_citations();
    ohc_ISO_to_dmy_in_references();
}

function ohc_delink_ISO_to_mdy()
{
    ohc_ISO_to_mdy_in_citations();
    ohc_ISO_to_mdy_in_references();
}

function ohc_delink_year_in_X()
{
    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");
    regex(/\[\[\d{1,4}\sin\s[^\|\]]+\|(\d{4})\]\]/gi, '$1');
//  regex(/\[\[(?:\d{4}.\d{2} in English football)\|([^\]]{1,30})\]\]/gi, '$1'); //temp disable to work on English football articles

    regex(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi, '$1$2');
}


// format parameter must be 'dmy' or 'mdy'
function ohc_fix_dts_template(format)
{
    // per {{dts}} doc, remove the obsolete link=off param
    regex(/(\{\{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');
}

// format parameter must be 'dmy' or 'mdy'
function ohc_fix_gr_template(format)
{
    // GR - date formatting parameter
    // per {{GR}} doc, insert date formatting param
    regex(/(\{\{GR\|\d\d?)(?!\|date)/gi, '$1|dateform=' + format);
}

function ohc_dates_to_dmy()
{
    //change start and end templates
    regex(/(\{\{(start\sdate|end\sdate)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');

    //change deprecated birth and death templates
    regex(/(\{\{(?:Birth|Death|launch|release|start|end)[^}]*)\|mf=ye?s?/gi, '$1'); //rem pipe symbol to treat cases where mf is at the end
    regex(/(\{\{(?:Birth|Death|launch|release|start|end|film date|Wayback)[^|}]*\|)/gi, '$1df=yes|');
    regex(/(\{\{(?:Birth|Death|launch|release|start|end|film date|Wayback)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '$1$2');

    // convert dates with year before any year-less dates
    // (md,d,d-dy to d,d,d-dmy)
    ohc_regex(/([^\d][^\w])@Month((?:\s@day?,?){1,6}),?((?:[\s_]*|&nbsp;)(?:and|&|to|or|[-–\/]|&ndash;)(?:[\s_]*|&nbsp;))@Day,?\s(?:of\s)?(@yyyy[^\w][^\d])/gi, "$1$2$3@Day @LMonth $4");

    // (mdy-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");

    // (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_]*|&nbsp;)(?:and|&|to|or|[-–\/]|&ndash;)(?:[\s_]*|&nbsp;))@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");

    // (md, md, to dm, dm,)
    ohc_regex(/([^\d][^\w])@Month @Day, @Month @Day(?=[,\.][^\w][^\d])/gi, "$1@Day1 @LMonth1, @Day2 @LMonth2");
    
    // 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?@YYYY(?=[^\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");

    // remaining md to dm
    ohc_regex(/([^\d][^\w])@Month\s@Day(?=[^\w][^\d])/gi, "$1@Day @LMonth");
}

function ohc_dates_to_mdy()
{
    //change deprecated birth and death templates
    regex(/({{(?:Birth|Death|release|start|end)[^}]*)\|df=ye?s?/gi, '$1');
    regex(/({{(?:Birth|Death|release|start|end)[^|]*\|)mf=ye?s?\|([^}]*mf=ye?s?)/gi, '$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?(?:[-–]|&ndash;)\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?(?:[-–]|&ndash;)\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");
    ohc_regex(/([^\d][^\w])@Day((?:, @day){0,5})\s@Month(?=[^\w][^\d])/gi, "$1@LMonth @Day1$2");

    //'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,");
}

function ohc_fix_dmy_redundancies()
{
    //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) {
        if (d1.m == d2.m) return true;
        return false;
    });
}

function ohc_fix_mdy_redundancies()
{
    //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) {
        if (d1.m == d2.m) return true;
        return false;
    });
}

function ohc_expand_ref_dates()
{
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@Day @Month @YYYY(?=[ ]*[\|\}])/gi, "$1@Day @FullMonth @YYYY");
    ohc_regex(/(<ref[^>]*>[^<]+?[\s\(])@Day @Month @YYYY([^\d\w\/\-%,<]*?<\/ref>)/gi, "$1@Day @FullMonth @YYYY$2");

    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@Month @Day, @YYYY(?=[ ]*[\|\}])/gi, "$1@FullMonth @Day, @YYYY");
    ohc_regex(/(<ref[^>]*>[^<]+?[\s\(])@Month @Day, @YYYY([^\d\w\/\-%,<]*?<\/ref>)/gi, "$1@FullMonth @Day, @YYYY$2");
}

function ohc_expand_all_dates()
{
    ohc_regex(/([^\w\/-])@Day @Month @YYYY([^\w\/-])/gi, '$1@Day @FullMonth @YYYY$2');
    ohc_regex(/([^\w\/-])@Month @Day, @YYYY([^\w\/-])/gi, '$1@FullMonth @Day, @YYYY$2');
}

function ohc_abbrev_ref_dates()
{
    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@Day @Month @YYYY(?=[ ]*[\|\}])/gi, "$1@Day @Mon @YYYY");
    ohc_regex(/(<ref[^>]*>[^<]+?[\s\(])@Day @Month @YYYY([^\d\w\/\-%,<]*?<\/ref>)/gi, "$1@Day @Mon @YYYY$2");

    ohc_regex(/(\|[ ]*(?:date|archivedate|accessdate)[ ]*=[ ]*)@Month @Day, @YYYY(?=[ ]*[\|\}])/gi, "$1@Mon @Day, @YYYY");
    ohc_regex(/(<ref[^>]*>[^<]+?[\s\(])@Month @Day, @YYYY([^\d\w\/\-%,<]*?<\/ref>)/gi, "$1@Mon @Day, @YYYY$2");
}

//not currently used
function ohc_abbrev_all_dates()
{
    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
function ohc_publication_dates()
{
    ohc_regex(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Day @Month @YYYY");
    ohc_regex(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=[^\w][^\d])/gi, "$1@Month @Day, @YYYY");
}

/** ------------------------------------------------------------------------ **/
/// DATE PROTECTION

var linkmap=[];
function ohc_protect_dates()
{
    // 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;
    }

    regex(/((?:Category|Image|File):)([^|\]]*)([\|\]])/gi, protect_function);
    regex(/(\{(?:See ?also|Main))(\|[^\}]*)(\})/gi, protect_function);
    regex(/(\[(?:http:|https:|ftp:))([^\s\]]*)([\s\]])/gi, protect_function);
    regex(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function);
    regex(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function);
    regex(/(<ref)([^>]+)(>)/gi, protect_function);
    regex(/(<ref[^>]*>(?:http:|https:|ftp:))([^\s<]*)(<\/ref>)/gi, protect_function);
    regex(/(<ref[^>]*>(?:http:|https:|ftp:))([^\s<]*)(<\/ref>)/gi, protect_function);
    regex(/(<ref[^>]*>(?:.(?!<\/ref>))*?'')((?:.(?!<\/ref>))*?)(''(?:.(?!<\/ref>))*?.?<\/ref>)/gi, protect_function);
    regex(/([\|\{]\s*(?:file|filename\d?|image\d?|image location\d?|img|pic|title|quote|chapter|journal|url|archiveurl|work|doi|club)\s*=)([^\|\}⍍]*)([\|\}])/gi, protect_function);
    regex(/([\|\{]\s*(?:file|filename\d?|image\d?|image location\d?|img|pic|title|quote|chapter|journal|url|archiveurl|work|doi|club)\s*=)([^\|\}⍍]*)([\|\}])/gi, protect_function);
    regex(/([\|\{]\s*(?:season)\s*=)(\s*\[\[[^\]]*\]\]\s*)([\|\}])/gi, protect_function);
    regex(/(\{[^\{]{0,6}(?:quot[^\|]{1,7}\s?|sic)\|)([^\}]+)(\})/gi, protect_function);
    regex(/([*\s\(]")([^"\n]*)(")/gi, protect_function);
    regex(/([*\s\(]“)([^”\n]*)(”)/gi, protect_function);

    //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 internal links containing a date and some text
    ohc_regex(/(\[\[)([^\]\|\n]+?@day[^\]\|\n]+?@fullmonth[^\]\|\n]*)(\]\]|\|)/gi, protect_function);
    ohc_regex(/(\[\[)([^\]\|\n]*?@day[^\]\|\n]+?@fullmonth[^\]\|\n]+)(\]\]|\|)/gi, protect_function);
    ohc_regex(/(\[\[)([^\]\|\n]+?@fullmonth[^\]\|\n]+?@day[^\]\|\n]*)(\]\]|\|)/gi, protect_function);
    ohc_regex(/(\[\[)([^\]\|\n]*?@fullmonth[^\]\|\n]+?@day[^\]\|\n]+)(\]\]|\|)/gi, protect_function);

    //protect all external links
    ohc_regex(/([^\[]\[)(\s*http[^\]]*)(\][^\]])/gi, protect_function);
    ohc_regex(/^(\[)(\s*http[^\]]*)(\][^\]])/gi, protect_function);
    ohc_regex(/([^\[]\[)(\s*http[^\]]*)(\])$/gi, protect_function);
    ohc_regex(/^(\[)(\s*http[^\]]*)(\])$/gi, protect_function);

    //protects certain dates
    regex(/(\[\[)(4AD)(.)/gi, protect_function);
    regex(/([\s\S])(March (?:8|14) Alliance)([\s\S])/gi, protect_function);
    regex(/([\s\S])(23rd March 1931: Shaheed)([\s\S])/gi, protect_function);
    regex(/([\s\S])(Long March [1-7])([\s\S])/gi, protect_function);
    regex(/([\s\S])(movement 2 June)([\s\S])/gi, protect_function);
    regex(/([\s\S])(6th\sof October City)([\s\S])/gi, protect_function);
    regex(/([\s\S])(Party Workers' Liberation Front 30th of May)([\s\S])/gi, protect_function);
    regex(/([\s\S])(4th\sof August regime)([\s\S])/gi, protect_function);
    regex(/([\s\S])(19th\sof April movement)([\s\S])/gi, protect_function);
    regex(/([\s\S])(June 4th incident)([\s\S])/gi, protect_function);
    regex(/([\s\S])(July 31st \(film\))([\s\S])/gi, protect_function);
    regex(/(\[\[)(13 May incident)(\|)/gi, protect_function);
    regex(/(\[\[)(November 1828)(\]\])/gi, protect_function);
    regex(/(\[\[)(2030 CE)(\]\])/gi, protect_function);
    regex(/(\[\[May\s1968)(\]\])/gi, '$1 in France|May 1968$2');
    regex(/(\[\[)(4th\sof July)(.)/gi, protect_function);
    regex(/(\[\[)((?:2300|2000)\s?AD)(\]\])/gi, protect_function);
    regex(/(\[\[)(29 February)(\]\])/gi, protect_function);
    regex(/(\[\[)(February 29)(\]\])/gi, protect_function);

    // album names
    regex(/(4th\sof)( July, Asbury)/gi, '$1♫$2');
    regex(/((?:\[\[|\'\')June)( 1, 1974)(?=[\]\'])/gi, '$1♫$2');
    regex(/((?:\[\[|\'\')July)( 15, 1972)(?=[\]\'])/gi, '$1♫$2');
    regex(/(Les Bains Douches 18)( December 1979)/gi, '$1♫$2');
    regex(/(Live \(at Raji's June)( 12\))/gi, '$1♫$2');
    regex(/(August)( 7, 4:15)/gi, '$1♫$2');
    regex(/(In Concert, Zürich, October)( 28, 1979)/gi, '$1♫$2');
    regex(/(CBGB OMFUG Masters: Live June)( 29, 2001)/gi, '$1♫$2');
    ohc_regex(/(Live at [^\|\]]* [1-3]\d)( @fullmonth)/gi, "$1♫$2");
    ohc_regex(/(Live at [^\|\]]* @fullmonth)( @dd)/gi, "$1♫$2");
}

function ohc_unprotect_dates()
{
	//unprotect all dates
    regex(/[♫]/g, '');
    regex(/⍌([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;
    });
}

/** ------------------------------------------------------------------------ **/
/// EDIT SUMMARIES & USE DMY TEMPLATE

// format parameter must be 'dmy' or 'mdy'
function ohc_use_dates_template(format)
{
    var txt=document.editform.wpTextbox1;
    // 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
    regex(/{{(use (dmy|mdy) dates|dmy|mdy)[ ]*(\|[^}]*)?}}/gi, '{{Use '+format+' dates|date='+curryyyymm+'}}');

    var rxpdd = new RegExp("{{Use "+format+" dates\\|date="+curryyyymm+"}}", "gi");
    var dflagfound = txt.value.search(rxpdd);
    if (dflagfound == -1)
    {
        txt.value='{{Use '+format+' dates|date='+curryyyymm+'}}\r\n'+txt.value;
    }
}

function ohc_MOSNUM_edit_summary()
{
    //Add a tag to the summary box
    setoptions(minor='true'); 		
    setreason('date formats per [[WP:MOSNUM]] by [[WP:MOSNUMscript|script]]', 'append');
    doaction('diff');
}

function ohc_slash_edit_summary()
{
    //Add a tag to the summary box
    setoptions(minor='true'); 		
    setreason('resolved [[WP:MOSNUM|ambiguous date formats]]', 'append');
    doaction('diff');
}

function ohc_expand_edit_summary()
{
    //Add a tag to the summary box
    setoptions(minor='true'); 		
    setreason('expand month names', 'append');
    doaction('diff');
}

function ohc_abbrev_edit_summary()
{
    //Add a tag to the summary box
    setoptions(minor='true'); 		
    setreason('abbrev month names', 'append');
    doaction('diff');
}

/** ------------------------------------------------------------------------ **/
/// CUSTOMIZATION POINTS
function ohc_customize_all_to_dmy() {}
function ohc_customize_all_to_mdy() {}
function ohc_customize_body_to_dmy() {}
function ohc_customize_body_to_mdy() {}
function ohc_customize_ISO_to_dmy() {}
function ohc_customize_ISO_to_mdy() {}

/** ------------------------------------------------------------------------ **/
/// DRIVER FUNCTIONS

function ohc_body_dates_to_dmy()
{
    ohc_use_dates_template('dmy');

    ohc_fix_common_errors();
    ohc_fix_dts_template('dmy');
    ohc_fix_gr_template('dmy');
    ohc_delink_dates();
    ohc_dates_to_dmy();
    ohc_remove_leading_zeroes();
    ohc_fix_dmy_redundancies();
}

function ohc_body_dates_to_mdy()
{
    ohc_use_dates_template('mdy');

    ohc_fix_common_errors();
    ohc_fix_dts_template('mdy');
    ohc_fix_gr_template('mdy');
    ohc_delink_dates();
    ohc_dates_to_mdy();
    ohc_remove_leading_zeroes();
    ohc_fix_mdy_redundancies();
}


/** ------------------------------------------------------------------------ **/

function ohc_all_to_dmy_driver()
{
    ohc_protect_dates();
    ohc_fix_unambiguous_dates();
    ohc_body_dates_to_dmy();
    ohc_delink_ISO_to_dmy();
    ohc_delink_year_in_X();
    ohc_customize_all_to_dmy();
    ohc_unprotect_dates();

    ohc_MOSNUM_edit_summary();
}

function ohc_all_to_mdy_driver()
{
    ohc_protect_dates();
    ohc_fix_unambiguous_dates();
    ohc_body_dates_to_mdy();
    ohc_delink_ISO_to_mdy();
    ohc_delink_year_in_X();
    ohc_customize_all_to_mdy();
    ohc_unprotect_dates();

    ohc_MOSNUM_edit_summary();
}

function ohc_body_to_dmy_driver()
{
    ohc_protect_dates();
    ohc_body_dates_to_dmy();
    ohc_customize_body_to_dmy();
    ohc_unprotect_dates();

    ohc_MOSNUM_edit_summary();
}

function ohc_body_to_mdy_driver()
{
    ohc_protect_dates();
    ohc_body_dates_to_mdy();
    ohc_customize_body_to_mdy();
    ohc_unprotect_dates();

    ohc_MOSNUM_edit_summary();
}

function ohc_ISO_to_dmy_driver()
{
    ohc_protect_dates();
    ohc_delink_ISO_to_dmy();
    ohc_customize_ISO_to_dmy();
    ohc_unprotect_dates();

//  ohc_MOSNUM_edit_summary();
}

function ohc_ISO_to_mdy_driver()
{
    ohc_protect_dates();
    ohc_delink_ISO_to_mdy();
    ohc_customize_ISO_to_mdy();
    ohc_unprotect_dates();

    //  ohc_MOSNUM_edit_summary();
}

function ohc_delink_year_in_X_driver()
{
    ohc_delink_year_in_X();
}

function ohc_unambiguous_dates_driver()
{
    ohc_protect_dates();
    ohc_fix_unambiguous_dates();
    ohc_unprotect_dates();

    ohc_slash_edit_summary();
}

function ohc_US_slash_dates_driver()
{
    ohc_protect_dates();
    ohc_US_slash_dates_to_mdy();
    ohc_unprotect_dates();

    ohc_slash_edit_summary();
}

function ohc_UK_slash_dates_driver()
{
    ohc_protect_dates();
    ohc_UK_slash_dates_to_dmy();
    ohc_unprotect_dates();

    ohc_slash_edit_summary();
}

function ohc_expand_ref_dates_driver()
{
    ohc_protect_dates();
    ohc_expand_ref_dates();
    ohc_unprotect_dates();
    ohc_expand_edit_summary();
}

function ohc_expand_all_dates_driver()
{
    ohc_protect_dates();
    ohc_expand_ref_dates();
    ohc_expand_all_dates();
    ohc_unprotect_dates();
    ohc_expand_edit_summary();
}

function ohc_abbrev_ref_dates_driver()
{
    ohc_protect_dates();
    ohc_abbrev_ref_dates();
    ohc_unprotect_dates();
    ohc_abbrev_edit_summary();
}

function Ohc_abbrev_all_dates_driver()
{
    ohc_protect_dates();
    ohc_abbrev_ref_dates();
    ohc_abbrev_all_dates();
    ohc_unprotect_dates();
    ohc_abbrev_edit_summary();
}

$(function () {
    if(document.forms.editform) {
        mw.util.addPortletLink('p-tb', 'javascript:ohc_all_to_dmy_driver()', 'ALL dates to dmy', 'ca-unitfixer', 'Align all dates to dmy', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_all_to_mdy_driver()', 'ALL dates to mdy', 'ca-unitfixer', 'Align all dates to mdy', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_body_to_dmy_driver()', 'Body dates to dmy', 't-dmy', 'day month', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_body_to_mdy_driver()', 'Body dates to mdy', 't-mdy', 'month day', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_ISO_to_dmy_driver()', 'ISO to dmy', 't-ISOdmy', 'ISO day month', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_ISO_to_mdy_driver()', 'ISO to mdy', 't-ISOmdy', 'ISO month day', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_delink_year_in_X_driver()'  , 'Del year-in-X dates', 't-yearinX',  'Year in X', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_expand_ref_dates_driver()', 'Expand ref dates', 't-expand', 'Expand month names within refs', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_expand_all_dates_driver()', 'Expand all dates', 't-expand', 'Expand month names throughout', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_abbrev_ref_dates_driver()', 'Abbrev ref dates', 't-expand', 'Abbreviate month names within refs', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_abbrev_all_dates_driver()', 'Abbrev all dates', 't-expand', 'Abbreviate month names throughout', '', '');
//      mw.util.addPortletLink('p-tb', 'javascript:ohc_unambiguous_dates_driver()', 'unambiguous dates', 't-slash', 'resolves slash date format', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_US_slash_dates_driver()', 'US-slash dates', 't-US', 'US-slash', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ohc_UK_slash_dates_driver()', 'UK-slash dates', 't-UK', 'UK-slash', '', '');
    }
});

/* </syntaxhighlight> */