Content deleted Content added
New version |
Amorymeltzer (talk | contribs) m Bugfix: Allow for &diff or ?diff; Better ways to do this would involve more editing |
||
(12 intermediate revisions by 3 users not shown) | |||
Line 1:
// Autolink [[wikilinks]], [external links] and
// and similar pages); adapted from [[Wikipedia:WikiProject User scripts/Scripts/Autolink]]
/* ---------------------------------------------------------------------------------------------- */
var autolinkCronoSpecial = mw.config.get('wgCanonicalSpecialPageName') == "Recentchanges" || /*
*/ mw.config.get('wgCanonicalSpecialPageName') == "Watchlist" || /*
*/ mw.config.get('wgCanonicalSpecialPageName') == "Recentchangeslinked" || /*
*/ mw.config.get('wgCanonicalSpecialPageName') == "Newpages" || /*
*/ mw.config.get('wgCanonicalSpecialPageName') == "Log" || /*
*/ mw.config.get('wgCanonicalSpecialPageName') == "Contributions";
// Special crono pages where this script is enabled
if ((typeof(autolinkMySpecialPage) != "undefined"))
autolinkCronoSpecial = autolinkCronoSpecial || mw.config.get('wgPageName') == autolinkMySpecialPage;
if (mw.config.get('wgCanonicalNamespace') == "Special" && !autolinkCronoSpecial) {
return; // Disabled in the other special pages
Line 31:
/* ---------------------------------------- Variables ------------------------------------------- */
var autolinkDiff = ___location.href.indexOf('
// It says if I'm in a diff page
var autolinkCrono = (mw.config.get('wgAction') == 'history' || autolinkCronoSpecial);
// It says if I'm in a history page
var autolinkEdit = ($.inArray(mw.config.get('wgAction'),
// It says if I'm in an edit or submit page
Line 46:
if (autolinkDiff) { // in diff pages
if (autolinkParseLink) { // without wikEd
autolinkTargetDiv[0] =
autolinkTargetDiv[1] =
autolinkColor = 'inherit'; // not coloured links
} else { // with wikEd
autolinkTargetDiv[0] =
autolinkColor = ''; // coloured links
}
} else if (autolinkCrono || autolinkEdit) { // in comments
autolinkTargetDiv[0] =
autolinkColor = ''; // coloured links
} else { // in code sections
autolinkTargetDiv[0] =
autolinkTargetDiv[1] =
autolinkTargetDiv[2] =
autolinkTargetDiv[3] =
autolinkTargetDiv[4] = $('.source-css');
autolinkColor = ''; // coloured links
}
Line 87 ⟶ 89:
var autolinkActivateHTML = false;
/* ------------------------------------------------------------------------------------------ */
autolinkRegexTl = /([^{]{{2}\s*[Tt]l\|)([^[\]{}|:<>\n]+)/g;
// For {{tl}}
Line 97 ⟶ 99:
// Regex for diffs
autolinkRegexURLinWcodeWoLabel = /((?:[^\[]|^)\[
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
Line 105 ⟶ 107:
// 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
Line 124 ⟶ 126:
if (!autolinkDiff || (autolinkDiff && !autolinkParseLink)) {
autolinkRegexURLinWcodeWoLabel = /([^\[]|^)\[
autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>';
// External links in comments or code sections, wikicode without label
autolinkRegexURLinWcodeWithLabel = /([^\[]|^)\[
autolinkRegexSubstinWcodeWithLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$3</a>';
// External links in comments or code sections, wikicode with label (the URL will not be visible)
autolinkRegexOtherPages = /((?:[^{]|^)\{{2}\s*(?:(?:[Ss][Uu][Bb][Ss][Tt]|[Mm][Ss][Gg]|[Mm][Ss][Gg][Nn][Ww])\s*:)?\s*)((?:[Dd]iscussion[ei] ?)?\s*(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto)?\s*(?: ?[Tt]alk)?\s*:[^[\]{}|:<>\n]+)(\||}{2})/gm;
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 comments or code sections
Line 159 ⟶ 161:
// ImportScript
/* ---------------------------------------------------------------------------------------------- */
for (i=0; i<autolinkTargetDiv.length; i++) {
Line 184 ⟶ 186:
autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWoLabel, autolinkRegexSubstinWcodeWoLabel);
// Make external links in wikicode without label into links
autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWithLabel, autolinkRegexSubstinWcodeWithLabel);
Line 199 ⟶ 202:
// Make wikilink code into links
autolinkContent = autolinkContent.replace(autolinkRegexInternalURL, '$1$2<a class="external autolink" style="color:' + autolinkColor + '" href="' + mw.config.get('wgServer') + '$3">$3</a>$2');
// Parse inactive external links (no wikicode, under wgServer)
Line 217 ⟶ 220:
autolinkContent = autolinkContent.replace(/([^']|^)'{2}(.+?)'{2}([^']|$)/gm, '$1<i>$2</i>$3');
if (autolinkCrono || autolinkEdit)
autolinkContent = autolinkContent.replace(/<i>(.*?)<\/i>/g, '<span title="italic" style="border: 1px solid silver; padding: 2px;">$1</span>');
// I'm in a comment field (italic)
}
if (autolinkDiff && autolinkParseLink) {
autolinkContent = autolinkContent.replace(/<a [^>]+><\/a>/g, ''); // Clean
autolinkContent = autolinkContent.replace(/([^\[]|^)\[\s*(<a [^>]+>)(?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+(<\/a>)\s+([^\]\n]+)\]/gm, '$1$2$4$3');
autolinkContent = autolinkContent.replace(/([^\[]|^)\[\s*(<a [^>]+>)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)(<\/a>)\s*\]/gm, '$1$2$3$4');
}
autolinkTargetDiv[i][j].innerHTML = autolinkContent; // Write it back
|