User:Ohconfucius/test/YMD dot dates.js

In this article, we will explore the impact of User:Ohconfucius/test/YMD dot dates.js in various areas of daily life. From its influence on technology to its role in society, User:Ohconfucius/test/YMD dot dates.js has become a topic of increasing relevance in the contemporary world. Through in-depth analysis, we will examine how User:Ohconfucius/test/YMD dot dates.js has shaped the way we interact with the world around us, as well as the implications it has for the future. From its origins to its presence today, this article seeks to shed light on the crucial role User:Ohconfucius/test/YMD dot dates.js plays in our daily lives, and how its influence will continue to shape our present and future.
// *********************************************************************************************

//This is a test (non-production) script, and may have untested errors. Please exercise due care should you decide to use it.

// *********************************************************************************************

// This script aligns dates in the format YYYY.MM.DD or YYYY/MM/DD into abbreviated dmy format allowed by ].

// Feedback and constructive criticism are welcome

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.orghttps://wikifreehand.com/en/TemplateScript
 * @update-token ]
 */
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');

importScript("User:Ohconfucius/script/MOSNUM_utils.js"); 
// <pre>

function ohc_dot_dates_to_dmy()
{
//ranges
	ohc_regex(/()@YYYY\/@MM\/@DD(&nbsp;|\s)?(?:(?:|&dash;)(?:&nbsp;|\s)?)@YYYY\/@MM\/@DD(?=)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
	ohc_regex(/()@YYYY\.@MM\.@DD(&nbsp;|\s)?(?:(?:|&dash;)(?:&nbsp;|\s)?)@YYYY\.@MM\.@DD(?=)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
	ohc_regex(/(\| ?)@YYYY\/@MM\/@DD(&nbsp;|\s)?(?:(?:|&dash;)(?:&nbsp;|\s)?)@YYYY\/@MM\/@DD(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");
	ohc_regex(/(\| ?)@YYYY\.@MM\.@DD(&nbsp;|\s)?(?:(?:|&dash;)(?:&nbsp;|\s)?)@YYYY\.@MM\.@DD(?=\s*\|)/gi, "$1@Day1 @Mon1 @Year1$2 – @Day2 @Mon2 @Year2");

// resolvable ambiguous date formats
	ohc_regex(/()@YYYY\/@MM\/@DD(?=)/gi, '$1@Day @Mon @YYYY');
	ohc_regex(/()@YYYY\.@MM\.@DD(?=)/gi, '$1@Day @Mon @YYYY');
	ohc_regex(/()@DD@MM@YYNN(?=)/gi, '$1@Day @Mon @YYYY');
	ohc_regex(/(\| ?)@YYYY\/@MM\/@DD(?=\s*\|)/gi, '$1@Day @Mon @YYYY');
	ohc_regex(/(\| ?)@YYYY\.@MM\.@DD(?=\s*\|)/gi, '$1@Day @Mon @YYYY');
//	ohc_regex(/(\| ?)@DD@MM@YYNN(?=\s*\|)/gi, '$1@Day @Mon @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;
	};
//\|x=
	regex(/(<timeline>)(*?)(<\/timeline>)/gi, protect_function);
	regex(/(<math>)(*?)(<\/math>)/gi, protect_function);
	regex(/((?:{(?:Wikimedia |)Commons ?|C ?))(Cat(?:egory|))\|(})/gi, protect_function);
	regex(/(<ref)(+)(>)/gi, protect_function);
	regex(/((?:Category|Image|File):)(]*)(])/gi, protect_function);
	regex(/(\{(?:See ?also|Main))(\|*)(\})/gi, protect_function);
	regex(/(\{\{(?:double ?|external ?|wide ?)image\s?\|)(+)(\})/gi, protect_function);
	regex(/(\{\{(?:harvnb|r|wikisource)\|)(+)(\})/gi, protect_function);
	regex(/(\]*)(\])/gi, protect_function);
	regex(/(>*(?:https?:|ftp:))(]*)(*<)/gi, protect_function);
//	regex(/(https?:|ftp:)(]*)(])/gi, protect_function);
	regex(/(<blockquote>)(*?)(<\/blockquote>)/gi, protect_function);
	regex(/(<noinclude>)(*?)(<\/noinclude>)/gi, protect_function);
	regex(/(<gallery)(*?)(<\/gallery>)/gi, protect_function);
	regex(/(<poem>)(*?)(<\/poem>)/gi, protect_function);
	regex(/(\{{0,6}(?:quot{1,7}\s?|sic)\|)(+)(\})/gi, protect_function);
	regex(/((?:image\d?|image_skyline|imagelocation\d?|imagename|imagefile|img|pic)\s*=)(*)()/gi, protect_function);
	regex(/(\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)(*)()/gi, protect_function);
	regex(/(\s*(?:file(?:name\d?|)|image\d?|image location\d?|img|pic|Cover|(?:trans-?|)title|quote|chapter|journal|url|archiveurl|work|doi|club|at|volume|reporter)\s*=)(*)()/gi, protect_function);
	regex(/(\s*(?:season)\s*=)(\s*\]*\]\]\s*)()/gi, protect_function);
	regex(/(\s*(?:)\s*=)(\s*+\s*)(\|)/gi, protect_function);
	regex(/(\{\{navsource\|)(+)(\})/gi, protect_function);
	regex(/(\{\{(?:singlechart)\|)(+)(\})/gi, protect_function);
	regex(/(\{\{(?:defaultsort|graph):)(+)(\})/gi, protect_function);
	regex(/()(*)()/gi, protect_function);


	// works names
//	regex(/(.)(protect string)(.)/gi, protect_function);
	regex(/(.)(11\/22\/63)(.)/gi, protect_function);
	regex(/(.)(1\.1\.1994)(.)/gi, protect_function);
	regex(/()(2\.13\.61)()/gi, protect_function);
//	regex(/(.)(4th of July, Asbury)(.)/gi, protect_function); //protected above globally

	
}


function ohc_unprotect_dates()
{

	//unprotect all dates
	regex(//g, '');
	regex(/⍌(+)⍍/g, function(x, n) {
		var res = linkmap;
		res = res.replace(/⍌(+)⍍/g, function(x, n) {
			var res = linkmap;
			res = res.replace(/⍌(+)⍍/g, function(x, n) {
				var res = linkmap;
				res = res.replace(/⍌(+)⍍/g, function(x, n) {
					return linkmap;
				});
				return res;
			});
			return res;
		});
		return res;
	});
}


function ohc_dot_edit_summary()
{
	//Add a tag to the summary box
	setoptions(minor='true');
	setreason('resolved ]', 'append');
	doaction('diff');
}

function ohc_dot_dates(){
// Add a tag to the summary box
 var txt=document.editform.wpTextbox1;
	ohc_protect_dates();
	ohc_dot_dates_to_dmy();
	ohc_unprotect_dates();
	ohc_dot_edit_summary();
}

$(function () {
 if(document.forms.editform) {
   mw.util.addPortletLink('p-tb', 'javascript:ohc_dot_dates()', 'DOT to dmy dates', 't-UK', 'UK-dot', '', '');

  }
});

// </pre>