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

Content deleted Content added
partial alignment to test script
align function ohc_delink_dates
Line 105:
{
//add missing space between wikilinks
regex(/(\]\])(\[\[)(?!file:)/gi, '$1 $2'); //remove (?!file:) to ensure a space between all links
// rem redundant quote marks and parentheses
Line 113:
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\(([^|}\[\]]*)\)(?=\s*[|}])/gi, "$1$2");
 
//delink fullunpiped dates
//rem linking date parameters
//delink yyyy-mm-ddfull dates
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\[\[([^|\]]+?)\]\](?=\s*[|}])/gi, '$1$2');
regexohc_regex(/(\|[\[@Day[\s*s_](?:publication|archive|access|air|of[\s_])-?date@Month(?:\s*=]\]\s*)?\[\[[^|\]]+?\|([^\]]+? )@YYYY\]\](?=\s*[|}])/gi, '$1$2'"@Day @LMonth @YYYY");
ohc_regex(/\[\[@Month (?:the\s)?@Day(?:\]\],? \[\[|, )@YYYY\]\]/gi, "@LMonth @Day, @YYYY");
regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\]([^|\[]*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\](?:([^|\[]*)\[\[(?:[^|\]]+?\||)([^\]]+?)\]\]|)(?=\s*[|}])/gi, '$1$2$3$4$5$6');
 
//delink yyyy-mm-dd dates
ohc_regex(/\[\[@YYYY(?:\]\]-\[\[|-)@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
ohc_regex(/@YYYY-\[\[@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
 
//underscore and nbsp in linked dates
Line 128 ⟶ 132:
ohc_regex(/\[\[@Month(?:[ _]| )@ZD@th\]\]/gi, "@LMonth @Day");
ohc_regex(/\[\[@ZD@th(?:[ _]| )@Month\]\]/gi, "@Day @LMonth");
//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
Line 137:
ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi, '$1@LMonth @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
regex(/\[\[(\{\{CURRENTDAY\}\} \{\{CURRENTMONTHNAME\}\})\]\]/gi, "$1");
regex(/\[\[(\{\{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@th?[\s_](?:of[\s_])?@Month\]\]/gi, "@Day @LMonth");
Line 154 ⟶ 142:
ohc_regex(/\[\[@Month[\s_](?:the[\s_])?@Day@th?\]\](?=\W)/gi, "@LMonth @Day");
 
//month+day piped
//Month+day_number "[[March 7]]th" -> "March 7"
ohc_regex(/\[\[(?:@Month\sdd@DDth?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|((?:@month |)@day)@th?\]\]/gi, "@LMonth @Day$1");
ohc_regex(/(?:the\s)?\[\[(?:@daydd@th?[\s_](?:of[\s_])?@month|@month[\s_]@dd@th?)\|(@Day@th?[^\s_]]{1,30}(@month|)\]\]/gi, "@Day $1");
 
// ohc_regex(/\[\[@month @yyyydd(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1");
// ohc_regex(/\[\[@dd @month(?:#[^|]+|)\|([^|\]]+)@th?\]\]/gi, "$1");
ohc_regex(/\[\[@month @ddyyyy(?:#[^|]+|)\|([^|\]]+)\]\]/gi, "$1");
 
//month+day+year pseudo-ISO dates
ohc_regex(/(\[\[@Month @DD\|\s*d\d-\d\d\]\]-(?:publication|archive|access|air|\[\[)-?date\s(?:@yyyy[^|]*=\s*@dd|)-@Mon-?@YYYY(?:\]\])/gi, "$1@Day @FullMonthLMonth @YYYY");
ohc_regex(/(\|[\[@DD\s*@Month\|\d\d-\d\d\]\]-(?:publication|archive|access|air|\[\[)-?date\s(?:@yyyy[^|]*=\s*|)?@YYYY-@DD-@Mon(?:\]\])/gi, "$1 @DDDay @FullMonthLMonth @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'
Line 172 ⟶ 159:
ohc_regex(/\[\[@Day\s@Month\|@dd.@dd\]\].@YYYY/gi, "@Day @LMonth @YYYY");
 
// century
regex(/\[\[((?: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');
regex(/\[\[(?: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');
regex(/\[\[(\d{1,2}(?:st|[nr]d|th))[\s\-_])(centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi, '$1 $2$3');
ohc_regex(/\[\[\d{1,2}@th[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi, '$1');
 
Line 205 ⟶ 192:
 
ohc_regex(/(\[\[@yyyy[^|\]]+\|@yyyy)(\]\])( season)/gi, "$1$3$2");
ohc_regex(/@Month\s\[\[@yyyy[^|\]]+\|@YYYY\]\]/gi, "@LMonth @Year");
ohc_regex(/(\[\[The Who[^|\]]+\|@YYNN)(\]\])/gi, "@YYNN"); //The Who tours
 
//removed piped years when in full date (excepting disambiguated parentheses - updated 24/2/2012)
// ohc_regex(/\[\[@DD\s@Month\]\],?\s?\[\[[^|\]\(\)]{1,32}\|@YearYYYY\]\]/gi, '@DD @LMonth @Year'); // 23/6/2021 – disabled delinking "other" year-in articles
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.
Line 514 ⟶ 498:
//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");
}
Line 522 ⟶ 505:
//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");
}
Line 838 ⟶ 820:
//\|x=
regex(/(<timeline>)([\s\S]*?)(<\/timeline>)/gi, protect_function);
regex(/(<!--)([^<\{\}]*?)(-->)/gi, protect_function);
regex(/(<math>)([\s\S]*?)(<\/math>)/gi, protect_function);
regex(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|[^{}*](})/gi, protect_function);
Line 866 ⟶ 849:
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}[-–]\{\{by\|)([12]\d{3}[ ]*\}\}\))/gi, protect_function);
regex(/(.)(\(\{\{by\|[12]\d{3}\}\}(?:[-–]present|))(\))/gi, protect_function);
regex(/(\[\[)(4AD)(\]\]|\|)/gi, protect_function);
 
//retraining redirects containing a date