MediaWiki:Gadget-AutoEd.js
Z Nonsensopedii, polskiej encyklopedii humoru
Uwaga: aby zobaczyć zmiany po zapisaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5 lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer: Przytrzymaj Ctrl jednocześnie klikając Odśwież lub naciśnij klawisze Ctrl+F5
- Konqueror: Kliknij polecenie Odśwież lub naciśnij klawisz F5
- Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
//<pre><nowiki>
//This script does not function without additional "helper" modules!
//Please see [[Wikipedia:AutoEd]] for details on use.
//Initiates AutoEd
window.autoEdExecute = function() {
if(!document.getElementById('wpTextbox1')) return;
//alert/return if autoEdFunctions is not defined
if( typeof( autoEdFunctions ) == 'undefined' ) {
alert('AutoEd/core.js: autoEdFunctions is undefined');
return;
}
autoEdFunctions();
autoEdEditSummary();
}
//Adds Tag to edit summary textbox
window.autoEdEditSummary = function() {
var txt = document.forms.editform.wpSummary;
if( typeof( autoEdTag ) == 'undefined' ) {
var tag = "Poprawki same się robią…";
} else {
var 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 ) {
wpDiff.click();
}
}
//Allows URI to be properly decoded for AutoEd in View Mode
window.autoEdQueryString = function(p) {
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches[1]);
} catch (e) {
}
}
return null;
}
/* autoEdUnicodify()
* converts HTML entities to WikiText
*/
window.autoEdUnicodify = function(str) { //MAIN FUNCTION describes list of fixes
// Task 1: Replace named html entities with unicode
// Most common replacements
str = str.replace(/—/gi, '—');
str = str.replace(/–/gi, '–');
// 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, '♥');
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, 'Œ');
// ... => …
str = str.replace(/\.{3}(?!\.)/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;
}
/* autoEdISBN()
* fixes ISBN syntax so that WikiMagic can work
*/
window.autoEdISBN = function(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;
}
/* autoEdWhitespace()
* cleans up whitespace
*/
window.autoEdWhitespace = function(str) { //MAIN FUNCTION describes list of fixes
str = str.replace(/\t/g, " ");
str = str.replace(/^ ? ? \n/gm, "\n");
str = str.replace(/(\n\n)\n+/g, "$1");
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]\n)\n+/g, "$1");
str = str.replace(/ \n/g, "\n");
//* bullet points
str = str.replace(/^([\*#]+:*) /gm, "$1");
str = str.replace(/^([\*#]+:*)/gm, "$1 ");
//==Headings==
str = str.replace(/^(={1,4}) ?(.*?) ?(={1,4})$/gm, "$1 $2 $3");
return str;
}
/* autoEdWikilinks()
* simplifies and shortens wikilinks where appropriate
* Credits: A modification of [[Wikipedia:WikiProject User scripts/Scripts/Formatter]]
*/
window.autoEdWikilinks = function(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 = mw.config.get("wgPageName"); // PAGENAME including underscores
var p2 = mw.config.get("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');
//Popraw linki do plików
str = str.replace(/\[\[FILE:/gi, '[[Plik:');
str = str.replace(/\[\[GRAFIKA:/gi, '[[Plik:');
str = str.replace(/\[\[IMAGE:/gi, '[[Plik:');
//Replace [[Foo #bar]] -> [[Foo#bar]]
str = str.replace(/\[\[([^\]]*?)( |_)+#([^\]]*?)\]\]/g, '[[$1#$3]]');
//Replace [[Foo|]] -> [[Foo| ]]
str = str.replace(/\|\]\]/g, '| ]]');
return str;
}
// Converts the first character in a string to lower case
// Notes: Used by autoEdWikilinks
window.autoEd_first2lower = function(str) {
if (str != "") {
var letter = str.substr(0, 1);
return letter.toLowerCase() + str.substr(1, str.length);
} else {
return "";
}
}
/* autoEdHTMLtoWikitext()
* converts HTML to wikitext
*/
window.autoEdHTMLtoWikitext = function(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''");
// <s> => <del>
str = str.replace(/<\s*(\\|\/)\s*s\s*>/gi, '</del>');
str = str.replace(/<\s*s\s*>/gi, '<del>');
// </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;
}
/* autoEdHeadlines()
* fixes common headline errors and renames some headers
*/
window.autoEdHeadlines = function(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, "$1 See 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, "$1 See also $2");
}
// Common synonyms for "External links"
str = str.replace(/(==[\t ]*)(?:external links?|outside links?|web ?links?|exterior links?)([\t ]*==)/gi, "$1 External links $2");
// Capitalization and/or plural of "References", "Sources", "Further reading"
str = str.replace(/(==[\t ]*)references([\t ]*==)/gi, "$1 References $2");
str = str.replace(/(==[\t ]*)sources([\t ]*==)/gi, "$1 Sources $2");
str = str.replace(/(==[\t ]*)further readings?([\t ]*==)/gi, "$1 Further reading $2");
return str;
}
/* autoEdUnicodeControlChars()
* converts HTML to wikitext
*/
window.autoEdUnicodeControlChars = function(str) { //MAIN FUNCTION describes list of fixes
//Removes unneeded Unicode control characters
str = str.replace(new RegExp('\u200E|\uFEFF|\u200B', 'gi'), '');
return str;
}
/* autoEdUnicodeHex()
* converts hex encoded characters to unicode
*
* 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.
*/
window.autoEdUnicodeHex = function(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, ""));
}
/* autoEdTemplates()
* cleans up templates
*/
window.autoEdTemplates = function(str) { //MAIN FUNCTION describes list of fixes
//Remove unneeded Template: text from transclusions
str = str.replace(/{{[_ ]*szablon:[_ ]*/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;
}
/* autoEdTablestoWikitext()
* replaces HTML tables with wikitables
*/
window.autoEdTablestoWikitext = function(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 stuff>' with '{| stuff'
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;
}
/* autoEdExtraBreaks()
* removes extra BR tags
*/
window.autoEdExtraBreaks = function(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;
}
/* autoEdLinks()
* cleans up common link errors
*/
window.autoEdLinks = function(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;
}
// Moduł AutoEdDashes
// Autor: GregU / Wikipedia
// Źródło: [[Wikipedia:User:GregU/dashes.js]]
window.autoEdDashes = function(str)
{
if (str.search(/nodashes/i) >= 0)
return str;
var scpat = /\bscores?\b|\[\[Category:.*\b(sport|athlet|players|teams|games|league|champion|tournament|competit|cup\b|\w+ball\b|hockey|lacrosse|cricket|rugby|tennis|golf|polo|boxing|boxers|martial.art|chess)/i;
var scoresAreLikely = (str.search(scpat) >= 0);
// Ensure the replacement isn't a link such as [[FOO - BAR]] before
// replacing it, so that we don't break the link. But we do want to
// replace dashes used in the right-side label part of links. Also,
// don't break templates, URLs, DOIs, {{#expr:}}, <math> equations,
// source code, or <ref name="13-70">.
//
function ifNotLink (str)
{
var pos = arguments[ arguments.length - 2 ];
var string = arguments[ arguments.length - 1 ];
var pat = /\[\[[^|\]]*$|\{\{[^|}]*$|[:\/%][^\s|>]+$|<[^>]*$|#\w*expr:.*$/i;
if (string.substring(pos-260,pos+1).search(pat) >= 0)
return str; // it's a link, so don't change it
var pat2 = /\{\{(main|see|detail|about|for\b|other|redir|conv|coor|sort|anchor|DNB(?: [Cc]ite|)|[Cc]ite DNB)[^}]*$/i;
if (string.substring(pos-260,pos+1).search(pat2) >= 0)
return str; // likely templates with page-name or neg params
var pat3 = /\|\s*(CAS_number)\s*=\s*/i;
if (string.substring(pos-260,pos+1).search(pat3) >= 0)
return str; // drugbox CAS_number
var pat4 = /\|\s*(doi)\s*=\s*/i;
if (string.substring(pos-260,pos+1).search(pat4) >= 0)
return str; // doi
var m = string.slice(pos).search(/<\/?(math|pre|code|tt|source|syntaxhighlight|gallery)\b/i);
if (m >= 0 && string.charAt(pos+m+1) == '/')
return str; // don't break a <math> equation, or source code
if (string.slice(pos).search(/^[^|{}[\]<>\n]*\.([a-z]{3,4}\s*[|}]|jpg|png|svg)|^.*hyphen/i) >= 0)
return str; // it's a file name parameter, or <!--sic hyphen-->
if (str.search(/[ |(>][-–]\b/) >= 0)
return str.replace(/[-–]/, "−"); // minus sign
else
return str.replace(/--+\b/g, "—") . replace(/[-–−]+/g, "–"); // dash
}
str = str.replace(/\s--?\s/g, ifNotLink); // en dash looks better
str = str.replace(/[a-z\d]---?[a-z\d]/ig, ifNotLink); // em dash
str = str.replace(/\d\d\d]*}*[-−](dziś|teraz|dzisiaj)\b/ig, ifNotLink); // 1973-present
str = str.replace(/[^\w−-](18|19|20)\d\d]*}*[-−][^\w−-]/g, ifNotLink); // (1973-)
str = str.replace(/\d(s|%|\?|''')[-−]\d/g, ifNotLink); // 1950s-1960s, 40%-50%
str = str.replace(/\d[-−](\$|'+)\d/g, ifNotLink); // $40-$50, 7-'''4''', '49-'53
str = str.replace(/[½⅓⅔¼¾⅛⅜⅝⅞]%?[-−][\d½⅓⅔¼¾⅛⅜⅝⅞]/g, ifNotLink); // 3½-6
str = str.replace(/\d(st|nd|rd|th)?[-−]\d+(st|nd|rd|th)\b/g, ifNotLink); // 2nd-3rd
str = str.replace(/([a-z,'"”\]>] +|\(|^\| *|\|\| *)[-–]\d/mig, ifNotLink); // minus -35
str = str.replace(/<((sup|sub|td)>\s*)[-–](\d)/ig, "<$1−$3"); // 10<sup>-3</sup>
str = str.replace(/,*(?=.? ) *[-–—−] *(\d*:\d\d[\s*<])/g, " – $1"); // album track listings
// November 15, 2005-March 7, 2006; [[March 18]]-[[April 4]]
str = str.replace(/(\d\]*)[-–—−](\[*(Sty|Lut|Mar|Kwi|Maj|Cze|Lip|Sie|Wrz|Paź|Lis|Gru)[a-z]* +\d)/g, "$1 – $2");
// July-August 2007
str = str.replace(/\b((Sty|Lut|Mar|Kwi|Maj|Cze|Lip|Sie|Wrz|Paź|Lis|Gru)[a-z]*[-−]?\b){2,}/g, ifNotLink);
// [[266]]-[[283]]
str = str.replace(/(\d(?: BC)?\]\])[-−]((ca?\.|AD ?)?\[\[\d+[^\d-])/g, "$1–$2");
// (1984 – 1992)
str = str.replace(/([(|=] *\[*\d+\]*) +[–—−] +(\[*\d+\]*\s*[)|}])/g, "$1–$2");
// iv-xii
str = str.replace(/[ ;(=](?=\w+-)(m*(cm|cd|d?c*)(xc|xl|l?x*)(ix|iv|v?i*)-?\b){2}[^\w-]/g, ifNotLink);
if (scoresAreLikely) // W-L-D or 73–70–67–70=280, but not castling
str = str.replace(/[^\w−–-](?!0-0-0)(\d\d?\d?[-–−]){2,}\d\d?[^\w\/−–-]/g, ifNotLink);
str = str.replace(/\b(\d+)[–−](year|month|day|hour|minute|mile|yard|foot|inch|bit|door|speed|gun|page|seat|way|point|ton|man)\b/g, "$1-$2"); // hyphen
// Number ranges and scores should use en dashes, per [[MOS:DASH]].
// This has been well-tested and false positives (e.g., ID nos.) are rare.
//
function range (str, from,to, pos,string)
{
var dash = true;
var except = /\b(fig(ure)?|table|example|exhibit|circular|section|part|number|no|nr|id|model|pub|std|report|rpt|law|[P.]L|p|page|date|IS\wN\b[ a-z]*|SCOTUS)[^\w(,;]*$/i;
var rpat = /^([^A-Za-z]|nbsp)*(AD|BC|B?CE|BP|[kMG]a|km|mi|kg|lb|\w?Hz|vote|decision|record|odds|scor\w*|win|loss|tie|draw|lead|victory|defeat|upset|run|deficit|start|finish|season|game)\b/;
var lpat = /\b(pages|pp|rp|nos|\d+\)?'*[:,]|(w[io]n|lost?|tie|dr.w|lea?d|f.ll|vot|rul|decid|pass|fail|defeat|scor|gam|match|trail|finish|end)e?[ds]?|\w\w+ing|ahead|behind|up|down|from|to|is|are|was|were|of|out|by|an?|at|it|went|go|gone|beaten|between)([^a-z]|nbsp)*$/i;
var inorder = (to-0 > from.slice(-to.length)); // pp 362-5
var precision = Math.max( from.search(/0*$/), to.search(/0*$/) );
if (string.substring(pos-20,pos+1).search(except) >= 0) {
return str; // based on preceding word, looks like a ref number
}
if (from == 9 && to == 11) {
dash = false; // 9-11 is a common special case
}
if (from-0 >= to) {
dash = false; // values don't look like a range
}
if (to-from > 120 && from * (precision > 2 ? 5 : 50) < to && from > 1) {
dash = false; // values don't look like a range
}
if (scoresAreLikely && from <= 900 && to <= 900) {
dash = true; // likely a score or wins-losses
}
if (from < 2-to && string.search(/Category:.*\bChess\b/i) >= 0) {
dash = false; // chess notations 0-0, 0-1, 1-0
}
if (str.charAt(0) == '(' && string.charAt(pos + str.length) == ')') {
dash = true; // scores often seen as (8-4)
}
if (from.search(/^0./) >= 0 || to.search(/^0./) >= 0) {
dash = false; // 3-07 and 0123-4567 look like ref numbers
}
if (string.substr(pos-1,15).search(/^\d([:,.])\d+.\d+\1\d/) >= 0) {
dash = true; // 10:30-11:30, 35,000-40,000, 2.5-4.0
}
if (string.substr(pos,30).search(rpat) >= 0) {
dash = true; // 12-5 BC, 5-5000 km, 6-4 win, 73-50 vote
}
if (string.substring(pos-80,pos).search(lpat) >= 0) {
dash = true; // pp. 8, 25, 270-74, 313-7; won 6-4, 6-2
}
if (from > 1000 && from < 2100 && to.length == 2 && inorder) {
dash = true; // 1994-95 year range
}
return dash ? ifNotLink(str,pos,string) : str;
}
str = str.replace(/[^\w\/+−–-](\d{1,4})[-−](\d{1,4})(?!'*[\w\/+−–-])/g, range);
return str;
}
/* Activates individual modules when "auto ed" tab is clicked */
window.autoEdFunctions = function() {
var txt = $( '#wpTextbox1' );
txt.val(autoEdUnicodify(txt.val()));
txt.val(autoEdISBN(txt.val()));
txt.val(autoEdWhitespace(txt.val()));
txt.val(autoEdUnicodeHex(txt.val()));
txt.val(autoEdWikilinks(txt.val()));
txt.val(autoEdHTMLtoWikitext(txt.val()));
txt.val(autoEdHeadlines(txt.val()));
txt.val(autoEdUnicodeControlChars(txt.val()));
txt.val(autoEdTemplates(txt.val()));
txt.val(autoEdTablestoWikitext(txt.val()));
txt.val(autoEdExtraBreaks(txt.val()));
txt.val(autoEdLinks(txt.val()));
txt.val(autoEdDashes(txt.val()));
}
// Add "auto ed" tab and associate with actions
$(document).ready(function () {
//Execute AutoEd after call from "view mode"
if( autoEdQueryString('AutoEd') ) {
autoEdExecute();
}
// Set default values for any unset variables
if( typeof( autoEdLinkHover ) == 'undefined' ) {
autoEdLinkHover = "Uruchom AutoEd";
}
if( typeof( autoEdLinkName ) == 'undefined' ) {
autoEdLinkName = "AutoEd";
}
if( typeof( autoEdLinkLocation ) == 'undefined' ) {
autoEdLinkLocation = "p-cactions";
}
//Add the "auto ed" tab
if( typeof( document.forms.editform) != 'undefined' ) {
mw.util.addPortletLink( autoEdLinkLocation, '#', autoEdLinkName,
'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
$("#ca-AutoEd").on('click', window.autoEdExecute);
} else if (mw.config.get("wgIsArticle") && document.getElementById('ca-edit') && mw.config.get("wgAction") == "view") {
var url = mw.config.get("wgServer") + mw.config.get("wgScript") + '?title=' + encodeURIComponent(mw.config.get("wgPageName")) + '&action=edit';
mw.util.addPortletLink( autoEdLinkLocation, url + '&AutoEd=true', autoEdLinkName,
'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
} //End view-mode/edit-mode if
});
//</nowiki></pre>