User:Ohconfucius/test/MOSNUM dates.js: Difference between revisions

Content deleted Content added
tweak centuries
fully protect archive-url with built-in spacces
 
(45 intermediate revisions by the same user not shown)
Line 30:
script: ohc_all_to_mdy_driver
},
/*{
name: "Expand ref datesDMY_cs1=ly",
tooltip: "ExpandAccess month& namesarchive within refsdates",
script: ohc_expand_ref_dates_driverohc_dmy_cs1_ly_driver
},
{
name: "Expand all datesMDY_cs1=ly",
tooltip: "Expandsay month names throughouthello",
script: ohc_expand_all_dates_driverohc_mdy_cs1_ly_driver
},*/
{
name: "US-slash dates",
Line 211:
.replace(/\[\[(\d{1,3}0)\'?s\]\]/g, "$1s")
.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, "$1")
// .replace(/\[\[(\d{2,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")
 
Line 236 ⟶ 232:
// Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
.ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth")
// .ohc_regex(/\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, "@Year") //disable easter egg removal per request 5 November 2022
 
// month and day piped
Line 285 ⟶ 281:
 
// remove parasitic metadata - days of the week/descriptives
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:[^|}\d]*|)@Day\s+@Month\s+@YYYY((?:[a-z]\b|)\s(?):[^|<}\w\d]*{2,}|)(?=[\s\n]*[<|}])/gi, "$1@Day @Month @YYYY$2") // rem negate "<", "hyphens" "dashes" 26/6/2020
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)[^|}]*@Month\s+@Day,\s+@YYYY((?:[a-z]\b|)\s(?):[^|<}\w\d]*{2,}|)(?=[\s\n]*[<|}])/gi, "$1@Month @Day, @YYYY$2") // rem negate "<", "hyphens" "dashes" 26/6/2020; rem ([^|<}]*) false positive for \n
//.ohc_regex(/(\|\s*date\s*=\s*)(?:[^|}–<]*\D|)@Day\s+@Month\s+@YYYY ?– ?@Day\s+@Month\s+@YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Day1 @Mon1 @Year1 – @Day2 @Mon2 @Year2")
//.ohc_regex(/(\|\s*date\s*=\s*)[^|}–<]*@Month\s+@Day,\s+@YYYY ?– ?@Month @Day, @YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Mon1 @Day1, @Year1 – @@Mon2 Day2, @Year2")
Line 349 ⟶ 345:
 
// add back spaces or comma or remove other single artefact after date string
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Day\s{,2}@Month\s{,2}@YYYY[^a-z{}]?\b(?=[\s\n]*[<|}\n])/gi, "$1@Day @Month @YYYY$2")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:on |)@Month\s{,2}@Day,?\s{,2}@YYYY[^a-z{}]?\b(?=[\s\n]*[<|}\n])/gi, "$1@Month @Day, @YYYY$2")
 
// long-hand palliative for observed failure to insert spaces
.ohc_regex(/(\|\s*(?:archive|access|air)-?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<>]*b(?=\s*[|}])/gi, "$1$2 $3 $4")
//.ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)(?:on |)@Day\s*@Month\s*@YYYY([a-z]\s?|\s?)\w*[^|{}<>]*(?=[|}])/gi, "$1@Day @Month @YYYY$2")
//.ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)(?:on |)@Month\s*@Day,\s*@YYYY([a-z]\s?|\s?)\w*[^|{}<>]*(?=[|}])/gi, "$1@Month @Day, @YYYY$2")
 
// remove extraneous bracket //from Batty
Line 460 ⟶ 454:
.ohc_regex(/([ =|])@DD\.@MM\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @MM @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=[\s\n]*[<|}\n])/gi, "$1@Day @Month @YYYY")
 
//convert yyyy-dd-mm to yyyy-mm-dd
Line 529 ⟶ 523:
editor
// ISO dates within single citation
//.ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY"); //regex which converts ymd to dmy or mdy throughout (within citation templates)
.ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY");
}
 
Line 536 ⟶ 529:
editor
// ISO dates within single citation
//.ohc_regex(/(\|\s*(?:publication|archive|access|air|designation\d?_|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY"); //regex which converts ymd to dmy or mdy throughout (within citation templates)
.ohc_regex(/(\|\s*(?:publication|)-?date\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY");
}
 
Line 552 ⟶ 544:
.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(editor) {
editor
// 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(editor) {
editor
// 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");
}
 
Line 669 ⟶ 643:
 
//remove comma
.ohc_regex(/(\D\W)@Day\s@Month,\s?@YearYYYY(?=\W\D)/gi, "$1@Day @LMonth @YearYYYY")
 
// remove "the" from "on the dd month"
Line 810 ⟶ 784:
}
 
function ohc_Bigendian_ref_datesohc_refs_to_yyyymmdd(editor) {
editor
// Add a tag to the summary box
.ohc_regex(/(\|\s*(?:archive|access)-?date\s*=\s*)@Day @Month @YYYY/gi, "$1@YYYY-@MM-@DD") // conversion of dmy dates to ymd within citation templates
.replace(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\|[^\}\|]+\}\})/gi, "$1|cs1-dates=y$2");
.ohc_regex(/(\|\s*(?:archive|access)-?date\s*=\s*)@Month @Day, @YYYY/gi, "$1@YYYY-@MM-@DD") // conversion of mdy dates to ymd within citation templates
.replace(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\s*\|date=[^\}\|]+)(?=\}\})/gi, "$1$2|cs1-dates=y$2ly");
}
 
Line 930 ⟶ 906:
.replace(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:Single chart|harvnb|r|wikisource)\|)([^}]+)(\})/gi, protect_function)
.replace(/(\{\{(?:About-distinguish-text)\s*\|)([^}]+)(\}\})/gi, protect_function)
.replace(/(\{\{(?:Canadian federal by-election))([^}]+)(\}\})/gi, protect_function)
 
.replace(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function)
.replace(/(>[ ]*(?:https?:|ftp:))([^< >\]]*)([ ]*<)/gi, protect_function)
.replace(/(\|\s*archive-?url\s*=\s*https?:|ftp:)([^\s\|]*)(\s?\|)/gi, protect_function) //repurposed unused line to protect archive url links (archive.today)
.replace(/(<blockquote>)([\s\S]*?)(<\/blockquote>)/gi, protect_function)
.replace(/(<noinclude>)([\s\S]*?)(<\/noinclude>)/gi, protect_function)
Line 1,297 ⟶ 1,274:
}
 
function ohc_dmy_publication_dates_driverohc_dmy_cs1_ly_driver(editor) {
ohc_extend_editor(editor);
 
//ohc_delink_dates(editor);
ohc_protect_dates(editor);
ohc_fix_unambiguous_dates(editor);
ohc_body_dates_to_dmy(editor);
ohc_customize_body_to_dmyohc_delink_ISO_to_dmy(editor);
ohc_dmy_publication_dates//ohc_delink_year_in_X(editor);
ohc_customize_all_to_dmy(editor);
ohc_ISO_to_dmy_in_citations(editor);
ohc_unprotect_dates(editor);
ohc_refs_to_yyyymmdd(editor);
ohc_MOSNUM_edit_summary(editor);
 
function ohc_ISO_to_dmy_anywhereohc_mdy_cs1_ly_driver(editor) {
ohc_extend_editor(editor);
 
ohc_delink_dates(editor);
ohc_protect_dates(editor);
ohc_fix_unambiguous_dates(editor);
ohc_body_dates_to_mdy(editor);
ohc_delink_ISO_to_mdy(editor);
//ohc_delink_year_in_X(editor);
ohc_customize_all_to_mdy();
ohc_ISO_to_mdy_in_citations(editor);
ohc_unprotect_dates(editor);
ohc_refs_to_yyyymmdd(editor);
ohc_MOSNUM_edit_summary(editor);
 
function ohc_ISO_to_mdy_anywhereohc_bigendian_driver(editor) {
ohc_refs_to_yyyymmdd(editor);
 
ohc_bigendien_edit_summary(editor);
}
 
function ohc_dmy_publication_dates_driver(editor) {
ohc_dmy_publication_dates(editor);
 
ohc_MOSNUM_edit_summary(editor);
Line 1,347 ⟶ 1,355:
ohc_MOSNUM_edit_summary(editor);
}
//is this being used at all?
 
function ohc_ISO_to_dmy_driver(editor) {
ohc_extend_editor(editor);
Line 1,358 ⟶ 1,366:
//ohc_MOSNUM_edit_summary(editor);
}
//is this being used at all?
 
function ohc_ISO_to_mdy_driver(editor) {
ohc_extend_editor(editor);
Line 1,369 ⟶ 1,377:
//ohc_MOSNUM_edit_summary(editor);
}
//is this being used at all?
 
function ohc_delink_year_in_X_driver(editor) {
ohc_extend_editor(editor);
Line 1,375 ⟶ 1,383:
ohc_delink_year_in_X(editor);
}
//is this being used at all?
 
function ohc_expand_ref_dates_driver(editor) {
ohc_extend_editor(editor);
Line 1,384 ⟶ 1,392:
ohc_expand_edit_summary(editor);
}
//is this being used at all?
 
function ohc_expand_all_dates_driver(editor) {
ohc_extend_editor(editor);