பயனர்:Maathavan/For Me/complete.js
குறிப்பு - சேமித்த பின்னர், நீங்கள் செய்த மாற்றங்களைக் காண்பதற்கு உங்கள் உலவியின் இடைமாற்று அகற்றப்பட வேண்டும்.
- மொஸில்லா பயர்பாக்ஸ் / சபாரி: Shift+Reload, அல்லது Ctrl-F5 அல்லது Ctrl-R (⌘-R Mac ல்)
- கூகிள் குரோம் Ctrl-Shift-R அழுத்தவும். (⌘-Shift-R Mac ல்) ;
- இண்டர்நெட் எக்ஸ்ப்ளோரர்: Ctrl-Refresh அல்லது Ctrl-F5 ஐ அழுத்தவும்.
- ஒபேரா: Tools → Preferences இல் இடைமாற்றை அகற்றவும்;
//
function autoEdUnicodify(str) { //MAIN FUNCTION describes list of fixes
if(window.template_autosave == false){}else{ template_autosave = true; }
// Task 1: Replace named html entities with unicode
// Most common replacements
str = str.replace(/—/gi, '—');
str = str.replace(/–/gi, '–');
str = str.replace(/File:/gi, 'படிமம்:');
str = str.replace(/0500000US34023/gi, '0500000US34027');
str = str.replace(/Middlesex County, New Jersey/gi, 'Morris County, New Jersey');
// Case insensitive symbols
if(str.search(/&[a-z][a-z]+[0-9]*;/i) >= 0) {
//XML and HTML Symbols
str = str.replace(/+/gi, '+');
str = str.replace(/±/gi, '±');
str = str.replace(/−/gi, '−');
str = str.replace(/×/gi, '×');
str = str.replace(/÷/gi, '÷');
str = str.replace(/≠/gi, '≠');
str = str.replace(/≈/gi, '≈');
str = str.replace(/≤/gi, '≤');
str = str.replace(/≥/gi, '≥');
str = str.replace(/"/gi, '"'); // "
str = str.replace(/'/gi, "'"); // '
str = str.replace(/¡/gi, '¡');
str = str.replace(/¢/gi, '¢');
str = str.replace(/£/gi, '£');
str = str.replace(/¤/gi, '¤');
str = str.replace(/¥/gi, '¥');
str = str.replace(/¦/gi, '¦');
str = str.replace(/§/gi, '§');
str = str.replace(/¨/gi, '¨');
str = str.replace(/©/gi, '©');
str = str.replace(/ª/gi, 'ª');
str = str.replace(/«/gi, '«');
str = str.replace(/¬/gi, '¬');
str = str.replace(/®/gi, '®');
str = str.replace(/¯/gi, '¯');
str = str.replace(/°/gi, '°');
str = str.replace(/²/gi, '²');
str = str.replace(/³/gi, '³');
str = str.replace(/´/gi, '´');
str = str.replace(/µ/gi, 'µ');
str = str.replace(/¶/gi, '¶');
str = str.replace(/·/gi, '·');
str = str.replace(/¸/gi, '¸');
str = str.replace(/¹/gi, '¹');
str = str.replace(/º/gi, 'º');
str = str.replace(/»/gi, '»');
str = str.replace(/¼/gi, '¼');
str = str.replace(/½/gi, '½');
str = str.replace(/¾/gi, '¾');
str = str.replace(/¿/gi, '¿');
str = str.replace(/ˆ/gi, 'ˆ');
str = str.replace(/˜/gi, '˜');
str = str.replace(/‘/gi, '‘');
str = str.replace(/’/gi, '’');
str = str.replace(/‚/gi, '‚');
str = str.replace(/“/gi, '“');
str = str.replace(/”/gi, '”');
str = str.replace(/„/gi, '„');
str = str.replace(/•/gi, '•');
str = str.replace(/‰/gi, '‰');
str = str.replace(/‹/gi, '‹');
str = str.replace(/›/gi, '›');
str = str.replace(/‾/gi, '‾');
str = str.replace(/⁄/gi, '⁄');
str = str.replace(/€/gi, '€');
str = str.replace(/ℑ/gi, 'ℑ');
str = str.replace(/℘/gi, '℘');
str = str.replace(/ℜ/gi, 'ℜ');
str = str.replace(/™/gi, '™');
str = str.replace(/ℵ/gi, 'ℵ');
str = str.replace(/↵/gi, '↵');
str = str.replace(/∀/gi, '∀');
str = str.replace(/∂/gi, '∂');
str = str.replace(/∃/gi, '∃');
str = str.replace(/∅/gi, '∅');
str = str.replace(/∇/gi, '∇');
str = str.replace(/∈/gi, '∈');
str = str.replace(/∉/gi, '∉');
str = str.replace(/∋/gi, '∋');
str = str.replace(/∏/gi, '∏');
str = str.replace(/∑/gi, '∑');
str = str.replace(/∗/gi, '∗');
str = str.replace(/√/gi, '√');
str = str.replace(/∝/gi, '∝');
str = str.replace(/∞/gi, '∞');
str = str.replace(/∠/gi, '∠');
str = str.replace(/∧/gi, '∧');
str = str.replace(/∨/gi, '∨');
str = str.replace(/∩/gi, '∩');
str = str.replace(/∪/gi, '∪');
str = str.replace(/∫/gi, '∫');
str = str.replace(/∴/gi, '∴');
str = str.replace(/∼/gi, '∼');
str = str.replace(/≅/gi, '≅');
str = str.replace(/⊂/gi, '⊂');
str = str.replace(/⊃/gi, '⊃');
str = str.replace(/⊄/gi, '⊄');
str = str.replace(/⊆/gi, '⊆');
str = str.replace(/⊇/gi, '⊇');
str = str.replace(/⊕/gi, '⊕');
str = str.replace(/⊗/gi, '⊗');
str = str.replace(/⊥/gi, '⊥');
str = str.replace(/⋅/gi, '⋅');
str = str.replace(/⌈/gi, '⌈');
str = str.replace(/⌉/gi, '⌉');
str = str.replace(/⌊/gi, '⌊');
str = str.replace(/⌋/gi, '⌋');
str = str.replace(/⟨/gi, '〈');
str = str.replace(/⟩/gi, '〉');
str = str.replace(/◊/gi, '◊');
str = str.replace(/♠/gi, '♠');
str = str.replace(/♣/gi, '♣');
str = str.replace(/♥/gi, '♥');
str = str.replace(/♦/gi, '♦');
}
// Uppercase symbols
if(str.search(/&[A-Z][a-z]+;/) >= 0) {
//Greek symbols
str = str.replace(/Α/g, 'Α');
str = str.replace(/Β/g, 'Β');
str = str.replace(/Γ/g, 'Γ');
str = str.replace(/Δ/g, 'Δ');
str = str.replace(/Ε/g, 'Ε');
str = str.replace(/Ζ/g, 'Ζ');
str = str.replace(/Η/g, 'Η');
str = str.replace(/Θ/g, 'Θ');
str = str.replace(/Ι/g, 'Ι');
str = str.replace(/Κ/g, 'Κ');
str = str.replace(/Λ/g, 'Λ');
str = str.replace(/Μ/g, 'Μ');
str = str.replace(/Ν/g, 'Ν');
str = str.replace(/Ξ/g, 'Ξ');
str = str.replace(/Ο/g, 'Ο');
str = str.replace(/Π/g, 'Π');
str = str.replace(/Ρ/g, 'Ρ');
str = str.replace(/Σ/g, 'Σ');
str = str.replace(/Τ/g, 'Τ');
str = str.replace(/Υ/g, 'Υ');
str = str.replace(/Φ/g, 'Φ');
str = str.replace(/Χ/g, 'Χ');
str = str.replace(/Ψ/g, 'Ψ');
str = str.replace(/Ω/g, 'Ω');
//Latin symbols
str = str.replace(/À/g, 'À');
str = str.replace(/Á/g, 'Á');
str = str.replace(/Â/g, 'Â');
str = str.replace(/Ã/g, 'Ã');
str = str.replace(/Ä/g, 'Ä');
str = str.replace(/Å/g, 'Å');
str = str.replace(/Æ/g, 'Æ');
str = str.replace(/Ç/g, 'Ç');
str = str.replace(/È/g, 'È');
str = str.replace(/É/g, 'É');
str = str.replace(/Ê/g, 'Ê');
str = str.replace(/Ë/g, 'Ë');
str = str.replace(/Ì/g, 'Ì');
str = str.replace(/Í/g, 'Í');
str = str.replace(/Î/g, 'Î');
str = str.replace(/Ï/g, 'Ï');
str = str.replace(/Ñ/g, 'Ñ');
str = str.replace(/Ò/g, 'Ò');
str = str.replace(/Ó/g, 'Ó');
str = str.replace(/Ô/g, 'Ô');
str = str.replace(/Õ/g, 'Õ');
str = str.replace(/Ö/g, 'Ö');
str = str.replace(/Ø/g, 'Ø');
str = str.replace(/Ù/g, 'Ù');
str = str.replace(/Ú/g, 'Ú');
str = str.replace(/Û/g, 'Û');
str = str.replace(/Ü/g, 'Ü');
str = str.replace(/Ý/g, 'Ý');
str = str.replace(/Š/g, 'Š');
str = str.replace(/Ÿ/g, 'Ÿ');
//XML and HTML Symbols
str = str.replace(/‡/g, '‡');
str = str.replace(/″/g, '″');
}
// lowercase symbols
if(str.search(/&[a-z][a-z]+;/) >= 0) {
//Greek symbols
str = str.replace(/α/g, 'α');
str = str.replace(/β/g, 'β');
str = str.replace(/γ/g, 'γ');
str = str.replace(/δ/g, 'δ');
str = str.replace(/ε/g, 'ε');
str = str.replace(/ζ/g, 'ζ');
str = str.replace(/η/g, 'η');
str = str.replace(/θ/g, 'θ');
str = str.replace(/ι/g, 'ι');
str = str.replace(/κ/g, 'κ');
str = str.replace(/λ/g, 'λ');
str = str.replace(/μ/g, 'μ');
str = str.replace(/ν/g, 'ν');
str = str.replace(/ξ/g, 'ξ');
str = str.replace(/ο/g, 'ο');
str = str.replace(/π/g, 'π');
str = str.replace(/ρ/g, 'ρ');
str = str.replace(/ς/g, 'ς');
str = str.replace(/σ/g, 'σ');
str = str.replace(/τ/g, 'τ');
str = str.replace(/υ/g, 'υ');
str = str.replace(/φ/g, 'φ');
str = str.replace(/χ/g, 'χ');
str = str.replace(/ψ/g, 'ψ');
str = str.replace(/ω/g, 'ω');
str = str.replace(/ϑ/g, 'ϑ');
str = str.replace(/ϒ/g, 'ϒ');
str = str.replace(/ϖ/g, 'ϖ');
//Latin symbols
str = str.replace(/ß/g, 'ß');
str = str.replace(/à/g, 'à');
str = str.replace(/á/g, 'á');
str = str.replace(/â/g, 'â');
str = str.replace(/ã/g, 'ã');
str = str.replace(/ä/g, 'ä');
str = str.replace(/å/g, 'å');
str = str.replace(/æ/g, 'æ');
str = str.replace(/ç/g, 'ç');
str = str.replace(/è/g, 'è');
str = str.replace(/é/g, 'é');
str = str.replace(/ê/g, 'ê');
str = str.replace(/ë/g, 'ë');
str = str.replace(/ì/g, 'ì');
str = str.replace(/í/g, 'í');
str = str.replace(/î/g, 'î');
str = str.replace(/ï/g, 'ï');
str = str.replace(/ð/g, 'ð');
str = str.replace(/ñ/g, 'ñ');
str = str.replace(/ò/g, 'ò');
str = str.replace(/ó/g, 'ó');
str = str.replace(/ô/g, 'ô');
str = str.replace(/õ/g, 'õ');
str = str.replace(/ö/g, 'ö');
str = str.replace(/ø/g, 'ø');
str = str.replace(/ù/g, 'ù');
str = str.replace(/ú/g, 'ú');
str = str.replace(/û/g, 'û');
str = str.replace(/ü/g, 'ü');
str = str.replace(/ý/g, 'ý');
str = str.replace(/þ/g, 'þ');
str = str.replace(/ÿ/g, 'ÿ');
str = str.replace(/œ/g, 'œ');
str = str.replace(/š/g, 'š');
str = str.replace(/ƒ/g, 'ƒ');
//XML and HTML Symbols
str = str.replace(/†/g, '†');
str = str.replace(/′/g, '′');
}
// False positives
// Breaks large amounts of code which discuss programming/scripting.
// str = str.replace(/</gi, '<');
// str = str.replace(/>/gi, '>');
// Breaks large number of URLs and discussion of programming/scripting.
// str = str.replace(/&/gi, '&');
// Arrows
str = str.replace(/←/g, '←');
str = str.replace(/→/g, '→');
str = str.replace(/↑/g, '↑');
str = str.replace(/↓/g, '↓');
str = str.replace(/⇐/g, '⇐');
str = str.replace(/⇒/g, '⇒');
str = str.replace(/⇑/g, '⇑');
str = str.replace(/⇓/g, '⇓');
str = str.replace(/↔/g, '↔');
str = str.replace(/⇔/g, '⇔');
str = str.replace(/<==|<--/gi, '←');
str = str.replace(/==>/gi, '→');
// Specific case
str = str.replace(/Ð/g, 'Ð');
str = str.replace(/Þ/g, 'Þ');
str = str.replace(/Œ/g, 'Œ');
// Task 2: Replace numeric html entities with unicode ( User:CharlotteWebb )
// Symbols for which there may be a good reason to obfuscate/escape
var dont_replace = "|!{}[]=<>";
// START specialreplace function from User:CharlotteWebb
function specialreplace(ent, base){
var chr = "";
var num = parseInt(ent.replace(/[\&\#\;x]/g, ''), base);
// see [[UTF-16]] for chars outside the BMP
// try this with Gothic letters at full volume ^_^
if (num > 0xFFFF) {
num -= 0x10000;
chr = String.fromCharCode(0xD800 + (num >> 10), 0xDC00 + (num & 0x3FF));
} else {
chr = String.fromCharCode(num);
}
if (dont_replace.indexOf(chr) == -1) {
str = str.replace(ent, chr, "gi");
}
}
// END specialreplace function
// perform replacement
if(m = str.match(/\&\#(\d+)\;/g)) {
for(i = 0; i < m.length; i++) {
specialreplace(m[i], 10);
}
}
if(m = str.match(/\&\#x([\da-f]+)\;/gi)) {
for(i = 0; i < m.length; i++) {
specialreplace(m[i], 16);
}
}
// Task 3: Unprintable control characters [[Windows-1252]] from User:CharlotteWebb
var failstr = "<!-- AutoEd: rm unicode ctrl char w/no win-1252 mapping, intent unknown -->";
str = str.replace(/\u0080/g, '€');
str = str.replace(/\u0081/g, failstr);
str = str.replace(/\u0082/g, '‚');
str = str.replace(/\u0083/g, 'ƒ');
str = str.replace(/\u0084/g, '„');
str = str.replace(/\u0085/g, '…');
str = str.replace(/\u0086/g, '†');
str = str.replace(/\u0087/g, '‡');
str = str.replace(/\u0088/g, 'ˆ');
str = str.replace(/\u0089/g, '‰');
str = str.replace(/\u008a/g, 'Š');
str = str.replace(/\u008b/g, '‹');
str = str.replace(/\u008c/g, 'Œ');
str = str.replace(/\u008d/g, failstr);
str = str.replace(/\u008e/g, 'Ž');
str = str.replace(/\u008f/g, failstr);
str = str.replace(/\u0090/g, failstr);
str = str.replace(/\u0091/g, '‘');
str = str.replace(/\u0092/g, '’');
str = str.replace(/\u0093/g, '“');
str = str.replace(/\u0094/g, '”');
str = str.replace(/\u0095/g, '•');
str = str.replace(/\u0096/g, '–');
str = str.replace(/\u0097/g, '—');
str = str.replace(/\u0098/g, '˜');
str = str.replace(/\u0099/g, '™');
str = str.replace(/\u009a/g, 'š');
str = str.replace(/\u009b/g, '›');
str = str.replace(/\u009c/g, 'œ');
str = str.replace(/\u009d/g, failstr);
str = str.replace(/\u009e/g, 'ž');
str = str.replace(/\u009f/g, 'Ÿ');
return str;
}
function autoEdISBN(str) { //MAIN FUNCTION describes list of fixes
//Allows WikiMagic to work with ISBNs
str = str.replace(/ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:/gi, 'ISBN');
return str;
}
function autoEdWhitespace(str) { //MAIN FUNCTION describes list of fixes
str = str.replace(/\t/g, " ");
str = str.replace(/^ ? ? \n/gm, "\n");
// Extra newlines
if(str.search(/\uE000/g) < 0) { // see [[Private Use Area]]
// Mark spacing before stub templates
str = str.replace(/(\n)[ \t]*(\n)[ \t]*(\n\{\{[^{}]*\-stub\}\})/gm, "$1\uE000$2\uE000$3");
str = str.replace(/(\n)[ \t]*(\n\{\{[^{}]*\-stub\}\})/gm, "$1\uE000$2");
// Remove extra newlines
str = str.replace(/(?:[\t ]*\n)+[\t ]*(\n\uE000\n\uE000\n)/gm, "$1");
str = str.replace(/(\n\n)\n+/gm, "$1");
str = str.replace(/(\n[\t ]*\n)(?:[\t ]*\n)+/g, "$1");
// Unmark
str = str.replace(/\uE000/g, '');
}
// str = str.replace(/== ? ?\n\n==/g, "==\n==");
str = str.replace(/\n\n(\* ?\[?http)/g, "\n$1");
str = str.replace(/^ ? ? \n/gm, "\n");
str = str.replace(/\n\n\*/g, "\n*");
// str = str.replace(/[ \t][ \t]+/g, " ");
str = str.replace(/(=\n[\t ]*\n[\t ]*\n)(?:[\t ]*\n)+/g, "$1");
str = str.replace(/ \n/g, "\n");
//* bullet points
if(str.search(/\uE000/g) < 0) { // see [[Private Use Area]]
str = str.replace(/^(\#)(REDIRECT)/gi, '$1\uE000$2'); // Mark redirects
str = str.replace(/^([\*#]+:*) /gm, "$1");
str = str.replace(/^([\*#]+:*)/gm, "$1 ");
str = str.replace(/[\t ]*\uE000[\t ]*/g, ''); // Unmark redirects
}
//==Headings==
str = str.replace(/^(={1,4} )[ ]*([^= ][^=]*[^= ])[ ]*( ={1,4})$/gm, "$1$2$3");
str = str.replace(/^(={1,4})([^= ][^=]*[^= ])[ ]+(={1,4})$/gm, "$1$2$3");
str = str.replace(/^(={1,4})[ ]+([^= ][^=]*[^= ])(={1,4})$/gm, "$1$2$3");
return str;
}
// Credits: A modification of [[Wikipedia:WikiProject User scripts/Scripts/Formatter]]
function autoEdWikilinks(str) { //MAIN FUNCTION describes list of fixes
//Get the list of all wikilinks with underscores
var m = str.match(/\[\[[^\[\]]*_[^\[\]]*\]\]/g);
if (m) {
//For each wikilink in the list
for (var i = 0; i < m.length; i++) {
var x = m[i].toString() // Contains the entire wikilink
// Exclude URLs and leading underscores
if( !x.match(/^\[\[[\t ]*(?:http|ftp|https):/i) && !x.match(/^\[\[_[^\[\]]*\]\]/) ) {
var x_arr = x.match(/^(\[\[[^\[\]\|]*)(\|?[^\[\]]*?\]\])$/);
var a = x_arr[1]; // Everything before the pipe (or everything minus ]])
var b = x_arr[2]; // Everything after the pipe (or ]])
// Replace underscores with spaces
a = a.replace(/_/g, ' ');
// Do the replacement
str = str.replace(x, a+b);
}
}
}
//Fix links which have no target
str = str.replace(/\[\[[\t ]*\|/gi, '[[');
//Leading and trailing space before the pipe inside wikilinks
str=str.replace(/(\[\[)[\t ]+([^\[\]\|]*?)(\|)/g, '$1$2$3');
str=str.replace(/(\[\[)([^\[\]\|]*?)[\t ]+(\|)/g, '$1$2$3');
//Leading space after the pipe (or in an unpiped) wikilink
str=str.replace(/^(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g, '$1$2$3');
str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g, ' $1$2$3');
//Trailing space after the pipe (or in an unpiped) wikilink
str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|\t ][^\[\]\|]*?)[\t ]+(\]\])([^A-Za-z])/gi, '$1$2$3 $4');
str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|]*?)[\t ]+(\]\])$/gi, '$1$2$3');
//Get the list of all piped wikilinks
var m = str.match(/\[\[[^\[]*?\|[^\[]*?\]\]/g);
if (m) {
//For each piped wikilink in the list
for (var i = 0; i < m.length; i++) {
var n_arr = m[i].toString().match(/\[\[[ ]*([^\[]*?)\|[ ]*([^\[]*?)\]\]/);
var n = n_arr[0]; // Contains the entire piped link
var a = n_arr[1]; // Contains everything before pipe
var b = n_arr[2]; // Contains everything after pipe
var c = b.replace(/[\.,:; ]*$/); // Same as b, but without trailing punctuation
//Is the display name a leading substring of the wikilink?
if (b.indexOf(a) == 0 || b.indexOf(autoEd_first2lower(a)) == 0) {
//Create a simplified replacement string
var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w]*?)\]\]/i, "[[$2]]$3");
//And do the replacement
str = str.replace(n, k);
}
if (c.indexOf(a) == 0 || c.indexOf(autoEd_first2lower(a)) == 0) {
// Create a simplified replacement string
var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w\.,:;]*?)\]\]/i, "[[$2]]$3");
// And do the replacement
str = str.replace(n, k);
}
}
}
//Push trailing characters into display string of piped wikilinks
str = str.replace(/\[\[([^\[\]\|]+)\|([^\[\]\|]+)\]\]([a-z]+)/g, "[[$1|$2$3]]");
//Removes links to current article
var p1 = wgPageName; // PAGENAME including underscores
var p2 = wgPageName.replace('_',' '); // PAGENAME without underscores
var p3 = autoEd_first2lower(p1); // First character lowercase PAGENAME including underscores
var p4 = autoEd_first2lower(p2); // First character lowercase PAGENAME without underscores
// Standard wikilinks
str = str.replace(new RegExp('\\[\\[(' + p1 + '|' + p2 + '|' + p3 + '|' + p4 + ')\\]\\]', 'g'), '$1');
// Piped wikilinks
str = str.replace(new RegExp('\\[\\[(?:' + p1 + '|' + p2 + '|' + p3 + '|' + p4 + ')\\|([^\\]\\|]*)\\]\\]', 'g'), '$1');
//Shorten interwiki links
str = str.replace(/\[\[WIKTIONARY:/gi, '[[wikt:');
str = str.replace(/\[\[WIKINEWS:/gi, '[[n:');
str = str.replace(/\[\[WIKIBOOKS:/gi, '[[b:');
str = str.replace(/\[\[WIKIQUOTE:/gi, '[[q:');
str = str.replace(/\[\[WIKISOURCE:/gi, '[[s:');
str = str.replace(/\[\[WIKISPECIES:/gi, '[[species:');
str = str.replace(/\[\[WIKIVERSITY:/gi, '[[v:');
str = str.replace(/\[\[(?:WIKIMEDIA|FOUNDATION):/gi, '[[wmf:');
str = str.replace(/\[\[METAWIKIPEDIA:/gi, '[[m:');
//Replace [[Foo #bar]] -> [[Foo#bar]]
str = str.replace(/\[\[([^\]]*?)( |_)+#([^\]]*?)\]\]/g, '[[$1#$3]]');
//Replace [[Foo|Foo]] -> [[Foo| ]]
str = str.replace(/\|\]\]/g, '| ]]');
return str;
}
// Converts the first character in a string to lower case
// Notes: Used by autoEdWikilinks
function autoEd_first2lower(str) {
if (str != "") {
var letter = str.substr(0, 1);
return letter.toLowerCase() + str.substr(1, str.length);
} else {
return "";
}
}
//Convert HTML to wikitext
function autoEdHTMLtoWikitext(str) {
// <b>, <strong>, <i>, and <em> tags
str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "'''$2'''");
str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "''$2''");
// </br>, <\br>, <br\>, <BR />, ...
str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, '<br />');
str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, '<br />');
// <.br>, <br.>, <Br>, ...
str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, '<br>');
// <br>>, <<br />, <<br >> ...
str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, '$1');
str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, '$1');
// <hr>
str = str.replace(/([\r\n])[\t ]*<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1----');
str = str.replace(/(.)<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1\n----');
// Not really an HTML-to-wikitext fix, but close enough
str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, '<references />');
// Repeated references tag
str = str.replace(/(<references \/>)[\s]*\1/gim, '$1');
// Make sure <H1>, ..., <H6> is after a newline
str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, '$1\n$2');
// Make sure </H1>, ..., </H6> is before a newline
str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, '$1\n$2');
// Remove newlines from inside <H1>, ..., <H6>
var loopcount = 0;
while( str.search( /<H([1-6])[^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H\1[^<>]*>/gim ) >= 0 && loopcount <= 10 ) {
str = str.replace(/(<H)([1-6])([^<>]*>(?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?)[\r\n]((?:[^<>]|<\/?[^\/h\r\n][^<>]*>)*?<\/H)\2([^<>]*>)/gim, '$1$2$3 $4$2$5');
loopcount++;
}
// Replace <H1>, ..., <H6> with wikified section headings
str = str.replace(/(^|[\r\n])[\t ]*<H1[^<>]*>([^\r\n]*?)<\/H1[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=$2=$3');
str = str.replace(/(^|[\r\n])[\t ]*<H2[^<>]*>([^\r\n]*?)<\/H2[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1==$2==$3');
str = str.replace(/(^|[\r\n])[\t ]*<H3[^<>]*>([^\r\n]*?)<\/H3[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1===$2===$3');
str = str.replace(/(^|[\r\n])[\t ]*<H4[^<>]*>([^\r\n]*?)<\/H4[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1====$2====$3');
str = str.replace(/(^|[\r\n])[\t ]*<H5[^<>]*>([^\r\n]*?)<\/H5[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1=====$2=====$3');
str = str.replace(/(^|[\r\n])[\t ]*<H6[^<>]*>([^\r\n]*?)<\/H6[\r\n\t ]*>[\t ]*([\r\n]|$)/gim, '$1======$2======$3');
return str;
}
function autoEdHeadlines(str) { //MAIN FUNCTION describes list of fixes
// Remove bold from section headings
var loopcount = 0;
while( str.search(/^[=]{1,5}[^=\r\n]*'''[^=\r\n]*[=]{1,5}/gim) >= 0 && loopcount <= 10 ) { //'
str = str.replace(/(^[=]{1,5}[^=\r\n]*)'''([^=\r\n]*[=]{1,5})[\t ]*/gim, '$1$2'); //'
loopcount++;
}
// Remove trailing colon from section headings
str = str.replace(/(^[=]{1,5}[^=\r\n]*)[:]([\t ]*[=]{1,5})[\t ]*/gim, '$1$2');
// Correct caps in "See also" section
str = str.replace(/(==[\t ]*)see also([\t ]*==)/gi, "$1See also$2");
// Change common synonyms for "See also" to "See also", but only if "See also" doesn't exist
if( !str.match(/=[\t ]*See also[\t ]*=/gi) ) {
str = str.replace(/(==[\t ]*)(?:related topics|related articles|internal links|also see)([\t ]*==)/gi, "$1See also$2");
}
// Common synonyms for "External links"
str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1External links$2");
// Capitalization and/or plural of "References", "Sources", "Further reading"
str = str.replace(/(==[\t ]*)references([\t ]*==)/gi, "$1References$2");
str = str.replace(/(==[\t ]*)sources([\t ]*==)/gi, "$1Sources$2");
str = str.replace(/(==[\t ]*)further readings?([\t ]*==)/gi, "$1Further reading$2");
return str;
}
function autoEdUnicodeControlChars(str) { //MAIN FUNCTION describes list of fixes
//Removes unneeded Unicode control characters
str = str.replace(new RegExp('\u200E|\uFEFF|\u200B', 'gi'), '');
return str;
}
// Purpose: Changes hexcharacter codes in wikilinks to actual unicode characters
//
// Examples: [[Stra%C3%9Fe|street]] -> [[Straße|street]]
// [[AutoEd#History_.281990.29|History]] ->
// [[AutoEd#History (1990)|History]]
//
// Note: Contributed by CharlotteWeb
//
// Comments (CharlotteWeb):
// To keep things simple we'll ignore all image links. because some people prefer
// underscores in the file name and the caption can contain god-knows-what.
// one easy way is to flag them with a character which should never be used,
// but if it is already present we have a problem, so let's just quit.
//
function autoEdUnicodeHex(txt) { //MAIN FUNCTION describes list of fixes
if(txt.match(/\uE000/)) return(txt); // see [[Private Use Area]]
txt = txt.replace(/(\[\[[\:\s*]*(?:Image|File|Media)\s*\:)/gi, "$1\uE000");
if(m = txt.match(/\[\[[^\[\]\n\uE000]+\]\]/g)) {
for(var i = 0; i < m.length; i++) {
parts = m[i].split("|");
link = parts[0];
a = link.split("#")
title = a[0];
section = a[1];
try {
link = decodeURIComponent(title.replace(/\%(.[^0-9A-F]|[^0-9A-F].|$)/gi, "%25$1")
) + ( section ? ("#" + decodeURIComponent(section
// change "." to "%" when followed by valid hex
.replace(/\.([0-9A-F]{2})/gi, "%$1")
.replace(/\%(.[^0-9A-F]|[^0-9A-F].|$)/gi, "%25$1")
)
) : "" )
} catch(e) { } // just do no decoding
parts[0] = link;
txt = txt.replace(m[i], parts.join("|"));
}
}
return(txt.replace(/\uE000/g, ""));
}
function autoEdTemplates(str) { //MAIN FUNCTION describes list of fixes
//Remove unneeded Template: text from transclusions
str = str.replace(/{{[_ ]*Template:[_ ]*/gi, '{{');
//Replace redirects to Reflist with Reflist
str = str.replace(/{{[_ ]*(?:Reference[_ ]+List|References-Small|Reflink)[_ ]*(\||}})/gi, '{{Reflist$1');
str = str.replace(/{{[_ ]*(?:Refs|Reference|Ref-list|Listaref|FootnotesSmall)[_ ]*(\||}})/gi, '{{Reflist$1');
//Replace a long version of Reflist with Reflist
str = str.replace(/<div[^<>]*[ ]+class=['"]*references-small['"]*[^<>]*>[\r\n]*<references[ ]*\/>[\r\n]*<\/div>/gim, '{{Reflist}}');
//Replace redirects to about with about
str = str.replace(/{{[_ ]*(?:Otheruses4|Four[_ ]+other[_ ]+uses|Otherusesabout|This2)[_ ]*(\||}})/gi, '{{about$1');
return str;
}
//From Plastikspork's script
function autoEdTablestoWikitext(str) { //MAIN FUNCTION describes list of fixes
// Remove newlines from inside table specific tags
var loopcount = 0;
while( str.search(/(?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*[\r\n]/gi) >= 0 && loopcount <= 10 ) {
str.replace(/((?:<\/?table|<\/?tr|<\/?td|<\/?th)[^<>]*)[\r\n]/gi, '$1 ')
loopcount++;
}
// Remove extra whitespace from inside table specific tags
str=str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s]+(>)/gim, '$1$2$3');
str=str.replace(/(<table|<tr|<td|<th)([^<>]*?)[\s][\s]+/gim, '$1$2 ');
// Remove any extra junk </tr>, </td>, </th>, </table>
str=str.replace(/(<\/table|<\/tr|<\/td|<\/th)[^<>]+(>)/gim, '$1$2');
// Remove space whitespace after </tr>, </td>, </th>, <table>
str=str.replace(/(<\/tr>|<\/td>|<\/th>|<table[^<>]*>)[\s]+/gim, '$1');
// Remove space before <tr>, <td>, <th>, </table>
str=str.replace(/[\s]+(<\/table>|<tr[^<>]*>|<td[^<>]*>|<th[^<>]*>)/gim, '$1');
// Replace '<table>' with '{|'
str=str.replace(/<table( [^<>]*|)>[\s]*/gim, '{|$1\n');
// Replace '</table>' with '|}'
str=str.replace(/[\s]*<\/table>/gi, '\n|}');
// Replace '</td><td>' with '||'
str=str.replace(/<\/td[\s]*>[\s]*<td[\s]*>/gim, '||');
str=str.replace(/<\/td[\s]*>[\s]*<td ([^<>]+)>/gim, '|| $1 |');
// Replace '</th><th>' with '!!'
str=str.replace(/<\/th[\s]*>[\s]*<th[\s]*>/gim, '!!');
str=str.replace(/<\/th[\s]*>[\s]*<th ([^<>]+)>/gim, '!! $1 |');
// Replace '</td></tr>' and '</th></tr>' with EOL
str=str.replace(/<\/(?:td|th)>[\s]*<\/tr>[\s]/gim, '\n');
// Replace '</td>', '</th>', '</tr>' with EOL
str=str.replace(/<\/(?:td|th|tr)>[\s]*/gim, '\n');
// Replace '<tr>' with '|-'
str=str.replace(/[\s]*<tr>[\s]*/gim, '\n|-\n');
str=str.replace(/[\s]*<tr ([^<>]*)>[\s]*/gim, '\n|- $1\n');
// Replace '<td>' with '|'
str=str.replace(/[\s]*<td>([^\s])/gim, '\n| $1');
str=str.replace(/[\s]*<td>([\s])/gim, '\n|$1');
str=str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n| $1 | $2');
str=str.replace(/[\s]*<td[\s]*([^<>]*?)[\s]*>([\s])/gim, '\n| $1 |$2');
// Replace '<th>' with '!'
str=str.replace(/[\s]*<th>([^\s])/gim, '\n! $1');
str=str.replace(/[\s]*<th>([\s])/gim, '\n!$1');
str=str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n! $1 | $2');
str=str.replace(/[\s]*<th[\s]*([^<>]*?)[\s]*>([^\s])/gim, '\n! $1 |$2');
return str;
}
function autoEdExtraBreaks(str) { //MAIN FUNCTION describes list of fixes
//Usually unneeded BR tags from ends of image descriptions and wikilinks (]]), templates (}}), template parameters (|)
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\t\n ]*?)(\]\]|}}|\|)/gim, '$1$2');
//BR tag before a list item
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\s]*?[\n]\*)/gim, '$1');
//BR tag followed by at least two newlines
str = str.replace(/[\t ]*<[\s\/\.]*br[\s\/\.]*>[\t ]*([\n])[\t ]*([\n])/gim, '$1$2');
return str;
}
function autoEdLinks(str) { //MAIN FUNCTION describes list of fixes
str = str.replace(/\]\[/g, "] [");
//repair bad external links
str = str.replace(/\[?\[http:\/\/([^\]\n]*?)\]\]?/gi, "[http://$1]");
//str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]");
return str;
}
function autoEdFunctions() { //Activates individual modules when "auto ed" tab is clicked
var txt = document.editform.wpTextbox1;
txt.value = autoEdUnicodify(txt.value);
txt.value = autoEdISBN(txt.value);
txt.value = autoEdWhitespace(txt.value);
txt.value = autoEdUnicodeHex(txt.value);
txt.value = autoEdWikilinks(txt.value);
txt.value = autoEdHTMLtoWikitext(txt.value);
txt.value = autoEdHeadlines(txt.value);
txt.value = autoEdUnicodeControlChars(txt.value);
txt.value = autoEdTemplates(txt.value);
txt.value = autoEdTablestoWikitext(txt.value);
txt.value = autoEdExtraBreaks(txt.value);
txt.value = autoEdLinks(txt.value);
}
//This script does not function without additional "helper" modules!
//Please see [[Wikipedia:AutoEd]] for details on use.
//Initiates AutoEd
function autoEdExecute() {
if(!document.getElementById('wpTextbox1')) return;
// copy wikEd ([[User:Cacycle/wikEd.js]]) frame to wpTextbox1 textarea
// for compatibility with WikiEd
if (typeof wikEdUseWikEd !== 'undefined') {
if (wikEdUseWikEd === true) {
WikEdUpdateTextarea();
}
}
//alert/return if autoEdFunctions is not defined
if( typeof autoEdFunctions === 'undefined' ) {
alert('AutoEd/core.js: autoEdFunctions is undefined');
return;
}
autoEdFunctions();
autoEdEditSummary();
// copy wpTextbox1 textarea back to wikEd frame
// for compatibility with WikiEd
if (typeof wikEdUseWikEd !== 'undefined') {
if (wikEdUseWikEd === true) {
WikEdUpdateFrame();
}
}
}
//Adds Tag to edit summary textbox
function autoEdEditSummary() {
var txt = document.forms.editform.wpSummary;
var tag;
if( typeof autoEdTag === 'undefined' ) {
tag = '*திருத்தம்*';
} else {
tag = autoEdTag;
}
// Is the tag blank?
if( tag.match(/[^\s]/) ) {
// Has it already been tagged?
if( txt.value.indexOf(tag) == -1 ) {
// Append a pipe if necessary
if( txt.value.match(/[^\*\/\s][^\/\s]?\s*$/) ) {
txt.value += ' | ';
}
// Append our tag
txt.value += tag;
}
}
// Check 'This is a minor edit'
if( typeof autoEdMinor === 'undefined' || autoEdMinor ) {
document.forms.editform.wpMinoredit.checked = true;
}
// Click 'Show changes'
if( typeof autoEdClick === 'undefined' || autoEdClick ) {
document.forms.editform.wpDiff.click();
}
}
// Add "auto ed" tab and associate with actions
// Make sure the document is ready and our dependencies are loaded
$.when(
$.ready,
mw.loader.using(['mediawiki.util'])
).done(function () {
var $link;
//Execute AutoEd after call from "view mode"
if( mw.util.getParamValue('AutoEd') ) {
autoEdExecute();
}
// Set default values for any unset variables
if( typeof autoEdLinkHover === 'undefined' ) {
autoEdLinkHover = "Run AutoEd";
}
if( typeof autoEdLinkName === 'undefined' ) {
autoEdLinkName = "மாதவன்";
}
if( typeof autoEdLinkLocation === 'undefined' ) {
autoEdLinkLocation = "p-cactions";
}
// Add the "auto ed" tab
if( document.getElementById('ca-edit') ) {
var url = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', AutoEd: 'true', autosave: 'true' });
$link = $(mw.util.addPortletLink(
autoEdLinkLocation,
url,
autoEdLinkName,
'ca-AutoEd',
autoEdLinkHover,
'',
document.getElementById('ca-move')
));
if (template_autosave) document.editform.wpSave.click();
if( typeof document.forms.editform !== 'undefined' ) {
$link.on('click', function (e) {
e.preventDefault();
autoEdExecute();
});
}
}
});
//