Wikipedia:Scripts/Wikilinks
From Wikipedia, the free encyclopedia
[edit] Wikilinks 2.4
Makes wikilinks clickable in the output window; contributed to the public domain by IceKarma on April 22, 2005.
Installation:
- Copy The code below into a file called wikilinks.js somewhere convenient.
- Add it to Auto-load scripts on the Startup tab under Global Settings.
- To install the script while ChatZilla is running, use the "/load" command in one of the views.
//*********************************************** // IceKarma's WikiLinks script for ChatZilla // Version 1.2 // 1.2 by James Ross: fix the normal links by shunting the // word-hyphenator as well. // Version 2.0 // 2.0 By Glen Mailer: // - Converted to new plugin API // - Ripped out a whole load of unused stuff // - Also Made to fit chatzilla coding pedantics // 2.1 By Alphax: // - Added basic template linking functionality // 2.2 By Alphax: // - subst: and pipes now handled correctly in templates // 2.3 by Pathoschild: // - reverted to 2.2 (2.3 broke all links with non-interlanguage prefixes) // - fixed mailto: wikilink glitch (based on 2.3 code by Stigmj) // 2.4 By Stigmj: // - added support for handling mirc-colors. // This file is hereby placed by the author into the public domain. plugin.id = "WikiLinks"; plugin.prefary = [ ["class", "wiki-link", ""], ]; // // Plugin management // plugin.init = function init(glob) { plugin.major = 2; plugin.minor = 4; plugin.version = plugin.major + "." + plugin.minor; plugin.description = "Munges wiki-links to be clickable in the output window"; plugin.prefary = plugin.prefary.concat(plugin.prefary); } plugin.disable = function disable() { client.munger.delRule("wiki-link"); client.munger.delRule("wiki-template-link"); client.commandManager.removeCommands(plugin.commands); display( plugin.id + " v" + plugin.version + " disabled."); return true; } plugin.enable = function enable() { client.munger.addRule("wiki-link", /(\[([\x1f\x02\x0f\x03\x16]\d\d)*\[.+?\]([\x1f\x02\x0f\x03\x16]\d\d)*\])/, insertWikiLink); client.munger.addRule("wiki-template-link", /(\{([\x1f\x02\x0f\x03\x16]\d\d)*\{.+?\}([\x1f\x02\x0f\x03\x16]\d\d)*\})/, insertWikiTemplateLink); // ugly hack to cause the munger to evaluate wiki-link before these rules var tmp1 = client.munger.entries[".mirc-colors"]; var tmp2 = client.munger.entries[".mirc-bold"]; var tmp3 = client.munger.entries[".mirc-underline"]; var tmp4 = client.munger.entries[".mirc-color-reset"]; var tmp5 = client.munger.entries[".mirc-reverse"]; var tmp6 = client.munger.entries["ctrl-char"]; var tmp7 = client.munger.entries["link"]; var tmp8 = client.munger.entries["mailto"]; var tmp9 = client.munger.entries["bugzilla-link"]; var tmp10 = client.munger.entries["channel-link"]; var tmp11 = client.munger.entries["word-hyphenator"]; delete client.munger.entries[".mirc-colors"]; delete client.munger.entries[".mirc-bold"]; delete client.munger.entries[".mirc-underline"]; delete client.munger.entries[".mirc-color-reset"]; delete client.munger.entries[".mirc-reverse"]; delete client.munger.entries["ctrl-char"]; delete client.munger.entries["link"]; delete client.munger.entries["mailto"]; delete client.munger.entries["bugzilla-link"]; delete client.munger.entries["channel-link"]; delete client.munger.entries["word-hyphenator"]; client.munger.entries[".mirc-colors"] = tmp1; client.munger.entries[".mirc-bold"] = tmp2; client.munger.entries[".mirc-underline"] = tmp3; client.munger.entries[".mirc-color-reset"] = tmp4; client.munger.entries[".mirc-reverse"] = tmp5; client.munger.entries["ctrl-char"] = tmp6; client.munger.entries["link"] = tmp7; client.munger.entries["mailto"] = tmp8; client.munger.entries["bugzilla-link"] = tmp9; client.munger.entries["channel-link"] = tmp10; client.munger.entries["word-hyphenator"] = tmp11; var cmdary = [ [ "wiki-links-class", cmdClass, CMD_CONSOLE, "[<className>]" ], ]; plugin.commands = client.commandManager.defineCommands(cmdary); display( plugin.id + " v" + plugin.version + " enabled."); return true; } // // Mungers // function insertWikiLink(matchText,containerTag) { var wikiLink = matchText; var linkTitle; wikiLink = matchText.replace(/^\[([\x1f\x02\x0f\x03\x16]\d\d)*\[([\x1f\x02\x0f\x03\x16]\d\d)*/, ""); wikiLink = wikiLink.replace(/([\x1f\x02\x0f\x03\x16]\d\d)*\]([\x1f\x02\x0f\x03\x16]\d\d)*\]$/, ""); linkTitle = wikiLink; if (linkTitle.match(/\|/)) { var ary = linkTitle.match(/^(.*?)\|(.*)$/); wikiLink = ary[1]; linkTitle = ary[2]; } wikiLink = escape(wikiLink.replace(/ /g, "_")); var anchor = document.createElementNS( "http://www.w3.org/1999/xhtml", "html:a"); anchor.setAttribute("href", "http://en.wikipedia.org/wiki/" + wikiLink); anchor.setAttribute("class", "chatzilla-link "+plugin.prefs["class"]); insertHyphenatedWord(linkTitle, anchor); containerTag.appendChild(document.createTextNode("[[")); containerTag.appendChild(anchor); containerTag.appendChild(document.createTextNode("]]")); } function insertWikiTemplateLink(matchText,containerTag) { var wikiLink = matchText; var linkTitle; wikiLink = matchText.replace(/^\{([\x1f\x02\x0f\x03\x16]\d\d)*\{([\x1f\x02\x0f\x03\x16]\d\d)*/, ""); wikiLink = wikiLink.replace(/([\x1f\x02\x0f\x03\x16]\d\d)*\}([\x1f\x02\x0f\x03\x16]\d\d)*\}$/, ""); linkTitle = wikiLink; if (linkTitle.match(/^subst:/)) { var ary = linkTitle.match(/^(subst:)(.*)$/); wikiLink = ary[2]; } if (linkTitle.match(/\|/)) { if(linkTitle.match(/^subst:/)) { var ary = linkTitle.match(/^(subst:)(.*?)\|(.*)$/); wikiLink = ary[2]; } else { var ary = linkTitle.match(/^(.*?)\|(.*)$/); wikiLink = ary[1]; } } wikiLink = escape(wikiLink.replace(/ /g, "_")); var anchor = document.createElementNS( "http://www.w3.org/1999/xhtml", "html:a"); anchor.setAttribute("href", "http://en.wikipedia.org/wiki/Template:" + wikiLink); anchor.setAttribute("class", "chatzilla-link "+plugin.prefs["class"]); insertHyphenatedWord(linkTitle, anchor); containerTag.appendChild(document.createTextNode("{{")); containerTag.appendChild(anchor); containerTag.appendChild(document.createTextNode("}}")); } // // Commands // function cmdClass(e) { if ( null != e.linkclass ) plugin.prefs["class"] = e.linkclass; display( "Current value: " + plugin.prefs["class"] ); }
Special options:
- You can optionally (may not work) configure the formatting applied to Wikilinks using CSS. Use the command below, then define the relevant class in your motif skin. The default class is "wiki-link".
/wiki-links-class [{class}]