Content deleted Content added
m correct color of templates in diff pages |
New version |
||
Line 25:
if (typeof(autolinkParseLink) == 'undefined') {
autolinkParseLink = true; // Parse
}
/* ---------------------------------------- Variables ------------------------------------------- */
var autolinkDiff = ___location.href.indexOf('&diff=') != -1;
// It says if I'm in a diff page
var autolinkCrono = (wgAction == 'history' || autolinkCronoSpecial);
// It says if I'm in a history page
var autolinkEdit = (wgAction == 'edit' || wgAction == 'submit');
// It says if I'm in an edit or submit page
var autolinkColor; // links color
var autolinkTargetDiv = [];
if (autolinkDiff) { // in diff pages
if (autolinkParseLink) { // without wikEd
autolinkColor = 'inherit'; // not coloured links
} else { // with wikEd
autolinkTargetDiv[0] = document.getElementsByClassName('comment');
autolinkColor = ''; // coloured links
}
} else if (autolinkCrono || autolinkEdit) { // in comments
autolinkTargetDiv[0] = document.getElementsByClassName('comment');
autolinkColor = ''; // coloured links
} else { // in code sections
autolinkTargetDiv[0] = document.getElementsByTagName('pre');
autolinkTargetDiv[1] = document.getElementsByTagName('tt');
autolinkTargetDiv[2] = document.getElementsByTagName('code');
autolinkTargetDiv[3] = document.getElementsByTagName('source');
autolinkColor = ''; // coloured links
}
/* ------------------------------------------ Regex --------------------------------------------- */
var autolinkRegexTl;
var autolinkRegexURL;
var autolinkRegexURLinWcodeWoLabel;
var autolinkRegexSubstinWcodeWoLabel;
var autolinkRegexURLinWcodeWithLabel;
var autolinkRegexSubstinWcodeWithLabel;
var autolinkRegexOtherPages;
var autolinkRegexSubstOtherPages;
var autolinkRegexTemplate;
var autolinkRegexSubstTemplate;
var autolinkRegexWlink1;
var autolinkRegexSubstWlink1;
var autolinkRegexWlink2;
var autolinkRegexSubstWlink2;
var autolinkRegexInternalURL;
var autolinkRegexImportScript;
var
/* ------------------------------------------------------------------------------------------ */
autolinkRegexTl = /([^{]{{2}\s*[Tt]l\|)([^[\]{}|<>\n]+)/g;
// For {{tl}}
Line 85 ⟶ 95:
// External links (no wikicode)
// Regex for diffs
autolinkRegexURLinWcodeWoLabel = /(\[{1}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)((?:<\/span>)?(?:<span class="diffchange">)?)([\w._\/\\~%\-+&#?!=()@:]*)((?:<\/span>)?(?:<span class="diffchange">)?)([\w._\/\\~%\-+&#?!=()@:]*)([^\]\n]*\]{1})/g;
autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$2</a>$3<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$4</a>$5<a class="external autolink" style="color:' + autolinkColor + '" href="$2$4$6">$6</a>$7';
// External links in diff pages, wikicode without label
autolinkRegexURLinWcodeWithLabel = autolinkRegexURLinWcodeWoLabel;
autolinkRegexSubstinWcodeWithLabel = autolinkRegexSubstinWcodeWoLabel;
// External links in diff pages, wikicode with label
autolinkRegexOtherPages = /((?:[^{]|^)\{{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)((?:[Dd]iscussion[ei] ?)?\s*(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto)?\s*(?: ?[Tt]alk)?\s*:[^[\]{}|<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)(\||}{2})/gm;
autolinkRegexSubstOtherPages = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$6</a>$7';
// Other pages included in diff pages
autolinkRegexTemplate = /((?:[^{]|^)\{{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?)([^[\]{}|<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)(\||}{2})/gm;
autolinkRegexSubstTemplate = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$4$6">$6</a>$7';
// Templates in diff pages
autolinkRegexWlink1 = /(\[{2}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)([^[\]{}|<>\n]+)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:<\/span>)?(?:<span class="diffchange">)?)([^[\]{}|<>\n]*)((?:[^\]\n]|\][^\]])*\]{2})/g;
autolinkRegexSubstWlink1 = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$4</a>$5<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2$4$6">$6</a>$7';
// Wikilinks in diff pages
autolinkRegexWlink2 = autolinkRegexWlink1;
autolinkRegexSubstWlink2 = autolinkRegexSubstWlink1;
// Regex for comments or code sections
if (!autolinkDiff || (autolinkDiff && !autolinkParseLink)) {
autolinkRegexURLinWcodeWoLabel = /([^\[])\[{1}\s*((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)\s*\]{1}/g;
autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>';
// External links in
autolinkRegexURLinWcodeWithLabel = /([^\[])\[{1}\s*((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)\s+([^\]\n]+)\]{1}/g;
autolinkRegexSubstinWcodeWithLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$3</a>';
// External links in
autolinkRegexSubstOtherPages = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$2">$2</a>$3';
// Other pages included in comments or code sections
autolinkRegexTemplate = /((?:[^{]|^)\{{2}\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*)([^[\]{}|<>\n]+)(\||}{2})/gm;
autolinkRegexSubstTemplate = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2">$2</a>$3';
// Templates in
autolinkRegexWlink1 = /\[{2}\s*([^[\]{}|<>\n]+?)\s*\|\s*(.+?)\s*\]{2}/g;
autolinkRegexSubstWlink1 = '<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$1">$2</a>';
// Wikilinks in code sections, with label
autolinkRegexWlink2 = /\[{2}\s*([^[\]{}|<>\n]+?)\s*\|?\s*\]{2}/g;
autolinkRegexSubstWlink2 = '<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$1">$1</a>';
// Wikilinks in code sections, without label
autolinkActivateHTML = true;
// Activate some HTML (inline) and wikicode for bold and italic
}
autolinkRegexInternalURL = /([^=])('|"|\s)((?:\/?w\/index\.php\?|\/?wiki\/)[\w._\/\\~%\-+&#?!=()@:]+)\2/g;
Line 126 ⟶ 158:
autolinkRegexImportScript = /([Ii]mport[Ss]cript(?:<span class="br0">)?\((?:<\/span><span class="st0">)?)('|")([^[\]{}|<>\n]+?)(\2(?:<\/span><span class="br0">)?\)(?:<\/span>)?)/g;
// ImportScript
/* ---------------------------------------------------------------------------------------------- */
Line 136 ⟶ 165:
for (j=0; j<autolinkTargetDiv[i].length; j++) {
autolinkContent = autolinkContent.replace(/>/g, '­>­');
// &lt; to &shy;<&shy; and &gt; to &shy;>&shy; (&shy; is a marker)
autolinkContent = autolinkContent.replace(/&/g, '&');
// &amp; to &
/* ----------------------------------------------------------------------------------- */
autolinkContent = autolinkContent.replace(autolinkRegexTl, '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2">$2</a>');
// For {{tl}}: make his argument into link
autolinkContent = autolinkContent.replace(autolinkRegexURL, '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>');
// Parse inactive external links (no wikicode)
// Make external links in wikicode without label into links
// Make external links in wikicode with label into links
autolinkContent = autolinkContent.replace(autolinkRegexOtherPages, autolinkRegexSubstOtherPages);
// Make other pages included code into links
autolinkContent = autolinkContent.replace(/href\="\/wiki\/Template\:#/g, 'href="/wiki/Help:');
// Make template code into links
autolinkContent = autolinkContent.replace(autolinkRegexWlink1, autolinkRegexSubstWlink1);
autolinkContent = autolinkContent.replace(autolinkRegexWlink2, autolinkRegexSubstWlink2);
// Make wikilink code into links
autolinkContent = autolinkContent.replace(autolinkRegexInternalURL, '$1$2<a class="external autolink" style="color:' + autolinkColor + '" href="' + wgServer + '$3">$3</a>$2');
// Parse inactive external links (no wikicode, under wgServer)
autolinkContent = autolinkContent.replace(autolinkRegexImportScript, '$1$2<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$3">$3</a>$4');
// Parse ImportScript
/* ----------------------------------------------------------------------------------- */
autolinkContent = autolinkContent.replace(/­<­/g, '<');
autolinkContent = autolinkContent.replace(/­>­/g, '>');
// &shy;<&shy; to &lt; and &shy;>&shy; to &gt; (revert)
if (autolinkActivateHTML) {
autolinkContent = autolinkContent.replace(/<(span|b|i|strong|small|tt|del|s|u|sub|sup)>(.*?)<\/(\1)>/g, '<$1>$2</$3>');
autolinkContent = autolinkContent.replace(/([^']|^)'{3}(.+?)'{3}([^']|$)/gm, '$1<b>$2</b>$3');
autolinkContent = autolinkContent.replace(/([^']|^)'{2}(.+?)'{2}([^']|$)/gm, '$1<i>$2</i>$3');
}
}
|