ব্যবহারকারী:Sajidmahamud835/script/formatgeneral.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য
বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
রচনাশৈলী/বিন্যাসন ত্রুটি ঠিককরণ |
সম্পাদনা সারাংশ নেই |
||
২২৩ নং লাইন: | ২২৩ নং লাইন: | ||
/** ------------------------------------------------------------------------ **/ |
/** ------------------------------------------------------------------------ **/ |
||
/// PROTECTION BY STRING SUBSTITUTION |
/// PROTECTION BY STRING SUBSTITUTION |
||
/** |
|||
var linkmap=[]; |
var linkmap=[]; |
||
function ohc_downcase_CEO() |
function ohc_downcase_CEO() |
||
২৯৮ নং লাইন: | ২৯৮ নং লাইন: | ||
} |
} |
||
/** ------------------------------------------------------------------------ |
/** ------------------------------------------------------------------------ |
||
/// LINKSPAM removal with protection for Reference tags and External links |
/// LINKSPAM removal with protection for Reference tags and External links |
||
৩৯৯ নং লাইন: | ৩৯৯ নং লাইন: | ||
} |
} |
||
/** ----------------------------------------------------------------------- |
/** ----------------------------------------------------------------------- |
||
/// PROTECTION BY STRING SUBSTITUTION |
/// PROTECTION BY STRING SUBSTITUTION |
||
০৯:৪৫, ২৬ ডিসেম্বর ২০১৬ তারিখে সংশোধিত সংস্করণ
/**
* [[en:User:Ohconfucius/script/formatgeneral.js]]
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
* @see https://meta.wikimedia.org/wiki/TemplateScript
* @update-token [[File:pathoschild/templatescript.js]]
*/
function Ohc_format_Sundry() {
var txt=document.editform.wpTextbox1;
regex(/<br>/gi, '<br/>');
regex(/(\d)(<sup>)(m)(\d<\/sup>)/gi, '$1$3$2$4'); //misplaced unit (squared)
regex(/(\d)(?:<(?:small|sup)>){2}(th|st|nd|rd)(?:<\/(?:small|sup)>){2}/gi, '$1$2');
regex(/(\d)<(?:small|sup)>(th|st|nd|rd)(?:<\/(?:small|sup)>|<(?:small|sup)\/>)/gi, '$1$2');
//rem linking within section headings
regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');
// regex(/(==[ ]?)\d{1,2}px([^\|\]]+?)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3'); //rem artefact after removing file from title
//rem refs within section headings
regex(/(==[ ]?(?:[^<>\n]*))(?:<ref(?:>[^<>]*<\/ref| name=[^\/>]+\/)>)([^<>\n]*)(?=[ ]?==)/gi, '$1$2');
//rem linking within persondata fields
regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)(?=[\n}])/g, '$1$2$3');
regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)/g, '$1$2$3$4$5');
regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)/g, '$1$2$3$4$5'); //repeat to catch further linking
regex(/((?:SHORT DESCRIPTION|(?:DATE|PLACE) OF (?:BIRTH|DEATH)[ ]*=[ ]*)(?:[^\[\]\n]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\]\n}]*)(?=[\n}])/g, '$1$2$3'); //repeat to catch further linking (single)
//rem empty parameters
regex(/\|[\n]*[ ]*[a-zA-Z][a-z0-9_ ]*=[ ]*[\n]?[ ]*(?=[\|\}])/g, "");
//rem deprecated parameters
// regex(/\|\s*influence[sd]\s*=[^\|\{\}]*(?=[\|\}])/g, ""); //rfc infobox person July 2013; code fails if there are piped links
//add correct hyphenation
regex(/\b([2-9]|\d{2,3}|half|quarter|two|three|four|five|six|seven|eight|nine|ten) (second|minute|hour|day|week|month|year|decade|fold|liter|litre|degree|inch|foot|yard|mile|meter|metre|man|page|point|word|dollar|cent|floor|store?y|(?:bed|)room)\b/g, "$1-$2");
regex(/\b([2-9]|\d{2,3}|two|three|four|five|six|seven|eight|nine|ten)-(second[- ]class)\b/g, "$1 $2"); //palliative to reverse incorrectly inserted hyphen "n-second-class"
regex(/\b(two|three|four|five|six|seven|eight|nine|ten) (halves|thirds|quarters|(?:four|fif|six|seven|eigh|nin|ten)ths)\b/gi, "$1-$2");
regex(/\b((?:[2-9]|\d{2,3})-(?:month|year)) (old)\b/gi, "$1-$2");
regex(/(\bnon) ([A-Z]?[a-z]+)/g, "$1-$2");
regex(/(\bnon)-(grata)/g, "$1 $2"); //reinstate for "persona non grata"
regex(/(qua non)-([A-Z])/gi, "$1 $2"); //reinstate for "sine qua non"
regex(/(?:\| ?date= ?)(Cric\w{4,})(?=[|}])/gi, "|publisher=$1");
regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3$4");
regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?(?:box|sample)\s?\|#?\w+}}\s?([^{]*){{color ?(?:box|sample)\s?\|#?\w+}}([^{|]*)(?=\n?[|}])/gi, "$1$2$3");
regex(/(\|\s*colou?rs\s*=\s*[^{]*){{color ?sample\s?\|#?\w+}}([^{|]*)(?=\n?[|{}])/gi, "$1$2");
}
function Ohc_format_MOSFLAG(){
//remove flagicons from country, birth and death
regex(/((?:birth|death|place|captain|chairman|club|coach|manager|headquarters|citizenship|nationality|occupation|origin|party|stadium)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]\]\] ?)/gi, '$1');
regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flag(?:country|u|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
regex(/((?:(?:birth|death)(?:_?place|)|citizenship|residence|nationality)\s*=\s*)(?:\{\{flag ?icon\|[^{}]+(?:\|[^{}]+|)\}\} ?|\[\[(?:File|Image):Flag of [^\]]+\]\] ?)/gi, '$1$2');
// regex(/((?:country|location|nationality|residence)\s*=\s*)\{\{flagu?\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
// regex(/((?:country|location|nationality|residence)\s*=\s*)\{\{flag(?:country|)\|([^{}|]+)(?:\|[^{}]+|)\}\}/gi, '$1$2');
//strip bare facilities icons
regex(/\[\[(File|image):Feature (accessible|elevators|parking|suburban buses)\.svg\|\d\d?px(?:\|[^\]]+)?\]\]\s*/gi, '');
//remove scroll bar for reflists
regex(/(References ?={1,4}[\n\r])[\r\n\s]*<div class=[^>]*>([\S\s]*?)<\/div>/gi, '$1$2');
// regex(/((?:Notes ?|References ?)={2,4}\s?[\n\r])[\r\n\s]*(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/gi, '$1{{reflist|colwidth=30em}}');
}
function Ohc_format_MOSPUNCT(){
//rem redundant spaces underlining and punctuation
// regex(/([\s>()])[“„«](\[?\w+)/gi, '$1\"$2');
// regex(/(\w+\]?\.?)[”»](\W)/gi, '$1\"$2');
regex(/(।)[“„”«»](।)/gi, '$1\"$2');
// regex(/([\s>()])[‘`´’′](\[?\w+)/gi, '$1\'$2');
// regex(/(\w)[‘`´’′](s|t)\b/gi, '$1\'$2'); // in-word replacement of various single quotes and prime symbol with straight apostrophe
// regex(/(.)[‘`´’](.)/gi, '$1\'$2'); // straight apostrophe (won't touch prime symbol here)
regex(/([\w;,\]\)>] ) +([\[(]|[a-z\d])/gi, '$1$2'); //rem multiple spaces except when preceded by full stop; tweaked to not remove dbl spaces where preceded by new sentence (caps)
regex(/(^\.U\.)[ ]+((?:S|K)\.)/gi, '$1$2'); //U. S. and U. K. to U.S. and U.K.
regex(/(<\/?ref(?: name=[^<>\/]*?|)>)[ ,\.]*(<ref)/gi, '$1$2'); // remove punctuation between ref tags
regex(/[ ]{1,3}(<\/?ref(?:>| >| n))/gi, '$1'); // remove spaces and line feeds preceding ref tags and templates
// regex(/(<\/ref ?>|<ref name=[^>\/]+\/>)([^\s<])/gi, '$1 $2'); // add spaces after ref tags
// regex(/[ ]+(\n|\r)/gi, '$1'); //removes multiple spaces preceding line break
regex(/(\d), ([12]\d{3}\b)+/gi, '$1, $2'); //removes nbsp preceding year
regex(/(\d)(?: | )%/gi, '$1%'); //removes nbsp preceding '%'
regex(/( )[ ](–|–)/gi, '$1$2'); //Palliative for dashes script insertion of space after nbsp
regex(/( | )(?:—|—)( | )/gi, '$1–$2'); //Palliative for dashes script insertion of space after nbsp
// regex(/\b(US|UK|A(?:US|)|C(?:AN|)|NZ|HK) ([$£¥€])(\d)/g, '$1$2$3');
// regex(/([$£¥€]) (\d)/gi, '$1$2');
// regex(/(\{\{(?:INR|Indian Rupee)\}\}|Rs\.?)(\d+)/g, '$1 $2');
// regex(/\{\{AUD\}\} ?(\d+)/g, 'A$$1');
//rem 'external' wiktionary links
regex(/\[https?:\/\/bn\.wiktionary\.org\/wiki\/[\w]*[ ](\w[^\]]*)\]/gi, '$1');
regex(/\[https?:\/\/en\.wiktionary\.org\/wiki\/[\w]*[ ](\w[^\]]*)\]/gi, '$1');
//rem linked copyright symbol
regex(/(\[\[copyright\|©\]\] |©)/gi, '');
//rem leading and lagging spaces within wikilinks
regex(/(\[\[)[ ]+([^\[\]\|]*?)[ ]*(\]\])/gi, '$1$2$3');
regex(/(\[\[)[ ]*([^\[\]\|]*?)[ ]+(\]\])/gi, '$1$2$3');
regex(/(\[\[[^\[\]\|]*?[ ])[ ]+([^\[\]]*?\]\])/gi, '$1$2');
regex(/(\[\[[^\[\]\|]*?)[ ]+\|[ ]*([^\[\]]+\]\])/gi, '$1|$2');
// regex(/(\[\[[^\[\]\|]*?)[ ]*\|[ ]+([^\[\]]+\]\])/gi, '$1|$2'); //can't remember why we need the second (repeated) line
regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*(?:album|film|magazine|newspaper|song)\))(\]\])/gi, '[[$1$2|$1$3'); //adding piping to album|film|magazine dabbed by parentheticals
//symbol for 'times' and dashes
// regex(/×/gi, '×');
// regex(/([ \.][\d]+)x([\d]+(?:\.[\d]+|)\s)/gi, '$1 × $2'); //disabling - never ending false positives
regex(/(\d) x (\d )/gi, '$1 × $2');
regex(/\s(A[cglmrstu]|B[ahikrad]?|C[adeflmno]|D[bsyrsu]|E[rsu]|F[elmr]?|G[adef]|H[fgos]|I[nr]?|Kr?|L[aruv]|M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|S[bcegimnr]?|T[abcehilm]?|U[ub][neopst]|V|W|Xe|Yb?|Z[nr])-(Br|Cl?|F|H|I|N|O|P|Se?)\s/g, ' $1–$2 '); //signifying chemical bonds abbrev
// regex(/([^<][^!] *)--( *[^>])/gi, '$1–$2'); //disabling - causes false positives with urls and some images
regex(/—/gi, '—');
regex(/([\w\d]) — (?=[\w\d])/gi, '$1 – '); // tweak to avoid replacing emdashes in strings that are in non-roman unicode characters
regex(/(\D7\d7)–(\d(?:00|)\D)/gi, '$1-$2'); //airplane model numbers taking hyphen
//inserting a white space between wikilinks to avoid errors upon unlinking
regex(/(\]\][\.,]?)(\[\[)(?!file|image)/gi, '$1 $2');
//full stop and nbsp fixes
//protection for strings within wikilinks
// regex(/(\[(?:[^\|\]]*)\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})([ ]*(?:[cgkm])[^\|\]]*?[\|\]])/gi, '$1♭$2');
// regex(/(\[(?:[^\|\]]*)(?:\d?\d[:\.]\d?\d| \d?\d))([ ]*(?:[ap]\.m\.|[ap]m)[^\|\]]*?[\|\]])/gi, '$1♭$2');
//degrees and titles
// regex(/(Ph)(?:\.\s?|\s)(D)\.?/g, '$1$2');
// regex(/\b(B|M)(?:\.\s?|\s)(Arch|Comm|Ed|Eng|Sc|Tech)\.?(?=\W)/g, '$1$2');
// regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3$4]]');
// regex(/(\|[A-Z])\.\s?([A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2$3]]');
// regex(/(\|[A-Z])\.\s?([A-Z])\.?\]\]/g, '$1$2]]');
//times of day, time ranges
// regex(/((?:\d?\d[:\.]\d?\d| \d?\d) [ap])(?:\.m\.)(?=[^\w\-])/gi, '$1m');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:a\.m\.|am)(?:[ ]*| )[-–—](?:[ ]*| )(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*| )(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1 am – $2 pm');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:p\.m\.|pm)(?:[ ]*| )[-–—](?:[ ]*| )(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*| )(?:a\.m\.|am)(?=[^\w\-])/gi, '$1 pm – $2 am');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:a\.m\.|am)(?:[ ]*| )[-–—](?:[ ]*| )(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*| )(?:a\.m\.|am)(?=[^\w\-])/gi, '$1 am – $2 am');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:p\.m\.|pm)(?:[ ]*| )[-–—](?:[ ]*| )(\d?\d[:\.]\d?\d|\d?\d)(?:[ ]*| )(?:p\.m\.|pm)(?=[^\w\-])/gi, '$1 pm – $2 pm');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:a\.m\.|am)(?:[ ]*| )[-–—](?:[ ]*| )(noon|midnight)(?=[^\w\-])/gi, '$1 am – $2');
// regex(/(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:p\.m\.|pm)(?:[ ]*| )[-–—](?:[ ]*| )(noon|midnight)(?=[^\w\-])/gi, '$1 pm – $2');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:am|AM)(?=[^\w\-])/g, '$1 am');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:pm|PM)(?=[^\w\-])/g, '$1 pm');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Aa]\.[Mm]\.)(?=\S[^\w\-])/g, '$1 am');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Pp]\.[Mm]\.)(?=\S[^\w\-])/g, '$1 pm');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Aa]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1 am');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Pp]\.[Mm])(?=\.[\s\W][A-Z])/g, '$1 pm');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Aa]\.[Mm])(?=\.<)/g, '$1 am');
regex(/\b(\d?\d[:\.]\d?\d| \d?\d)(?:[ ]*| )(?:[Pp]\.[Mm])(?=\.<)/g, '$1 pm');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kw)\b/gi, '$1 kW');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:khz)\b/gi, '$1 kHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:mhz)\b/gi, '$1 MHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:ghz)\b/gi, '$1 GHz');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kph|kphr|kmh|kmhr|kmph|kmphr|km\/hr)\b/gi, '$1 km/h');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m\.p\.h\.)\b/gi, '$1 mph');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(gm|kg|km)s?\b/g, '$1 $2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KMs?\b/gi, '$1 km');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*KGs?\b/gi, '$1 kg');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/gi, '$1 k$2');
regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1 cm');
// regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1 $2illion$3');
regex(/(\d)(?: |\s)?C(entimet(?:er|re))/g, '$1 c$2');
regex(/(\d)(?: |\s)?K(ilomet(?:er|re))/g, '$1 k$2');
regex(/(\d)(?: |\s)?KM\b/g, '$1 km');
//turn letter 'x' into symbol '×'
regex(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in (');
regex(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');
// Convert degree symbols into ° symbol, ensure preceding space
regex(/°/g, '°');
// regex(/º/g, '°');
// Celsius spelling errors
// regex(/(?:celsius|celcius|centigrade)/gi, 'Celsius');
//Fix common naming error (be careful with this one)
// regex(/centigrade/gi, 'Celsius');
//Celsius or Fahrenheit
regex(/(\d) (?:[°º]|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
regex(/(\d)(?:[°º]|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
regex(/(\d) (?:[°º]|deg|degree|degrees)([CF]\W)/g, '$1 °$2');
regex(/(\d)(?:\s|)(?:[°º]|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1 °$2');
regex(/(\d)(?:\s| )?(?=\[\[Celsius\|[°º]C\]\])/gi, '$1 $2');
regex(/(\d)(?:\s| )?(?=\[\[Fahrenheit\|[°º]F\]\])/gi, '$1 $2');
regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)[°º]F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1{{convert|$2|°F|°C|abbr=on}}$3');
regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)(?:deg|degree|degrees)(?:\s|-| |)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1{{convert|$2|°F|°C}}$3');
// Convert &sup to superscript
// regex(/(m)(?:²|²);/gi, '$1<sup>2</sup>');
// regex(/(m)(?:³|³);/gi, '$1<sup>3</sup>');
//remove commas from numerical values in convert template
regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
regex(/(\{convert\|\d+),(\d)/gi, '$1$2');
//inappropriate unit pairs for convert template
regex(/(\{\{convert\s*\|\d+(?:\.\d|)\|acre\|)m2(?=[|}])/gi, '$1ha');
//remove leading zeros from convert template
regex(/(\{\{convert\s*\|)\s*0+(?=[1-9])/gi, '$1$2');
///e-acute accent in spelling
regex(/\b(caf|clich)e\b/g, '$1é');
}
function Ohc_format_MOSHASH(){
//hash fixes
// regex(/([^=] )#(\d{1,3}[,\.]?[<\s])/gi, '$1No. $2');
}
/** ------------------------------------------------------------------------ **/
/// PROTECTION BY STRING SUBSTITUTION
/**
var linkmap=[];
function ohc_downcase_CEO()
{
// protects categories, templates, link pipings, 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(/(<(?:imagemap)>)([\s\S]*)(<\/(?:imagemap)>)/gi, protect_function);
regex(/(\{(?:Coord|See ?also|Main|Wikisource))(\|[^{}]*)(\})/gi, protect_function);
regex(/(\{(?:Coord|অরো ?দেখুন|প্রধান|উইকিসংকলন))(\|[^{}]*)(\})/gi, protect_function);
regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/((?:বিষয়শ্রেণী|ফাইল|চিত্র):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/(\|\s*edition\s*=)([^|\]]*)([\|\]])/gi, protect_function);
regex(/(\|\s*\w*\s*=\s*)(\d(?:st|nd|rd|th)[^|\]]*)([\|\]])/gi, protect_function);
regex(/(\D)(\d(?:st|nd|rd|th)(?: (?:to |and )(?:the |)\d{1,2}(?:st|nd|rd|th)|) (?:centur|ed[i\. ]|grade|millenni[au]|parallel|round))(.)/gi, protect_function); //protecting lower case terms only; code does not expand where ordinal num is followed by a block cap
regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map|title|quote)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
regex(/(<ref name=)([^<>]*)(>)/gi, protect_function);
regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
regex(/(.)((?:Chairman's|President'?s) (?:XI|Cup))(.)/g, protect_function);
regex(/(.)(100\scrore club)(.)/gi, protect_function);
regex(/(.)(Conference of Presidents)(.)/g, protect_function);
// Euros - replace space as separator
regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5,$6');
regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4,$5');
regex(/(€|Euros?) ?(\d+)[\. ](\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3,$4');
regex(/(€|Euros?) ?(\d{3})[\. ](\d{3})(?=\W)/g, '$1$2,$3');
regex(/(\d+)[\. ](\d{3})[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$4$1,$2,$3');
regex(/(\d+)[\. ](\d{3}) ?(€|Euros?|\[\[(?:€|Euros?\||)(?:€|Euros?)\]\])(?=\W)/g, '$3$1,$2');
// replace full stop as thousands separator
regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4,$5');
regex(/(\|[\s\']+)(\d+)[\. ](\d{3})[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3,$4');
regex(/(\|[\s\']+)(\d+)[\. ](\d{3})(?=[ ']*[|\n<])/g, '$1$2,$3');
// replace comma as decimal separator
regex(/(\|[\s\']+)(\d+),(\d\d?)(?=[ ']*[|\n<])/g, '$1$2.$3');
regex(/(\(\d+),(\d\d?%\))/g, '$1.$2'); //percentages in parentheses
regex(/(\{\{(?:de|in)crease\}\}\s*)(\d+),(\d\d?)(?=[ ]*[|\n<])/g, '$1$2.$3');
regex(/([€])[ ]*(\d+)(?=\W)/g, '$1$2');
regex(/([€])(\d+),(\d\d?)(?=\W)/g, '$1$2.$3');
regex(/(\W)(\d+),(\d\d?)[ ]*(?=[€%]|Euro?)/g, '$1$2.$3');
regex(/(\|\s*attendance\s*=\s*\d{1,3})[\.]?(\d{3}\D)/gi, '$1,$2');
// layout - rem horizontal lines per WP:LAYOUT
// regex(/(\n)----\n/g, '$1'); // html element - may sometimes be appropriate – disabled per discussion at WT:LAYOUT July 2014
//removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
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;
});
}
/** ------------------------------------------------------------------------
/// LINKSPAM removal with protection for Reference tags and External links
var linkmap=[];
function ohc_linkspam()
{
// protects everything within reference tags
// 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(/(== ?(?:Bibliography|Further reading|Sources|Works) ?==+)(\n[\S\s]*?)(\n)(?===)/gi, protect_function);
regex(/(== ?(?:টীকা|আরও পড়ুন|তথ্যসূত্র|পরিশিষ্ট|পাদটীকা|বহিঃসংযোগ|তথ্যসূত্র ও পাদটীকা|গ্রন্থসূত্র|গ্রন্থপঞ্জি) ?==+)(\n[\S\s]*?)(\n)(?===)/gi, protect_function);
regex(/(== ?External links ?==)(\n[\S\s]*?)(\[\[Category:[^\]]+\]\])/gi, protect_function);
regex(/(== ?বহিঃসংযোগ ?==)(\n[\S\s]*?)(\[\[বিষয়শ্রেণী:[^\]]+\]\])/gi, protect_function);
regex(/({{refn\|)([^}]*?)(}})/gi, protect_function);
regex(/(<ref name="[^\"]*?" ?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
regex(/(<ref[^/>]*?>)([\s\S]*?)(<\/ref>)/gi, protect_function);
regex(/([=\*][ ]?\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/([^>\*][ ]?)\[https?:\/\/[^\s\[\]]*[ ]+([\'\"\w][^\[\]]*)\](?![ ]*[\n\-]+)/gi, '$1$2');
//removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
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_change_type(){
//update syntax of 'File'
// regex(/\[\[(file|[Ii]mage):/g, '[[File:');
//add {{url}} template to infobox parameter
regex(/({{) ?(url) ?(?=\|)/gi, '$1$2');
regex(/({{url\|)[ ]*https?:\/\/(?:www\.|)([^\}]+}})[ ]*(?=[\n\r])/gi, '$1$2');
regex(/(homepage[ ]*=)[ ]*https?:\/\/(?:www\.|)([^\s\[\]]+)(?=[\s])/gi, '$1{{url|$2}}');
regex(/((?:homepage|website)[ ]*=)[ ]*\[https?:\/\/(?:www\.|)([^\s\[\]]+) official (?:web|)site\](?=[\s])/gi, '$1{{url|$2}}');
regex(/({{url\|)([^\}]+)\|\2}}(?=[\s])/gi, '$1$2}}');
//remove icons from headers (needs to occur before protection)
regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');
}
function Ohc_final_cleanup(){
//adjust piping - remove redundant, adding piping for parentheticals
regex(/\[\[([^\]\|]*)\|\1([^-\] ]*|)(\]\])/gi, '[[$1$3$2');
regex(/\[\[([^\[\]\(\)\|:]*)( \((?:\d{4} |)film\))(\]\])/gi, '\'\'[[$1$2|$1$3\'\'');
regex(/\[\[([^\[\]\(\)\|:]*)( \([^\[\]\(\)\|]*\))(\]\])(?![\s\n])/gi, '[[$1$2|$1$3');
// deprecated parameters in citation templates
regex(/(\|\s*)coauthors(\s*=\s*)/g, '$1author2$2');
}
function Ohc_downcase_headings(){
//cleanup of headings per MOSHEAD before complete downcasing (most code is copied from other parts of the script)
// remove file
regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:File|image):[^\]]+?\]\]([^\[=\n]*)([ ]?==)/gi, '$1$2$3');
//rem linking within section headings
regex(/(==[ ]?(?:[^\[\n=]*))\[\[([^\|\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
regex(/(==[ ]?(?:[^\[\n=]*))\[\[[^\|\]]+?\|([^\]]+?)\]\]((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3');
regex(/(==[ ]?(?:[^\[\n=]*))\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\](?:([^\[\|]*)\[\[(?:[^\|\]]+?\||)([^\]]+?)\]\]|)((?:[^\[=\n]*|)[ ]?==)/gi, '$1$2$3$4$5$6$7');
//rem refs within section headings
regex(/(==[ ]?(?:[^<>\n]*))(?:<ref(?:>[^<>]*<\/ref| name=[^\/>]+\/)>)([^<>\n]*)(?=[ ]?==)/gi, '$1$2');
//original code
regex(/(==+[ ]?[A-Z])([^\[=|]*)(?===+ ?\n)/g, '$1{{' + 'subst:' + 'lc:$2}}');
}
function Ohc_castlist(){
//remove flagicons from country, birth and death
regex(/(\* )(\[\[[-\w' ]*\]\]) as ([^,\.]*)([,.])([^\n<]*)([\n<])/gi, '$1\'\'\'$3\'\'\' ($2)$4$5$6');
}
/** -----------------------------------------------------------------------
/// PROTECTION BY STRING SUBSTITUTION
var linkmap=[];
function ohc_protect_fmt()
{
// protects categories, templates, link pipings, 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(/(\{Wikisource\|)([\}]*)(\})/gi, protect_function);
regex(/(\{উইকিসংকলন\|)([\}]*)(\})/gi, protect_function);
regex(/((?:Category|File|Image):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/((?:বিষয়শ্রেণী|ফাইল|চিত্র):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/((?:[a-z]{2,3}):)([^|\]]*)([\|\]])/gi, protect_function);
regex(/(\{(?:See ?also|Main))(\|[^{}]*)(\})/gi, protect_function);
regex(/(\{(?:আরো ?দেখুন|প্রধান))(\|[^{}]*)(\})/gi, protect_function);
regex(/((?:cover|file(?:name|)|image\d?|image_skyline|image[ _]location\d?|image[ _]name|img|pic|map)\s*=)([^\|\}]*)([\|\}])/gi, protect_function);
regex(/(\[\[\w*)([^\|\]]*)(\|)/gi, protect_function);
regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function);
regex(/(<ref name=)([^<>]*)(>)/gi, protect_function);
regex(/(\{Infobox)( non Test)( cricket)/gi, protect_function);
}
function ohc_unprotect_fmt()
{
//removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
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_formats(){
//driver
Ohc_format_Sundry();
Ohc_format_MOSCAPS();
Ohc_format_MOSFLAG();
Ohc_format_MOSPUNCT();
Ohc_format_MOSHASH();
Ohc_format_COMMONALITY();
}
function Ohc_formatgeneral() {
ohc_change_type();
ohc_protect_fmt();
Ohc_formats();
ohc_unprotect_fmt();
ohc_downcase_CEO();
ohc_linkspam();
Ohc_final_cleanup();
}
function Ohc_run_formatgeneral() {
Ohc_formatgeneral();
Ohc_formatgen_edit_summary();
}
function Ohc_formatgen_edit_summary(){
//Add a tag to the summary box
setoptions(minor='true');
setreason('[[en:WP:MOS|রচনাশৈলী]]/বিন্যাসন ত্রুটি ঠিককরণ', 'append');
doaction('diff');
}
$(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral()', 'General formatting', 't-addmetric', 'Fixes some unit formatting', '', '');
}
});