User:Ohconfucius/script/protect.js

/** **/ /// DATE PROTECTION lighter protection than for dates or mosnum script designed to protect only the truly immutable strings: var linkmap=[]; function ohc_protect_basic {	// 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(/((?:image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic)\s*=)([^\|\}]*)([\|\}])/gi, protect_function); regex(/((?:file|pic|title|quote|journal|url|work|doi)\s*=)([^\|\}]*)([\|\}])/gi, protect_function); regex(/((?:[a-z]{2,3}):)([^|\]]*)([\|\]])/gi, protect_function); //interwikis

//protects certain links //	regex(/(.)(string to protect)(.)/gi, protect_function);

}

function ohc_unprotect_basic {	//unprotect all dates 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;	}); }