User:AT/monobook.js

/* I refactored wikiswap, finally, and mainly so I can leave maintenence to people who are actually active. It's now extensible, and you can do whatever you feel like with it. For basic usage, pass it a hostname of another wiki, a title, name, and unique id. However, you can now do a couple of fancy things using the modifier parameter.

For instance, say I wanted to add a tab to search google images for the page name, but only within a certain site.

For this, you'd call:

wiki_swapper('http:images.google.com/images?q=', 'google', 'Google Image Search', '_gis', add_site_search);

Where the function add_site_search is defined as follows:

function add_site_search(href) { return href + "+site:wiki.guildwars.com"; }

or, if you wanted to restrict the tab to certain namespaces, you could call a modifier like this:

function modifier_func(href) { if(wgCanonicalNamespace == 'foo') { return false; }  else { return href; }

If the modifier function returns false, the tab won't be added. So, the modifier needs to take a href as a parameter, and then either return the path to be used, or return false if no tab is to be added. Of course, you'll also need to include this page, or just copy the wiki_swapper and addTab functions to your own monobook.js.

Have fun!

function addTab(url, name, id, title, key) { return addPortletLink('p-cactions', url, name, id, title, key); }

/** function wiki_swapper(path, name, title, identifier, modifier) {  href = path + wgCanonicalNamespace + ':' + wgTitle; if ( modifier != null ) { href = modifier(href); }  if (href) addTab(href, name, "swapper_"+identifier, title, ''); }
 * This function provides a fairly simple interface for switching
 * between wikis. To use it, call wiki_swapper within load_swapper
 * with the desired parameters.
 * @author  AT
 * @param   path          The base path of the site you'd like to switch to.
 * @param   name          The name to be displayed on the tab
 * @param   title         The tab's title attribute
 * @param   identifier    A unique identifier to distinguish this tab
 * from others. Used for styling, DOM manipulation
 * @param   modifier      A function that can modify the final URI of the tab.
 * @param   modifier      A function that can modify the final URI of the tab.

/** function load_swapper { wiki_swapper('http://images.google.com/images?q=', 'google', 'Google Image Search', '_gis', add_site_search); }
 * Use this function to define your tabs. I've added a simple example - google
 * image search, only in the main namespace

function add_site_search(href) { if(wgNamespaceNumber == '0') { return href+"+site:wiki.guildwars.com"; }  else { return false; } }

// And add them to the page on load. addOnloadHook(load_swapper);