User:Lenore/autolink.js: Difference between revisions

Content deleted Content added
m -no more useful code
changes in regex
Line 78:
 
var autolinkRegexCorrectNs;
autolinkRegexTl = /([^{]{{2}\s*[Tt]l\|)([^[\]{\}\|<>\n]+)/g;
// For {{tl}}
 
autolinkRegexTemplate = /(\<span class\="diffchange"\>|)(?:[^\{]|\{{2}|^)(\<\/span\>|)(\<span class\="diffchange"\>|)\{{2}\s*(\?:<\/span\>|)?\s*(\?:<span class\="diffchange"\>|)?\s*(?:[Ss][Uu][Bb][Ss][Tt]\:|[Mm][Ss][Gg]\:|[Mm][Ss][Gg][Nn][Ww]\:|)(?\s*(?:<\/span>)?\s*(?:<span class="diffchange">|)?)([^[\]{\}\:\&\|<>\n]*+)((?:<\/span>)?(\?:<span class\="diffchange"\>|)?)([^[\]{\}\:\&\|<>\n]*?)(\(?:<\/span\>|)?(?:<span class="diffchange">)?)([^[\]{\}\:\&\|<>\n]*?)(?=\s*(?:(?:\:|\|)|\}{2}))/gm;
autolinkRegexSubstTemplate = '$1<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$2$3$4{{$5$6">$2</a>$3<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/HelpTemplate:$72$4$6">$74</a>$85<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$92$114$136">$9$10$11$12$136</a>$7');
// Templates
autolinkRegexURL = /((?:[^"\[]|[^=]")(?:<span class="diffchange">)?)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+?)(?=(?:<\/span>)?[\s|)\]}'"])/g;
// External links (no wikicode)
 
if (autolinkCrono || autolinkEdit) {
 
autolinkColor = ''; // Link color in history pages
 
autolinkRegexURLinWcodeWoLabel = /([^\[])\[{1}\s*((?:https?|ftps?):\/\/[\w-._\/\.\:~%\-+&#?\!=&%~()@:]+)\s*\]{1}()/g;
autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>$3');
// External links in history pages, wikicode without label
 
autolinkRegexURLinWcodeWithLabel = /([^\[])\[{1}\s*((?:https?|ftps?):\/\/[\w-._\/\.\:~%\-+&#?\!=&%~()@:]+)()\s+([^\]\n]+)\]{1}()/g;
autolinkRegexSubstinWcodeWithLabel = '$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$3$4</a>$5');
// External links in history pages, wikicode with label (the URL will not be visible)
autolinkRegexTemplate = /((?:[^{]|^)\{{2}\s*(?:[Ss][Uu][Bb][Ss][Tt]:|[Mm][Ss][Gg]:|[Mm][Ss][Gg][Nn][Ww]:)?\s*)([^[\]{}|<>\n]+)(\||}{2})/gm;
autolinkRegexSubstTemplate = '$1[[$2<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$3$5$72">$3$4$5$6$7$82</a>$9]]$103');
// Templates in history pages
 
} else {
Line 93 ⟶ 109:
autolinkColor = 'inherit'; // Link color in other pages
 
autolinkRegexURLinWcodeWoLabel = /(\[{1}\s*(?:<\/span>)?\s*(?:<span class="diffchange">)?\s*)((?:https?|ftps?):\/\/[\w._\/\\~%\-+&#?!=()@:]+)((?:<\/span>)?(?:<span class="diffchange">)?)([\w._\:/\\~%\-+&#?!=()@:]*)((?:<\/span>)?(?:<span class=&%"diffchange">)?)([\w._\/\\~]%\-+&#?!=()@:]*)([^\s]\n]*\]{1})/g;
autolinkRegexSubstinWcodeWoLabel = '$1<a class="external autolink" style="color:'$1 + autolinkColor + '" href="$2$3$4{{$5$6">$2</a>$3<a class="external autolink" style="color:' + autolinkColor + '" href="/wiki/Help:$72$4$6">$74</a>$85<a class="external autolink" style="color:' + autolinkColor + '" href="/wiki/$102$124$14$166">$9$10$11$12$13$14$15$166</a>$7');
// External links in other pages, wikicode without label
 
autolinkRegexURLinWcodeWithLabel = /(\[{1})(((?:https?|ftps?):\/\/[\w-\/\.\:\?\=&%~]+))(\s+[^\]\n]+)(\]{1})/gautolinkRegexURLinWcodeWoLabel;
autolinkRegexSubstinWcodeWithLabel = autolinkRegexSubstinWcodeWoLabel;
// External links in other pages, wikicode with label
 
}
 
autolinkRegexURLautolinkRegexWlink = /(\[{2}\s*(?:[^<\/span>)?\s*(?:<span class="diffchange">)?\s*)([^[\]{}|[^<>\=n]"+)((?:<\/span>)?(?:<span class\="diffchange"\>|))((?:https?|ftps?):\/\/([^[\w-\/\.\:]{}|<>\n]?\=&%~]+)((?:\<\/span\>|)?(?:<span class="diffchange">)?)([^[\s\]{}|<>\n]?)((?:[^\]\n]|\}'"][^\]])*\]{2})/g;
autolinkRegexSubstWlink = '$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';
// External links (no wikicode)
 
autolinkRegexWlink = /(\<span class\="diffchange"\>|)\[{2}(\<\/span\>|)([^\[\]\{\}<>\n]*?)(\<span class\="diffchange"\>|)([^\[\]\{\}<>\n]*?)(\<\/span\>|)([^\[\]\{\}<>\n]*?)(|\|[^\n]*?)(\<span class\="diffchange"\>|)\]{2}(\<\/span\>|)/g;
// Wikilinks
 
autolinkRegexInternalURL = /([^\=])('|"|\s)((?:\/?w\/index\.php\?|\/?wiki\/)[\w-._\/\.\:~%\-+&#?\!=&;%~()@:]+)\2/g;
autolinkRegexOtherPages = /(\<span class\="diffchange"\>|)([^\{]|\{{2}|^)(\<\/span\>|)(\<span class\="diffchange"\>|)\{{2}(\<\/span\>|)(\<span class\="diffchange"\>|)([Ss][Uu][Bb][Ss][Tt]\:|[Mm][Ss][Gg]\:|[Mm][Ss][Gg][Nn][Ww]\:|)(\<\/span\>|)(\<span class\="diffchange"\>|)((?:[Dd]iscussion[ei] ?|)(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto|)(?: ?[Tt]alk|)\:[^\{\}\:\&\|<>\n]*?)(\<\/span\>|)([^\{\}\:\&\|<>\n]*?)(\<span class\="diffchange"\>|)([^\{\}\:\&\|<>\n]*?)(\<\/span\>|)([^\{\}\:\&\|<>\n]*?)(?=\s*(?:(?:\:|\|)|\}{2}))/gm;
// Not-template pages included
 
autolinkRegexTl = /({{[Tt]l\|)([^\{\}\|<>]+)/g;
// For {{tl}}
 
autolinkRegexTemplate = /(\<span class\="diffchange"\>|)([^\{]|\{{2}|^)(\<\/span\>|)(\<span class\="diffchange"\>|)\{{2}(\<\/span\>|)(\<span class\="diffchange"\>|)([Ss][Uu][Bb][Ss][Tt]\:|[Mm][Ss][Gg]\:|[Mm][Ss][Gg][Nn][Ww]\:|)(\<\/span\>|)([^\{\}\:\&\|<>\n]*?)(\<span class\="diffchange"\>|)([^\{\}\:\&\|<>\n]*?)(\<\/span\>|)([^\{\}\:\&\|<>\n]*?)(?=\s*(?:(?:\:|\|)|\}{2}))/gm;
// Templates
 
autolinkRegexInternalURL = /([^\=])('|"|\s)((?:\/?w\/index\.php\?|\/?wiki\/)[\w-\/\.\:\?\=&;%~]+)\2/g;
// External links (no wikicode, under wgServer)
 
autolinkRegexImportScript = /([Ii]mport[Ss]cript(?:\<span class\="br0"\>)?\((?:\<\/span\>\<span class\="st0"\>)?)('|")([^\[\]\{}|<>\n]+?)(\2(?:\<\/span\>\<span class\="br0"\>)?\)(?:\<\/span\>)?)/g;
// ImportScript
 
autolinkRegexCorrectNs = /(href\="\/wiki\/)Template(:(?:[Dd]iscussion[ei] ?|)?(?:[Ss]peciale?|[Ww](?:ikipedia|P)|[Tt]emplate|[Uu](?:ser|tente)|[Pp]ortale?|[Pp]rogetto|)?(?: ?[Tt]alk|)?")/g;
// Correct link to Template:Namespace
 
Line 148 ⟶ 155:
 
autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWoLabel,
autolinkRegexSubstinWcodeWoLabel);
'$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>$3');
// Make external links in wikicode without label into links
 
autolinkContent = autolinkContent.replace(autolinkRegexURLinWcodeWithLabel,
autolinkRegexSubstinWcodeWithLabel);
'$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$3$4</a>$5');
// Make external links in wikicode with label into links
 
autolinkContent = autolinkContent.replace(autolinkRegexURL,
'$1<a class="external autolink" style="color:' + autolinkColor + '" href="$2">$2</a>$3');
// Parse inactive external links (no wikicode)
 
autolinkContent = autolinkContent.replace(autolinkRegexWlink,
autolinkRegexSubstWlink);
'$1[[$2<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$3$5$7">$3$4$5$6$7$8</a>$9]]$10');
// Make wikilink code into links
 
autolinkContent = autolinkContent.replace(autolinkRegexOtherPages,
'$1$2$3$4{{$5$6<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Help:$7">$7</a>$8<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/$10$12$14$16">$9$10$11$12$13$14$15$16</a>');
// Make not-template pages included code into links
 
autolinkContent = autolinkContent.replace(autolinkRegexTemplate,
autolinkRegexSubstTemplate);
'$1$2$3$4{{$5$6<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Help:$7">$7</a>$8<a class="autolink" style="color:' + autolinkColor + '" href="/wiki/Template:$9$11$13">$9$10$11$12$13</a>');
autolinkContent = autolinkContent.replace(/href\="\/wiki\/Template\:#/g, 'href="/wiki/Help:');
// Make template code into links