Misplaced Pages

:AutoEd/core.js: Difference between revisions - Misplaced Pages

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< Misplaced Pages:AutoEd Browse history interactivelyContent deleted Content added
Revision as of 22:21, 27 April 2009 view sourceAFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 edits Copy from User:Drilnoth/codefixer.js  Latest revision as of 16:55, 28 December 2024 view source Pppery (talk | contribs)Interface administrators, Administrators100,463 edits Per request 
(37 intermediate revisions by 6 users not shown)
Line 1: Line 1:
//This script does not function without additional "helper" modules!
// See ] for details.
//Please see ] for details on use.
// Special thanks to ] and the creators of ] for their help with coding

// <pre>
//Initiates AutoEd
function autoEdExecute() {
if( typeof( codefixerMinor ) == 'undefined' ) { //CONFIGURATION
if(!document.getElementById('wpTextbox1')) return;
codefixerMinor = true;

// copy wikEd (]) 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 codefixer() { //MAIN FUNCTION describes list of fixes
function autoEdEditSummary() {
var txt = document.editform.wpTextbox1;
var txt = document.forms.editform.wpSummary;
var page_name = wgPageName.replace('_',' ');
var tag;

//replace
if( typeof autoEdTag === 'undefined' ) {
//ISBNs
tag = 'Cleaned up using ]';
txt.value = txt.value.replace(new RegExp('ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:', 'gi'), 'ISBN');
} else {
//HTML tag = autoEdTag;
}
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>
// Is the tag blank?
txt.value = txt.value.replace(/<+BR*>/gi, '<br />'); // Tag starts with a slash or period
if( tag.match(//) ) {
txt.value = txt.value.replace(/<*BR*+*>/gi, '<br />'); // Tag ends with a slash or period
// Has it already been tagged?
txt.value = txt.value.replace(/<*BR*>/gi, '<br>'); // Tag contains no slashes
txt.value = txt.value.replace(/()*<*HR*>/gi, '$1----'); if( txt.value.indexOf(tag) == -1 ) {
// Append a pipe if necessary
txt.value = txt.value.replace(/(.)<*HR*>/gi, '$1\n----');
if( txt.value.match(/?\s*$/) ) {
txt.value = txt.value.replace(new RegExp('<REFERENCES/ >|<REFERENCES></REFERENCES>|<REFERENCES>|<REFERENCES/>', 'gi'), '<references />');
txt.value += ' | ';
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
// Append our tag
txt.value = txt.value.replace(/(^|)*<H1*>(*?)<\/H1*>*(|$)/gim, '$1=$2=$3');
txt.value += tag;
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('\&Agrave\;', 'g'), 'À');
txt.value = txt.value.replace(new RegExp('\&Aacute\;', 'g'), 'Á');
txt.value = txt.value.replace(new RegExp('\&Acirc\;', 'g'), 'Â');
txt.value = txt.value.replace(new RegExp('\&Atilde\;', 'g'), 'Ã');
txt.value = txt.value.replace(new RegExp('\&Auml\;', 'g'), 'Ä');
txt.value = txt.value.replace(new RegExp('\&Aring\;', 'g'), 'Å');
txt.value = txt.value.replace(new RegExp('\&AElig\;', 'g'), 'Æ');
txt.value = txt.value.replace(new RegExp('\&Ccedil\;', 'g'), 'Ç');
txt.value = txt.value.replace(new RegExp('\&Egrave\;', 'g'), 'È');
txt.value = txt.value.replace(new RegExp('\&Eacute\;', 'g'), 'É');
txt.value = txt.value.replace(new RegExp('\&Ecirc\;', 'g'), 'Ê');
txt.value = txt.value.replace(new RegExp('\&Euml\;', 'g'), 'Ë');
txt.value = txt.value.replace(new RegExp('\&Igrave\;', 'g'), 'Ì');
txt.value = txt.value.replace(new RegExp('\&Iacute\;', 'g'), 'Í');
txt.value = txt.value.replace(new RegExp('\&Icirc\;', 'g'), 'Î');
txt.value = txt.value.replace(new RegExp('\&Iuml\;', 'g'), 'Ï');
txt.value = txt.value.replace(new RegExp('\&Eth\;', 'g'), 'Ð');
txt.value = txt.value.replace(new RegExp('\&Ntilde\;', 'g'), 'Ñ');
txt.value = txt.value.replace(new RegExp('\&Ograve\;', 'g'), 'Ò');
txt.value = txt.value.replace(new RegExp('\&Oacute\;', 'g'), 'Ó');
txt.value = txt.value.replace(new RegExp('\&Ocirc\;', 'g'), 'Ô');
txt.value = txt.value.replace(new RegExp('\&Otilde\;', 'g'), 'Õ');
txt.value = txt.value.replace(new RegExp('\&Ouml\;', 'g'), 'Ö');
txt.value = txt.value.replace(new RegExp('\&Oslash\;', 'g'), 'Ø');
txt.value = txt.value.replace(new RegExp('\&Ugrave\;', 'g'), 'Ù');
txt.value = txt.value.replace(new RegExp('\&Uacute\;', 'g'), 'Ú');
txt.value = txt.value.replace(new RegExp('\&Ucirc\;', 'g'), 'Û');
txt.value = txt.value.replace(new RegExp('\&Uuml\;', 'g'), 'Ü');
txt.value = txt.value.replace(new RegExp('\&Yacute\;', 'g'), 'Ý');
txt.value = txt.value.replace(new RegExp('\&THORN\;', 'g'), 'Þ');
txt.value = txt.value.replace(new RegExp('\&szlig\;', 'g'), 'ß');
txt.value = txt.value.replace(new RegExp('\&agrave\;', 'g'), 'à');
txt.value = txt.value.replace(new RegExp('\&aacute\;', 'g'), 'á');
txt.value = txt.value.replace(new RegExp('\&acirc\;', 'g'), 'â');
txt.value = txt.value.replace(new RegExp('\&atilde\;', 'g'), 'ã');
txt.value = txt.value.replace(new RegExp('\&auml\;', 'g'), 'ä');
txt.value = txt.value.replace(new RegExp('\&aring\;', 'g'), 'å');
txt.value = txt.value.replace(new RegExp('\&aelig\;', 'g'), 'æ');
txt.value = txt.value.replace(new RegExp('\&ccedil\;', 'g'), 'ç');
txt.value = txt.value.replace(new RegExp('\&egrave\;', 'g'), 'è');
txt.value = txt.value.replace(new RegExp('\&eacute\;', 'g'), 'é');
txt.value = txt.value.replace(new RegExp('\&ecirc\;', 'g'), 'ê');
txt.value = txt.value.replace(new RegExp('\&euml\;', 'g'), 'ë');
txt.value = txt.value.replace(new RegExp('\&igrave\;', 'g'), 'ì');
txt.value = txt.value.replace(new RegExp('\&iacute\;', 'g'), 'í');
txt.value = txt.value.replace(new RegExp('\&icirc\;', 'g'), 'î');
txt.value = txt.value.replace(new RegExp('\&iuml\;', 'g'), 'ï');
txt.value = txt.value.replace(new RegExp('\&eth\;', 'g'), 'ð');
txt.value = txt.value.replace(new RegExp('\&ntilde\;', 'g'), 'ñ');
txt.value = txt.value.replace(new RegExp('\&ograve\;', 'g'), 'ò');
txt.value = txt.value.replace(new RegExp('\&oacute\;', 'g'), 'ó');
txt.value = txt.value.replace(new RegExp('\&ocirc\;', 'g'), 'ô');
txt.value = txt.value.replace(new RegExp('\&otilde\;', 'g'), 'õ');
txt.value = txt.value.replace(new RegExp('\&ouml\;', 'g'), 'ö');
txt.value = txt.value.replace(new RegExp('\&oslash\;', 'g'), 'ø');
txt.value = txt.value.replace(new RegExp('\&ugrave\;', 'g'), 'ù');
txt.value = txt.value.replace(new RegExp('\&uacute\;', 'g'), 'ú');
txt.value = txt.value.replace(new RegExp('\&ucirc\;', 'g'), 'û');
txt.value = txt.value.replace(new RegExp('\&uuml\;', 'g'), 'ü');
txt.value = txt.value.replace(new RegExp('\&yacute\;', 'g'), 'ý');
txt.value = txt.value.replace(new RegExp('\&thorn\;', 'g'), 'þ');
txt.value = txt.value.replace(new RegExp('\&yuml\;', '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('\&plusmn\;', 'gi'), '±');
txt.value = txt.value.replace(new RegExp('\&minus\;', 'gi'), '−');
txt.value = txt.value.replace(new RegExp('\&times\;', 'gi'), '×');
txt.value = txt.value.replace(new RegExp('\&divide\;', '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('\&lt\;', 'gi'), '<'); NOTE: Along with &gt;, 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('\&gt\;', 'gi'), '>'); NOTE: Along with &lt;, 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('\&quot\;', 'gi'), '"');
// txt.value = txt.value.replace(new RegExp('\&amp\;', 'gi'), '&'); WAY too many false positives in external links and display of raw code using "hacks" like &amp;beta; to produce &beta; without making it appear as the unicode character.
txt.value = txt.value.replace(new RegExp('\&apos\;', 'gi'), '\'');
txt.value = txt.value.replace(new RegExp('\&iexcl\;', 'gi'), '¡');
txt.value = txt.value.replace(new RegExp('\&cent\;', 'gi'), '¢');
txt.value = txt.value.replace(new RegExp('\&pound\;', 'gi'), '£');
txt.value = txt.value.replace(new RegExp('\&curren\;', 'gi'), '¤');
txt.value = txt.value.replace(new RegExp('\&yen\;', 'gi'), '¥');
txt.value = txt.value.replace(new RegExp('\&brvbar\;', 'gi'), '¦');
txt.value = txt.value.replace(new RegExp('\&sect\;', 'gi'), '§');
txt.value = txt.value.replace(new RegExp('\&uml\;', 'gi'), '¨');
txt.value = txt.value.replace(new RegExp('\&copy\;', 'gi'), '©');
txt.value = txt.value.replace(new RegExp('\&ordf\;', 'gi'), 'ª');
txt.value = txt.value.replace(new RegExp('\&laquo\;', 'gi'), '«');
txt.value = txt.value.replace(new RegExp('\&not\;', 'gi'), '¬');
txt.value = txt.value.replace(new RegExp('\&reg\;', 'gi'), '®');
txt.value = txt.value.replace(new RegExp('\&macr\;', 'gi'), '¯');
txt.value = txt.value.replace(new RegExp('\&deg\;', 'gi'), '°');
txt.value = txt.value.replace(new RegExp('\&sup2\;', 'gi'), '²');
txt.value = txt.value.replace(new RegExp('\&sup3\;', 'gi'), '³');
txt.value = txt.value.replace(new RegExp('\&acute\;', 'gi'), '´');
txt.value = txt.value.replace(new RegExp('\&micro\;', 'gi'), 'µ');
txt.value = txt.value.replace(new RegExp('\&para\;', 'gi'), '¶');
txt.value = txt.value.replace(new RegExp('\&middot\;', 'gi'), '•');
txt.value = txt.value.replace(new RegExp('\&cedil\;', 'gi'), '¸');
txt.value = txt.value.replace(new RegExp('\&sup1\;', 'gi'), '¹');
txt.value = txt.value.replace(new RegExp('\&ordm\;', 'gi'), 'º');
txt.value = txt.value.replace(new RegExp('\&raquo\;', 'gi'), '»');
txt.value = txt.value.replace(new RegExp('\&frac14\;', 'gi'), '¼');
txt.value = txt.value.replace(new RegExp('\&frac12\;', 'gi'), '½');
txt.value = txt.value.replace(new RegExp('\&frac34\;', 'gi'), '¾');
txt.value = txt.value.replace(new RegExp('\&iquest\;', '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('\&notin\;', '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 "";
// Check 'This is a minor edit'
if(!document.forms.editform || !document.forms.editform.wpMinoredit || !document.forms.editform.wpDiff) {
return;
}

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
function codefixerstartinedit() { //Initiates CodeFixer if you are already in edit mode
// Make sure the document is ready and our dependencies are loaded
codefixer();
$.when(
$.ready,
// Add a tag to the summary box
mw.loader.using()
var txt = document.editform.wpSummary;
).done(function () {
var summary = "Code cleaned up using ]";
var $link;
if (txt.value.indexOf(summary) == -1) {

if (txt.value.match(/?\s*$/)) {
//Execute AutoEd after call from "view mode"
txt.value += " | ";
if( mw.util.getParamValue('AutoEd') ) {
}
autoEdExecute();
txt.value += summary;
} }

// Set default values for any unset variables
document.editform.wpMinoredit.checked = codefixerMinor;
if( typeof autoEdLinkHover === 'undefined' ) {
document.editform.wpDiff.click()
autoEdLinkHover = "Run AutoEd";
}
}
if( typeof autoEdLinkName === 'undefined' ) {
function codefixerplusstartinedit() { //Initiates CodeFixer if you are already in edit mode
autoEdLinkName = "auto ed";
codefixer();
}
codefixerplus();
if( typeof autoEdLinkLocation === 'undefined' ) {
autoEdLinkLocation = "p-cactions";
// Add a tag to the summary box
}
var txt = document.editform.wpSummary;

var summary = "Code cleaned up using ]";
// Add the "auto ed" tab
if (txt.value.indexOf(summary) == -1) {
if( document.getElementById( 'ca-edit' ) && !document.getElementById( 'ca-AutoEd' ) ) {
if (txt.value.match(/?\s*$/)) {
var url = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', AutoEd: 'true' });
txt.value += " | ";
$link = $(mw.util.addPortletLink(
}
autoEdLinkLocation,
txt.value += summary;
url,
}
autoEdLinkName,
'ca-AutoEd',
document.editform.wpMinoredit.checked = codefixerMinor;
autoEdLinkHover,
document.editform.wpDiff.click()
'',
}
document.getElementById('ca-move')
));
if(queryString('codefixerstartfromview')) addOnloadHook(function() { codefixerstartfromview(); }) //Part of next function
if( typeof document.forms.editform !== 'undefined' ) {
function codefixerstartfromview() { //Initiates CodeFixer if you are viewing the article without currently editing it
$link.on('click', function (e) {
var txt = document.getElementById('wpTextbox1');
e.preventDefault();
if(!txt) return;
codefixer(); autoEdExecute();
});
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.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'));
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
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'));
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 namespace if
}); });
//</pre>

Latest revision as of 16:55, 28 December 2024

//This script does not function without additional "helper" modules!
//Please see ] for details on use.

//Initiates AutoEd
function autoEdExecute() {
 if(!document.getElementById('wpTextbox1')) return;

 // copy wikEd (]) 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 = 'Cleaned up using ]';
 } else {
  tag = autoEdTag;
 }

 // Is the tag blank?
 if( tag.match(//) ) {
  // Has it already been tagged?
  if( txt.value.indexOf(tag) == -1 ) {
   // Append a pipe if necessary
   if( txt.value.match(/?\s*$/) ) {
    txt.value += ' | ';
   }
   // Append our tag
   txt.value += tag;
  }
 }

 // Check 'This is a minor edit'
 if(!document.forms.editform || !document.forms.editform.wpMinoredit || !document.forms.editform.wpDiff) {
	 return;
 }

 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()
).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 = "auto ed";
 }
 if( typeof autoEdLinkLocation === 'undefined' ) {
  autoEdLinkLocation = "p-cactions";
 }

 // Add the "auto ed" tab
if( document.getElementById( 'ca-edit' ) && !document.getElementById( 'ca-AutoEd' ) ) {
  var url = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', AutoEd: 'true' });
  $link = $(mw.util.addPortletLink(
   autoEdLinkLocation,
   url,
   autoEdLinkName,
   'ca-AutoEd',
   autoEdLinkHover,
   '',
   document.getElementById('ca-move')
  ));
  if( typeof document.forms.editform !== 'undefined' ) {
   $link.on('click', function (e) {
    e.preventDefault();
    autoEdExecute();
   });
  }
 }

});