WikiApiary:Bookmarklet

This bookmarklet can be used to easily add websites to WikiApiary.

 javascript:var q=window.location.href,p,s,a,d='';if(window.mw&&mw.config){p=mw.config.get('wgSiteName')}else if(window.wgSiteName){p=wgSiteName}else{p=document.title.replace(/[\/#<>\[\]\|\{\}]/g,"-")}if(window.mw&&mw.util&&mw.util.wikiScript){s=mw.util.wikiScript('api');if(s.substr(0,1)!='/'){s='/'+s}a=mw.config.get('wgServer')+s}else if(typeof(window.wgScriptPath)=='string'){s=wgScriptPath+'/api.php';if(s.substr(0,1)!='/'){s='/'+s}a=wgServer+s}if(a&&a[0]=='/'){a=window.location.protocol+a}if(document.getSelection){d=document.getSelection}void(open('https://wikiapiary.com/wiki/Special:RunQuery/Bookmarklet'+'?Bookmarklet%5BURL%5D='+encodeURIComponent(q)+'&Bookmarklet%5BAPI%20URL%5D='+encodeURIComponent(a)+'&Bookmarklet%5BName%5D='+encodeURIComponent(p)+'&Bookmarklet%5BDescription%5D='+encodeURIComponent(d)+'&wpRunQuery=true','Add%20to%20WikiApiary'));

When you find a wiki that you want to add to WikiApiary, you can highlight the text that describes the wiki, and then activate the bookmarklet. The name of the window, URL in the location bar and the text you have highlighted will be used to pre-populate the form to add a new wiki.

Expanded Code
This is the same code as above, but with spaces and newlines in place to make it easier to read and edit.

javascript: var q = window.location.href, p, s, a, d = ''; if (window.mw && mw.config) { p = mw.config.get('wgSiteName'); } else if (window.wgSiteName) { p = wgSiteName; } else { p = document.title.replace(/[\/#<>\[\]\|\{\}]/g,"-"); } if (window.mw && mw.util && mw.util.wikiScript) { s = mw.util.wikiScript('api'); // Some bogus configurations don't include the leading / in $wgScriptPath if (s.substr(0,1) != '/') { s = '/' + s;   } a = mw.config.get('wgServer') + s; } else if (typeof(window.wgScriptPath) == 'string') { s = wgScriptPath + '/api.php'; if (s.substr(0,1) != '/') { s = '/' + s;   } a = wgServer + s; } if (a && a[0] == '/') { a = window.location.protocol + a; } if (document.getSelection) { d = document.getSelection; } void(open('https://wikiapiary.com/wiki/Special:RunQuery/Bookmarklet' + '?Bookmarklet%5BURL%5D=' + encodeURIComponent(q) + '&Bookmarklet%5BAPI%20URL%5D=' + encodeURIComponent(a) + '&Bookmarklet%5BName%5D=' + encodeURIComponent(p) + '&Bookmarklet%5BDescription%5D=' + encodeURIComponent(d) + '&wpRunQuery=true', 'Add%20to%20WikiApiary'));

It can be compressed online to get the bookmarklet with http://javascriptcompressor.com/

To Do

 * Automatically get API URL from EditURI link.
 * Instead of going directly to the edit form, go to a query form that will search to see if any wikis exist on this domain name. Provide a link in that querypage that will then allow the form to be activated with the fields populated.
 * Only relatively modern MediaWiki installs report EditURI. Older versions have link references in the head element pointing to index.php, which could reliably predict api.php. If EditURI is not present the bookmarklet could attempt to find index.php and assume that path for api.php.
 * It has been changed to use  if available, or , which is supported for even older MediaWiki versions than EditURI