Jump to content

User:Ryan Vesey/mosnum 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.
// <nowiki>
// 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

/**
 * 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:Ohconfucius/script/MOSNUM_utils.js");  

function ohc_fix_unambiguous_dates()
{
    // resolvable ambiguous date formats
    regex(/((?:at|from|till):\s*)(\d\d)/gi, '$1♫$2'); //protect for timeline

    // UK style
    ohc_regex(/(\D[^\w\/-:♫])@DD[\/\.]@MM[\/\.]@YYNN(?=[^\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[\/\.]@YYNN(?=[^\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(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi, '$1$2$3');
    regex(/\[\[([12]\d{3}|\d{1,3})\]\]/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 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\d])/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]\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]\D)/gi, '$1@LMonth @DD');
    ohc_regex(/(\W)@Month(?:_|&nbsp;)(?:the\s)?@DD<sup>@th<\/sup>(?=[^\]\|\w\d]\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(/(\|[ ]*author[ ]*=[ ]*)@month @day, @yyyy\s?\|/gi, "|");
    ohc_regex(/(\|[ ]*author[ ]*=[ ]*)@day @month @yyyy\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)@DD\s@Month(?:\s*[-–]\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(?:(?:&nbsp;|\s)?(?:[-–—]|&ndash;)(?:&nbsp;|\s)?)@DD\s@Month,? @Year(?=\D\W)/gi, "$1@Day1 @LMonth1 @Year1 – @Day2 @LMonth2 @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 – @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");

    //remove leading zero from 'Retrieved' date
    ohc_regex(/(?:Retrieved|Accessed)(?: on |:? )@Month\s@ZD,?\s@YYYY/gi, "Retrieved @LMonth @Day, @YYYY");
    ohc_regex(/(?:Retrieved|Accessed)(?: on |:? )@ZD\s@Month\s@YYYY/gi, "Retrieved @Day @LMonth @YYYY");

    ohc_regex(/(?:Retrieved|Accessed)(?: on |:? )@Month\s@ZD,?/gi, "Retrieved @LMonth @Day");
    ohc_regex(/(?:Retrieved|Accessed)(?: on |:? )@ZD\s@Month/gi, "Retrieved @Day @LMonth");

    // spaces and commas between month and year (again)
    ohc_regex(/@Month(?:,\s+|\s+of\s+)@YYYY(\w)/gi, "@LMonth @YYYY$1");

    // "|date=" to "|year"
    regex(/\|\s?date\s?=\s?(\d{4}\s?[\|\}])/gi, "|year=$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");
}

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([^\w\/\-%,<]*?<\/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()
{
    regex(/(\|[ ]*accessdate[ ]*=)[ ]*(\w)/gi, '$1$2');
    ohc_ISO_to_dmy_in_citations();
    ohc_ISO_to_dmy_in_references();
    regex(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Day @Month @Year$2');
}
 
function ohc_delink_ISO_to_mdy()
{ 
    regex(/(\|[ ]*accessdate[ ]*=)[ ]*(\w)/gi, '$1$2');
    ohc_ISO_to_mdy_in_citations();
    ohc_ISO_to_mdy_in_references();
    regex(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '$1@Month @Day, @Year$2');
}

function ohc_delink_year_in_X()
{
    ohc_regex(/{{(?:avyear|by|baseball\syear|fy|ly|mlb\syear|scy|sdy)\|(@year)}}/gi, "$1");
    ohc_regex(/{{(?:avyear|by|baseball\syear|fy|ly|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)
{
    // dts - format=dmy in this case (per D12000)
    // per {{dts}} doc, remove the obsolete link=off param
    regex(/(\{\{dts[^}]*)(?:\|link=off)/gi, '$1');
    // clean up existing format...
    regex(/(\{\{dts[^}]*)(?:\|format=(dmy|mdy))/gi, '$1');
    // then ensure format=dmy is applied if year is first
    regex(/(\{\{dts[^|]*\|)(?=\d{4}[-\|])/gi, '$1format=' + format + '|');
}

// 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 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?(?:[-–]|&ndash;)\s?|(?:[ _]|&nbsp;)(?:and|&|to|or)(?:[ _]|&nbsp;)+?)@Day,?\s(?:of\s)?(@yyyy\W\D)/gi, "$1$2$3@Day @LMonth $4");
    ohc_regex(/(\D\W)@Month((?:\s@day?,?){1,6}),?(\/|\s?(?:[-–]|&ndash;)\s?|(?:[ _]|&nbsp;)(?:and|&|to|or)(?:[ _]|&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");

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

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,");
    //rem superfluous comma where applicable
    ohc_regex(/(\D[^\w\/])@Month\s@ZD,,(?=\W\D|\b)/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;
    });
}
//not currently used
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([^\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([^\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([^\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([^\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_dmy_publication_dates()
{
    ohc_regex(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\W\D)/gi, "$1@Day @Month @YYYY");
}

function ohc_mdy_publication_dates()
{
    ohc_regex(/(\|[ ]*(?:date|archivedate)[ ]*=[ ]*)(?:\[\[)?@YYYY(?:\]\][-–]\[\[|[-–])@MM[-–]@DD(?:\]\])?(?=\W\D)/gi, "$1@Month @Day, @YYYY");
}

/** ------------------------------------------------------------------------ **/
/// 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;
    }
}
/** ------------------------------------------------------------------------ **/
/// 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>)(.*?)(<\/blockquote>)/gi, protect_function);
    regex(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/((?:file|image\d?|image location\d?|img|pic|title|quote|journal|url|work|doi)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
    regex(/((?:file|image\d?|image location\d?|img|pic|title|quote|journal|url|work|doi)\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 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 links
    regex(/(\[\[)(4AD)(.)/gi, protect_function);
    regex(/(.)(March (?:8|14) Alliance)(.)/gi, protect_function);
    regex(/(.)(23rd March 1931: Shaheed)(.)/gi, protect_function);
    regex(/(.)(Long March [1-7])(.)/gi, protect_function);
    regex(/(.)(movement 2 June)(.)/gi, protect_function);
    regex(/(.)(6th\sof October City)(.)/gi, protect_function);
    regex(/(.)(Party Workers' Liberation Front 30th of May)(.)/gi, protect_function);
    regex(/(.)(4th\sof August regime)(.)/gi, protect_function);
    regex(/(.)(19th\sof April movement)(.)/gi, protect_function);
    regex(/(.)(June 4th incident)(.)/gi, protect_function);
    regex(/(.)(July 31st \(film\))(.)/gi, protect_function);
    regex(/(\[\[)(13 May incident)(\|)/gi, protect_function);
    regex(/(\[\[)(November 1828)(\]\])/gi, protect_function);
    regex(/(\[\[)(4th\sof July)(.)/gi, protect_function);
    regex(/(\[\[)((?:2300|2000)\s?AD)(\]\])/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;
    });
}

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_ISO_to_dmy_in_citations();

    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_ISO_to_mdy_in_citations();

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