WikiApiary:Bookmarklet

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

 javascript:q=window.location.href;p=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){a=mw.config.get('wgServer')+mw.util.wikiScript('api')}else if(typeof(window.wgScriptPath)=='string'){a=wgServer+wgScriptPath+'/api.php'}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. If the wiki provides a  attribute the API URL will also be pre-populated.

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: q = window.location.href; p = 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) { a = mw.config.get('wgServer') + mw.util.wikiScript('api'); } else if (typeof(window.wgScriptPath) == 'string') { a = wgServer + wgScriptPath + '/api.php'; } 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