Revision as of 22:21, 27 April 2009 view sourceAFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 edits Copy from User:Drilnoth/codefixer.js | Revision as of 22:24, 27 April 2009 view source AFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 edits Remove unneededNext edit → | ||
Line 1: | Line 1: | ||
// See ] for details. | |||
// Special thanks to ] and the creators of ] for their help with coding | |||
// <pre> | // <pre> | ||
Line 10: | Line 8: | ||
var txt = document.editform.wpTextbox1; | var txt = document.editform.wpTextbox1; | ||
var page_name = wgPageName.replace('_',' '); | var page_name = wgPageName.replace('_',' '); | ||
//replace | |||
//ISBNs | |||
txt.value = txt.value.replace(new RegExp('ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:', 'gi'), 'ISBN'); | txt.value = txt.value.replace(new RegExp('ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:', 'gi'), 'ISBN'); | ||
//HTML | |||
txt.value = txt.value.replace(/<(B|STRONG)*>(*)<\/\1*>/gi, "'''$2'''"); // Wikify <B> and <STRONG> | |||
txt.value = txt.value.replace(/<(I|EM)*>(*)<\/\1*>/gi, "''$2''"); // Wikify <I> and <EM> | |||
txt.value = txt.value.replace(/<+BR*>/gi, '<br />'); // Tag starts with a slash or period | |||
txt.value = txt.value.replace(/<*BR*+*>/gi, '<br />'); // Tag ends with a slash or period | |||
txt.value = txt.value.replace(/<*BR*>/gi, '<br>'); // Tag contains no slashes | |||
txt.value = txt.value.replace(/()*<*HR*>/gi, '$1----'); | |||
txt.value = txt.value.replace(/(.)<*HR*>/gi, '$1\n----'); | |||
txt.value = txt.value.replace(new RegExp('<REFERENCES/ >|<REFERENCES></REFERENCES>|<REFERENCES>|<REFERENCES/>', 'gi'), '<references />'); | |||
txt.value = txt.value.replace(/()*(<H*>)/gim, '$1\n$2'); // Make sure <H1>, ..., <H6> is after a newline | |||
txt.value = txt.value.replace(/(<\/H*>)*()/gim, '$1\n$2'); // Make sure </H1>, ..., </H6> is before a newline | |||
txt.value = txt.value.replace(/(^|)*<H1*>(*?)<\/H1*>*(|$)/gim, '$1=$2=$3'); | |||
txt.value = txt.value.replace(/(^|)*<H2*>(*?)<\/H2*>*(|$)/gim, '$1==$2==$3'); | |||
txt.value = txt.value.replace(/(^|)*<H3*>(*?)<\/H3*>*(|$)/gim, '$1===$2===$3'); | |||
txt.value = txt.value.replace(/(^|)*<H4*>(*?)<\/H4*>*(|$)/gim, '$1====$2====$3'); | |||
txt.value = txt.value.replace(/(^|)*<H5*>(*?)<\/H5*>*(|$)/gim, '$1=====$2=====$3'); | |||
txt.value = txt.value.replace(/(^|)*<H6*>(*?)<\/H6*>*(|$)/gim, '$1======$2======$3'); | |||
//WikiText | |||
txt.value = txt.value.replace(new RegExp(':==|: ==', 'gi'), '=='); | |||
txt.value = txt.value.replace(new RegExp('==\'\'\'|\'\'\' ==|\'\'\'==|== \'\'\'', 'gi'), '=='); | |||
// txt.value = txt.value.replace(new RegExp('\\[\\[IMAGE\:', 'gi'), '\[\[File\:'); NOTE: Consensus is unclear on this change, so I have commented it out to prevent confusion. | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKTIONARY\:', 'gi'), '\[\[wikt\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKINEWS\:', 'gi'), '\[\[n\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKIBOOKS\:', 'gi'), '\[\[b\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKIQUOTE\:', 'gi'), '\[\[q\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKISOURCE\:', 'gi'), '\[\[s\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKISPECIES\:', 'gi'), '\[\[species\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKIVERSITY\:', 'gi'), '\[\[v\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[WIKIMEDIA\:|\\[\\[FOUNDATION\:', 'gi'), '\[\[wmf\:'); | |||
txt.value = txt.value.replace(new RegExp('\\[\\[METAWIKIPEDIA\:', 'gi'), '\[\[m\:'); | |||
//Templates | |||
txt.value = txt.value.replace(new RegExp('\{\{REFERENCE|\{\{REFS|\{\{REFERENCE LIST|\{\{REFERENCES-SMALL|\{\{REFLINK|\{\{LISTAREF|\{\{REFERENCE LIST|\{\{REF-LIST', 'gi'), '\{\{Reflist'); | |||
txt.value = txt.value.replace(new RegExp('<div class=\'references-small\'>\n<references \/>\n<\/div>|<div class=\'references-small\'>\n<references\/>\n<\/div>', 'gi'), '\{\{Reflist\}\}'); | |||
txt.value = txt.value.replace(new RegExp('\{\{TEMPLATE:', 'gi'), '\{\{'); | |||
//References | |||
txt.value = txt.value.replace(new RegExp(' <ref>', 'gi'), '<ref>'); | |||
//Unicode control characters | |||
txt.value = txt.value.replace(new RegExp('\u200E|\uFEFF|\u200B', 'gi'), ''); | |||
//Self-referential links | |||
txt.value = txt.value.replace(new RegExp('\\\\]', 'gi'), '$1'); | |||
txt.value = txt.value.replace(new RegExp('\\\\|]*)\\]\\]', 'gi'), '$1'); | |||
//Correct some section header names, from ] | |||
if( !txt.value.match(/= ?See also ?=/) ) | |||
txt.value = txt.value.replace(/(== ?)(see also:?|related topics:?|related articles:?|internal links:?|also see:?)( ?==)/gi, "$1See also$3"); | |||
txt.value = txt.value.replace(/(== ?)(external links?:?|outside links?|web ?links?:?|exterior links?:?)( ?==)/gi, "$1External links$3"); | |||
txt.value = txt.value.replace(/(== ?)(references?:?)( ?==)/gi, "$1References$3"); | |||
txt.value = txt.value.replace(/(== ?)(sources?:?)( ?==)/gi, "$1Sources$3"); | |||
txt.value = txt.value.replace(/(== ?)(further readings?:?)( ?==)/gi, "$1Further reading$3"); | |||
//Link simplifier, from ] | |||
var m = txt.value.match(/\*?)\|(*?)\]\]/g); | |||
if (m) | |||
{ | |||
for (var i = 0; i < m.length; i++) | |||
{ | |||
var n_arr = m.toString().match(/\*?)\|(*?)\]\]/); | |||
var n = n_arr; | |||
var a = n_arr; | |||
var b = n_arr; | |||
if (b.indexOf(a) == 0 || b.indexOf(TurnFirstToLower(a)) == 0) | |||
{ | |||
var k = n.replace(/\\|]*?)\|(\1)(*?)\]\]/i, "]$3"); | |||
txt.value = txt.value.replace(n, k); | |||
} | |||
} | |||
} | |||
txt.value = txt.value.replace(/\\|]+)\|(\|]+)\]\](*)()/g, "]$4"); // ' // Help the syntax highlighter... | |||
//Greek symbols (capitalization matters on all) | |||
txt.value = txt.value.replace(new RegExp('\&Alpha\;', 'g'), 'Α'); | |||
txt.value = txt.value.replace(new RegExp('\&Beta\;', 'g'), 'Β'); | |||
txt.value = txt.value.replace(new RegExp('\&Gamma\;', 'g'), 'Γ'); | |||
txt.value = txt.value.replace(new RegExp('\&Delta\;', 'g'), 'Δ'); | |||
txt.value = txt.value.replace(new RegExp('\&Epsilon\;', 'g'), 'Ε'); | |||
txt.value = txt.value.replace(new RegExp('\&Zeta\;', 'g'), 'Ζ'); | |||
txt.value = txt.value.replace(new RegExp('\&Eta\;', 'g'), 'Η'); | |||
txt.value = txt.value.replace(new RegExp('\&Theta\;', 'g'), 'Θ'); | |||
txt.value = txt.value.replace(new RegExp('\&Ioeta\;', 'g'), 'Ι'); | |||
txt.value = txt.value.replace(new RegExp('\&Kappa\;', 'g'), 'Κ'); | |||
txt.value = txt.value.replace(new RegExp('\&Lambda\;', 'g'), 'Λ'); | |||
txt.value = txt.value.replace(new RegExp('\&Mu\;', 'g'), 'Μ'); | |||
txt.value = txt.value.replace(new RegExp('\&Nu\;', 'g'), 'Ν'); | |||
txt.value = txt.value.replace(new RegExp('\&Xi\;', 'g'), 'Ξ'); | |||
txt.value = txt.value.replace(new RegExp('\&Omicron\;', 'g'), 'Ο'); | |||
txt.value = txt.value.replace(new RegExp('\&Pi\;', 'g'), 'Π'); | |||
txt.value = txt.value.replace(new RegExp('\&Rho\;', 'g'), 'Ρ'); | |||
txt.value = txt.value.replace(new RegExp('\&Sigma\;', 'g'), 'Σ'); | |||
txt.value = txt.value.replace(new RegExp('\&Tau\;', 'g'), 'Τ'); | |||
txt.value = txt.value.replace(new RegExp('\&Upsilon\;', 'g'), 'Υ'); | |||
txt.value = txt.value.replace(new RegExp('\&Phi\;', 'g'), 'Φ'); | |||
txt.value = txt.value.replace(new RegExp('\&Chi\;', 'g'), 'Χ'); | |||
txt.value = txt.value.replace(new RegExp('\&Psi\;', 'g'), 'Ψ'); | |||
txt.value = txt.value.replace(new RegExp('\&Omega\;', 'g'), 'Ω'); | |||
txt.value = txt.value.replace(new RegExp('\&alpha\;', 'g'), 'α'); | |||
txt.value = txt.value.replace(new RegExp('\&beta\;', 'g'), 'β'); | |||
txt.value = txt.value.replace(new RegExp('\&gamma\;', 'g'), 'γ'); | |||
txt.value = txt.value.replace(new RegExp('\&delta\;', 'g'), 'δ'); | |||
txt.value = txt.value.replace(new RegExp('\&epsilon\;', 'g'), 'ε'); | |||
txt.value = txt.value.replace(new RegExp('\&zeta\;', 'g'), 'ζ'); | |||
txt.value = txt.value.replace(new RegExp('\&eta\;', 'g'), 'η'); | |||
txt.value = txt.value.replace(new RegExp('\&theta\;', 'g'), 'θ'); | |||
txt.value = txt.value.replace(new RegExp('\&ioeta\;', 'g'), 'ι'); | |||
txt.value = txt.value.replace(new RegExp('\&kappa\;', 'g'), 'κ'); | |||
txt.value = txt.value.replace(new RegExp('\&lambda\;', 'g'), 'λ'); | |||
txt.value = txt.value.replace(new RegExp('\&mu\;', 'g'), 'μ'); | |||
txt.value = txt.value.replace(new RegExp('\&nu\;', 'g'), 'ν'); | |||
txt.value = txt.value.replace(new RegExp('\&xi\;', 'g'), 'ξ'); | |||
txt.value = txt.value.replace(new RegExp('\&omicron\;', 'g'), 'ο'); | |||
txt.value = txt.value.replace(new RegExp('\&pi\;', 'g'), 'π'); | |||
txt.value = txt.value.replace(new RegExp('\&rho\;', 'g'), 'ρ'); | |||
txt.value = txt.value.replace(new RegExp('\&sigmaf\;', 'g'), 'ς'); | |||
txt.value = txt.value.replace(new RegExp('\&sigma\;', 'g'), 'σ'); | |||
txt.value = txt.value.replace(new RegExp('\&tau\;', 'g'), 'τ'); | |||
txt.value = txt.value.replace(new RegExp('\&upsilon\;', 'g'), 'υ'); | |||
txt.value = txt.value.replace(new RegExp('\&phi\;', 'g'), 'φ'); | |||
txt.value = txt.value.replace(new RegExp('\&chi\;', 'g'), 'χ'); | |||
txt.value = txt.value.replace(new RegExp('\&psi\;', 'g'), 'ψ'); | |||
txt.value = txt.value.replace(new RegExp('\&omega\;', 'g'), 'ω'); | |||
txt.value = txt.value.replace(new RegExp('\&thetasym\;', 'g'), 'ϑ'); | |||
txt.value = txt.value.replace(new RegExp('\&upsih\;', 'g'), 'ϒ'); | |||
txt.value = txt.value.replace(new RegExp('\&piv\;', 'g'), 'ϖ'); | |||
//Latin symbols (capitalization matters on all) | |||
txt.value = txt.value.replace(new RegExp('\À\;', 'g'), 'À'); | |||
txt.value = txt.value.replace(new RegExp('\Á\;', 'g'), 'Á'); | |||
txt.value = txt.value.replace(new RegExp('\Â\;', 'g'), 'Â'); | |||
txt.value = txt.value.replace(new RegExp('\Ã\;', 'g'), 'Ã'); | |||
txt.value = txt.value.replace(new RegExp('\Ä\;', 'g'), 'Ä'); | |||
txt.value = txt.value.replace(new RegExp('\Å\;', 'g'), 'Å'); | |||
txt.value = txt.value.replace(new RegExp('\Æ\;', 'g'), 'Æ'); | |||
txt.value = txt.value.replace(new RegExp('\Ç\;', 'g'), 'Ç'); | |||
txt.value = txt.value.replace(new RegExp('\È\;', 'g'), 'È'); | |||
txt.value = txt.value.replace(new RegExp('\É\;', 'g'), 'É'); | |||
txt.value = txt.value.replace(new RegExp('\Ê\;', 'g'), 'Ê'); | |||
txt.value = txt.value.replace(new RegExp('\Ë\;', 'g'), 'Ë'); | |||
txt.value = txt.value.replace(new RegExp('\Ì\;', 'g'), 'Ì'); | |||
txt.value = txt.value.replace(new RegExp('\Í\;', 'g'), 'Í'); | |||
txt.value = txt.value.replace(new RegExp('\Î\;', 'g'), 'Î'); | |||
txt.value = txt.value.replace(new RegExp('\Ï\;', 'g'), 'Ï'); | |||
txt.value = txt.value.replace(new RegExp('\&Eth\;', 'g'), 'Ð'); | |||
txt.value = txt.value.replace(new RegExp('\Ñ\;', 'g'), 'Ñ'); | |||
txt.value = txt.value.replace(new RegExp('\Ò\;', 'g'), 'Ò'); | |||
txt.value = txt.value.replace(new RegExp('\Ó\;', 'g'), 'Ó'); | |||
txt.value = txt.value.replace(new RegExp('\Ô\;', 'g'), 'Ô'); | |||
txt.value = txt.value.replace(new RegExp('\Õ\;', 'g'), 'Õ'); | |||
txt.value = txt.value.replace(new RegExp('\Ö\;', 'g'), 'Ö'); | |||
txt.value = txt.value.replace(new RegExp('\Ø\;', 'g'), 'Ø'); | |||
txt.value = txt.value.replace(new RegExp('\Ù\;', 'g'), 'Ù'); | |||
txt.value = txt.value.replace(new RegExp('\Ú\;', 'g'), 'Ú'); | |||
txt.value = txt.value.replace(new RegExp('\Û\;', 'g'), 'Û'); | |||
txt.value = txt.value.replace(new RegExp('\Ü\;', 'g'), 'Ü'); | |||
txt.value = txt.value.replace(new RegExp('\Ý\;', 'g'), 'Ý'); | |||
txt.value = txt.value.replace(new RegExp('\Þ\;', 'g'), 'Þ'); | |||
txt.value = txt.value.replace(new RegExp('\ß\;', 'g'), 'ß'); | |||
txt.value = txt.value.replace(new RegExp('\à\;', 'g'), 'à'); | |||
txt.value = txt.value.replace(new RegExp('\á\;', 'g'), 'á'); | |||
txt.value = txt.value.replace(new RegExp('\â\;', 'g'), 'â'); | |||
txt.value = txt.value.replace(new RegExp('\ã\;', 'g'), 'ã'); | |||
txt.value = txt.value.replace(new RegExp('\ä\;', 'g'), 'ä'); | |||
txt.value = txt.value.replace(new RegExp('\å\;', 'g'), 'å'); | |||
txt.value = txt.value.replace(new RegExp('\æ\;', 'g'), 'æ'); | |||
txt.value = txt.value.replace(new RegExp('\ç\;', 'g'), 'ç'); | |||
txt.value = txt.value.replace(new RegExp('\è\;', 'g'), 'è'); | |||
txt.value = txt.value.replace(new RegExp('\é\;', 'g'), 'é'); | |||
txt.value = txt.value.replace(new RegExp('\ê\;', 'g'), 'ê'); | |||
txt.value = txt.value.replace(new RegExp('\ë\;', 'g'), 'ë'); | |||
txt.value = txt.value.replace(new RegExp('\ì\;', 'g'), 'ì'); | |||
txt.value = txt.value.replace(new RegExp('\í\;', 'g'), 'í'); | |||
txt.value = txt.value.replace(new RegExp('\î\;', 'g'), 'î'); | |||
txt.value = txt.value.replace(new RegExp('\ï\;', 'g'), 'ï'); | |||
txt.value = txt.value.replace(new RegExp('\ð\;', 'g'), 'ð'); | |||
txt.value = txt.value.replace(new RegExp('\ñ\;', 'g'), 'ñ'); | |||
txt.value = txt.value.replace(new RegExp('\ò\;', 'g'), 'ò'); | |||
txt.value = txt.value.replace(new RegExp('\ó\;', 'g'), 'ó'); | |||
txt.value = txt.value.replace(new RegExp('\ô\;', 'g'), 'ô'); | |||
txt.value = txt.value.replace(new RegExp('\õ\;', 'g'), 'õ'); | |||
txt.value = txt.value.replace(new RegExp('\ö\;', 'g'), 'ö'); | |||
txt.value = txt.value.replace(new RegExp('\ø\;', 'g'), 'ø'); | |||
txt.value = txt.value.replace(new RegExp('\ù\;', 'g'), 'ù'); | |||
txt.value = txt.value.replace(new RegExp('\ú\;', 'g'), 'ú'); | |||
txt.value = txt.value.replace(new RegExp('\û\;', 'g'), 'û'); | |||
txt.value = txt.value.replace(new RegExp('\ü\;', 'g'), 'ü'); | |||
txt.value = txt.value.replace(new RegExp('\ý\;', 'g'), 'ý'); | |||
txt.value = txt.value.replace(new RegExp('\þ\;', 'g'), 'þ'); | |||
txt.value = txt.value.replace(new RegExp('\ÿ\;', 'g'), 'ÿ'); | |||
txt.value = txt.value.replace(new RegExp('\&OElig\;', 'g'), 'Œ'); | |||
txt.value = txt.value.replace(new RegExp('\&oelig\;', 'g'), 'œ'); | |||
txt.value = txt.value.replace(new RegExp('\&Scaron\;', 'g'), 'Š'); | |||
txt.value = txt.value.replace(new RegExp('\&scaron\;', 'g'), 'š'); | |||
txt.value = txt.value.replace(new RegExp('\&Yuml\;', 'g'), 'Ÿ'); | |||
txt.value = txt.value.replace(new RegExp('\&fnof\;', 'g'), 'ƒ'); | |||
//"Fake" Symbols | |||
txt.value = txt.value.replace(new RegExp('<==|<--', 'gi'), '←'); | |||
txt.value = txt.value.replace(new RegExp('==>', 'gi'), '→'); | |||
//XML and HTML Symbols | |||
txt.value = txt.value.replace(new RegExp('\&mdash\;', 'gi'), '—'); | |||
txt.value = txt.value.replace(new RegExp('\&ndash\;', 'gi'), '–'); | |||
txt.value = txt.value.replace(new RegExp('\&hellip\;', 'gi'), '...'); | |||
txt.value = txt.value.replace(new RegExp('\&dagger\;', 'g'), '†'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&Dagger\;', 'g'), '‡'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&plus\;', 'gi'), '+'); | |||
txt.value = txt.value.replace(new RegExp('\±\;', 'gi'), '±'); | |||
txt.value = txt.value.replace(new RegExp('\&minus\;', 'gi'), '−'); | |||
txt.value = txt.value.replace(new RegExp('\×\;', 'gi'), '×'); | |||
txt.value = txt.value.replace(new RegExp('\÷\;', 'gi'), '÷'); | |||
txt.value = txt.value.replace(new RegExp('\&ne\;', 'gi'), '≠'); | |||
txt.value = txt.value.replace(new RegExp('\&asymp\;', 'gi'), '≈'); | |||
// txt.value = txt.value.replace(new RegExp('\<\;', 'gi'), '<'); NOTE: Along with >, this has been commented out because it can break large amounts of code on some pages which discuss computer and web programming/scripting. | |||
txt.value = txt.value.replace(new RegExp('\&le\;', 'gi'), '≤'); | |||
// txt.value = txt.value.replace(new RegExp('\>\;', 'gi'), '>'); NOTE: Along with <, this has been commented out because it can break large amounts of code on some pages which discuss computer and web programming/scripting. | |||
txt.value = txt.value.replace(new RegExp('\&ge\;', 'gi'), '≥'); | |||
txt.value = txt.value.replace(new RegExp('\"\;', 'gi'), '"'); | |||
// txt.value = txt.value.replace(new RegExp('\&\;', 'gi'), '&'); WAY too many false positives in external links and display of raw code using "hacks" like &beta; to produce β without making it appear as the unicode character. | |||
txt.value = txt.value.replace(new RegExp('\&apos\;', 'gi'), '\''); | |||
txt.value = txt.value.replace(new RegExp('\¡\;', 'gi'), '¡'); | |||
txt.value = txt.value.replace(new RegExp('\¢\;', 'gi'), '¢'); | |||
txt.value = txt.value.replace(new RegExp('\£\;', 'gi'), '£'); | |||
txt.value = txt.value.replace(new RegExp('\¤\;', 'gi'), '¤'); | |||
txt.value = txt.value.replace(new RegExp('\¥\;', 'gi'), '¥'); | |||
txt.value = txt.value.replace(new RegExp('\¦\;', 'gi'), '¦'); | |||
txt.value = txt.value.replace(new RegExp('\§\;', 'gi'), '§'); | |||
txt.value = txt.value.replace(new RegExp('\¨\;', 'gi'), '¨'); | |||
txt.value = txt.value.replace(new RegExp('\©\;', 'gi'), '©'); | |||
txt.value = txt.value.replace(new RegExp('\ª\;', 'gi'), 'ª'); | |||
txt.value = txt.value.replace(new RegExp('\«\;', 'gi'), '«'); | |||
txt.value = txt.value.replace(new RegExp('\¬\;', 'gi'), '¬'); | |||
txt.value = txt.value.replace(new RegExp('\®\;', 'gi'), '®'); | |||
txt.value = txt.value.replace(new RegExp('\¯\;', 'gi'), '¯'); | |||
txt.value = txt.value.replace(new RegExp('\°\;', 'gi'), '°'); | |||
txt.value = txt.value.replace(new RegExp('\²\;', 'gi'), '²'); | |||
txt.value = txt.value.replace(new RegExp('\³\;', 'gi'), '³'); | |||
txt.value = txt.value.replace(new RegExp('\´\;', 'gi'), '´'); | |||
txt.value = txt.value.replace(new RegExp('\µ\;', 'gi'), 'µ'); | |||
txt.value = txt.value.replace(new RegExp('\¶\;', 'gi'), '¶'); | |||
txt.value = txt.value.replace(new RegExp('\·\;', 'gi'), '•'); | |||
txt.value = txt.value.replace(new RegExp('\¸\;', 'gi'), '¸'); | |||
txt.value = txt.value.replace(new RegExp('\¹\;', 'gi'), '¹'); | |||
txt.value = txt.value.replace(new RegExp('\º\;', 'gi'), 'º'); | |||
txt.value = txt.value.replace(new RegExp('\»\;', 'gi'), '»'); | |||
txt.value = txt.value.replace(new RegExp('\¼\;', 'gi'), '¼'); | |||
txt.value = txt.value.replace(new RegExp('\½\;', 'gi'), '½'); | |||
txt.value = txt.value.replace(new RegExp('\¾\;', 'gi'), '¾'); | |||
txt.value = txt.value.replace(new RegExp('\¿\;', 'gi'), '¿'); | |||
txt.value = txt.value.replace(new RegExp('\&circ\;', 'gi'), 'ˆ'); | |||
txt.value = txt.value.replace(new RegExp('\&tilde\;', 'gi'), '˜'); | |||
txt.value = txt.value.replace(new RegExp('\&lsquo\;', 'gi'), '‘'); | |||
txt.value = txt.value.replace(new RegExp('\&rsquo\;', 'gi'), '’'); | |||
txt.value = txt.value.replace(new RegExp('\&sbquo\;', 'gi'), '‚'); | |||
txt.value = txt.value.replace(new RegExp('\&ldquo\;', 'gi'), '“'); | |||
txt.value = txt.value.replace(new RegExp('\&rdquo\;', 'gi'), '”'); | |||
txt.value = txt.value.replace(new RegExp('\&bdquo\;', 'gi'), '„'); | |||
txt.value = txt.value.replace(new RegExp('\&bull\;', 'gi'), '•'); | |||
txt.value = txt.value.replace(new RegExp('\&permil\;', 'gi'), '‰'); | |||
txt.value = txt.value.replace(new RegExp('\&prime\;', 'g'), '′'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&Prime\;', 'g'), '″'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&lsaquo\;', 'gi'), '‹'); | |||
txt.value = txt.value.replace(new RegExp('\&rsaquo\;', 'gi'), '›'); | |||
txt.value = txt.value.replace(new RegExp('\&oline\;', 'gi'), '‾'); | |||
txt.value = txt.value.replace(new RegExp('\&frasl\;', 'gi'), '⁄'); | |||
txt.value = txt.value.replace(new RegExp('\&euro\;', 'gi'), '€'); | |||
txt.value = txt.value.replace(new RegExp('\&image\;', 'gi'), 'ℑ'); | |||
txt.value = txt.value.replace(new RegExp('\&weierp\;', 'gi'), '℘'); | |||
txt.value = txt.value.replace(new RegExp('\&real\;', 'gi'), 'ℜ'); | |||
txt.value = txt.value.replace(new RegExp('\&trade\;', 'gi'), '™'); | |||
txt.value = txt.value.replace(new RegExp('\&alefsym\;', 'gi'), 'ℵ'); | |||
txt.value = txt.value.replace(new RegExp('\&larr\;', 'g'), '←'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&rarr\;', 'g'), '→'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&uarr\;', 'g'), '↑'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&darr\;', 'g'), '↓'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&lArr\;', 'g'), '⇐'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&rArr\;', 'g'), '⇒'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&uArr\;', 'g'), '⇑'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&dArr\;', 'g'), '⇓'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&harr\;', 'g'), '↔'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&hArr\;', 'g'), '⇔'); //Capitalization matters | |||
txt.value = txt.value.replace(new RegExp('\&crarr\;', 'gi'), '↵'); | |||
txt.value = txt.value.replace(new RegExp('\&forall\;', 'gi'), '∀'); | |||
txt.value = txt.value.replace(new RegExp('\&part\;', 'gi'), '∂'); | |||
txt.value = txt.value.replace(new RegExp('\&exist\;', 'gi'), '∃'); | |||
txt.value = txt.value.replace(new RegExp('\&empty\;', 'gi'), '∅'); | |||
txt.value = txt.value.replace(new RegExp('\&nabla\;', 'gi'), '∇'); | |||
txt.value = txt.value.replace(new RegExp('\&isin\;', 'gi'), '∈'); | |||
txt.value = txt.value.replace(new RegExp('\¬in\;', 'gi'), '∉'); | |||
txt.value = txt.value.replace(new RegExp('\&ni\;', 'gi'), '∋'); | |||
txt.value = txt.value.replace(new RegExp('\&prod\;', 'gi'), '∏'); | |||
txt.value = txt.value.replace(new RegExp('\&sum\;', 'gi'), '∑'); | |||
txt.value = txt.value.replace(new RegExp('\&lowast\;', 'gi'), '∗'); | |||
txt.value = txt.value.replace(new RegExp('\&radic\;', 'gi'), '√'); | |||
txt.value = txt.value.replace(new RegExp('\&prop\;', 'gi'), '∝'); | |||
txt.value = txt.value.replace(new RegExp('\&infin\;', 'gi'), '∞'); | |||
txt.value = txt.value.replace(new RegExp('\&ang\;', 'gi'), '∠'); | |||
txt.value = txt.value.replace(new RegExp('\&and\;', 'gi'), '∧'); | |||
txt.value = txt.value.replace(new RegExp('\&or\;', 'gi'), '∨'); | |||
txt.value = txt.value.replace(new RegExp('\&cap\;', 'gi'), '∩'); | |||
txt.value = txt.value.replace(new RegExp('\&cup\;', 'gi'), '∪'); | |||
txt.value = txt.value.replace(new RegExp('\&int\;', 'gi'), '∫'); | |||
txt.value = txt.value.replace(new RegExp('\&there4\;', 'gi'), '∴'); | |||
txt.value = txt.value.replace(new RegExp('\&sim\;', 'gi'), '∼'); | |||
txt.value = txt.value.replace(new RegExp('\&cong\;', 'gi'), '≅'); | |||
txt.value = txt.value.replace(new RegExp('\&sub\;', 'gi'), '⊂'); | |||
txt.value = txt.value.replace(new RegExp('\&sup\;', 'gi'), '⊃'); | |||
txt.value = txt.value.replace(new RegExp('\&nsub\;', 'gi'), '⊄'); | |||
txt.value = txt.value.replace(new RegExp('\&sube\;', 'gi'), '⊆'); | |||
txt.value = txt.value.replace(new RegExp('\&supe\;', 'gi'), '⊇'); | |||
txt.value = txt.value.replace(new RegExp('\&oplus\;', 'gi'), '⊕'); | |||
txt.value = txt.value.replace(new RegExp('\&otimes\;', 'gi'), '⊗'); | |||
txt.value = txt.value.replace(new RegExp('\&perp\;', 'gi'), '⊥'); | |||
txt.value = txt.value.replace(new RegExp('\&sdot\;', 'gi'), '⋅'); | |||
txt.value = txt.value.replace(new RegExp('\&lceil\;', 'gi'), '⌈'); | |||
txt.value = txt.value.replace(new RegExp('\&rceil\;', 'gi'), '⌉'); | |||
txt.value = txt.value.replace(new RegExp('\&lfloor\;', 'gi'), '⌊'); | |||
txt.value = txt.value.replace(new RegExp('\&rfloor\;', 'gi'), '⌋'); | |||
txt.value = txt.value.replace(new RegExp('\&lang\;', 'gi'), '〈'); | |||
txt.value = txt.value.replace(new RegExp('\&rang\;', 'gi'), '〉'); | |||
txt.value = txt.value.replace(new RegExp('\&loz\;', 'gi'), '◊'); | |||
txt.value = txt.value.replace(new RegExp('\&spades\;', 'gi'), '♠'); | |||
txt.value = txt.value.replace(new RegExp('\&clubs\;', 'gi'), '♣'); | |||
txt.value = txt.value.replace(new RegExp('\&hearts\;', 'gi'), '♥'); | |||
txt.value = txt.value.replace(new RegExp('\&diams\;', 'gi'), '♦'); | |||
} | |||
function codefixerplus() { //ADVANCED FUNCTION describes list of fixes when using CodeFixerPlus | |||
var txt = document.editform.wpTextbox1; | |||
//replace | |||
//HTML tables, from PlastikSpork's script | |||
txt.value=txt.value.replace(/()<*BR*>/gim, '$1*'); | |||
txt.value=txt.value.replace(/(<table|<\/tr|<\/td|<\/th)(*>)*()/gim, '$1$2\n$3'); | |||
txt.value=txt.value.replace(/<table(*)>()/gim, '{|$1$2'); | |||
txt.value=txt.value.replace(/*<\/table>/gi, '\n|}'); | |||
txt.value=txt.value.replace(/<\/td>*<td>/gim, '||'); | |||
txt.value=txt.value.replace(/<\/th>*<th>/gim, '!!'); | |||
txt.value=txt.value.replace(/<\/td>*<td (*)>/gim, '|| $1 |'); | |||
txt.value=txt.value.replace(/<\/th>*<th (*)>/gim, '!! $1 |'); | |||
txt.value=txt.value.replace(/<tr>*/gim, '|-\n'); | |||
txt.value=txt.value.replace(/<tr (*)>*/gim, '|- $1'); | |||
txt.value=txt.value.replace(/*<td>/gim, '\n|'); | |||
txt.value=txt.value.replace(/*<td (*)>/gim, '\n| $1 |'); | |||
txt.value=txt.value.replace(/*<th>/gim, '\n!'); | |||
txt.value=txt.value.replace(/*<th (*)>/gim, '\n! $1 |'); | |||
txt.value=txt.value.replace(/<\/(td|th)>*<\/tr>*()/gim, '$2'); | |||
} | |||
//turns first character to lowercase, from ] | |||
function TurnFirstToLower(input) { | |||
if (input != "") | |||
{ | |||
var temp = input.substr(0, 1); | |||
return temp.toLowerCase() + input.substr(1, input.length); | |||
} | |||
else | |||
return ""; | |||
} | } | ||
Line 384: | Line 18: | ||
var txt = document.editform.wpSummary; | var txt = document.editform.wpSummary; | ||
var summary = "Code cleaned up using ]"; | var summary = "Code cleaned up using ]"; | ||
if (txt.value.indexOf(summary) == -1) { | |||
if (txt.value.match(/?\s*$/)) { | |||
txt.value += " | "; | |||
} | |||
txt.value += summary; | |||
} | |||
document.editform.wpMinoredit.checked = codefixerMinor; | |||
document.editform.wpDiff.click() | |||
} | |||
function codefixerplusstartinedit() { //Initiates CodeFixer if you are already in edit mode | |||
codefixer(); | |||
codefixerplus(); | |||
// Add a tag to the summary box | |||
var txt = document.editform.wpSummary; | |||
var summary = "Code cleaned up using ]"; | |||
if (txt.value.indexOf(summary) == -1) { | if (txt.value.indexOf(summary) == -1) { | ||
if (txt.value.match(/?\s*$/)) { | if (txt.value.match(/?\s*$/)) { | ||
Line 419: | Line 35: | ||
codefixer(); | codefixer(); | ||
document.getElementById('wpSummary').value += 'Code cleaned up using ]'; | document.getElementById('wpSummary').value += 'Code cleaned up using ]'; | ||
document.editform.wpMinoredit.checked = codefixerMinor; | |||
document.editform.wpDiff.click() | |||
} | |||
if(queryString('codefixerplusstartfromview')) addOnloadHook(function() { codefixerplusstartfromview(); }) //Part of next function | |||
function codefixerplusstartfromview() { //Initiates CodeFixerPlus if you are viewing the article without currently editing it | |||
var txt = document.getElementById('wpTextbox1'); | |||
if(!txt) return; | |||
codefixer(); | |||
codefixerplus(); | |||
document.getElementById('wpSummary').value += 'Code cleaned up using ]'; | |||
document.editform.wpMinoredit.checked = codefixerMinor; | document.editform.wpMinoredit.checked = codefixerMinor; | ||
document.editform.wpDiff.click() | document.editform.wpDiff.click() | ||
Line 450: | Line 55: | ||
if(document.forms.editform) { | if(document.forms.editform) { | ||
addPortletLink('p-cactions', 'javascript:codefixerstartinedit()', 'fix code', 'ca-codefixeredit', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); | addPortletLink('p-cactions', 'javascript:codefixerstartinedit()', 'fix code', 'ca-codefixeredit', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); | ||
addPortletLink('p-cactions', 'javascript:codefixerplusstartinedit()', 'fix code (+)', 'ca-codefixerplusedit', 'Cleans up more advanced errors in code and syntax', '', document.getElementById('ca-move')); | |||
} //End editform if | } //End editform if | ||
if(wgAction == "view"){ | if(wgAction == "view"){ | ||
var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit'; | var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit'; | ||
addPortletLink('p-cactions',url + '&codefixerstartfromview=true', 'fix code','ca-codefixerview', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); | addPortletLink('p-cactions',url + '&codefixerstartfromview=true', 'fix code','ca-codefixerview', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); | ||
addPortletLink('p-cactions',url + '&codefixerplusstartfromview=true', 'fix code (+)','ca-codefixerplusview', 'Cleans up more advanced errors in code and syntax', '', document.getElementById('ca-move')); | |||
} //End pageview if | } //End pageview if | ||
}//End namespace if | }//End namespace if |
Revision as of 22:24, 27 April 2009
//
if( typeof( codefixerMinor ) == 'undefined' ) { //CONFIGURATION codefixerMinor = true; } function codefixer() { //MAIN FUNCTION describes list of fixes var txt = document.editform.wpTextbox1; var page_name = wgPageName.replace('_',' '); txt.value = txt.value.replace(new RegExp('ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:', 'gi'), 'ISBN'); } function codefixerstartinedit() { //Initiates CodeFixer if you are already in edit mode codefixer(); // Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "Code cleaned up using ]"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/?\s*$/)) { txt.value += " | "; } txt.value += summary; } document.editform.wpMinoredit.checked = codefixerMinor; document.editform.wpDiff.click() } if(queryString('codefixerstartfromview')) addOnloadHook(function() { codefixerstartfromview(); }) //Part of next function function codefixerstartfromview() { //Initiates CodeFixer if you are viewing the article without currently editing it var txt = document.getElementById('wpTextbox1'); if(!txt) return; codefixer(); document.getElementById('wpSummary').value += 'Code cleaned up using ]'; document.editform.wpMinoredit.checked = codefixerMinor; document.editform.wpDiff.click() } function queryString(p) { //Allows URI to be properly decoded so that codefixerstartfromview() works properly var re = RegExp('' + p + '=(*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches); } catch (e) { } } return null; } addOnloadHook(function () { //Adds "fix code" and "fix code (+)" tabs to page. if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "Image" || wgCanonicalNamespace == "File" || wgCanonicalNamespace == "User" || wgCanonicalNamespace == "Template" || wgCanonicalNamespace == "Project" || wgCanonicalNamespace == "Portal"){ if(document.forms.editform) { addPortletLink('p-cactions', 'javascript:codefixerstartinedit()', 'fix code', 'ca-codefixeredit', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); } //End editform if if(wgAction == "view"){ var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit'; addPortletLink('p-cactions',url + '&codefixerstartfromview=true', 'fix code','ca-codefixerview', 'Cleans up common errors in code and syntax', '', document.getElementById('ca-move')); } //End pageview if }//End namespace if }); //