Wiki API

Here we look at some useful javascript calls that the wiki-client can interpret. The examples on this page can be experimented with by typing them as is into your browsers javascript console.

Not an API yet perhaps. But in a federation of decentralised components some sort of API is needed. here we can start to ask this question.

# Web messaging

Web messaging is a way for documents in separate browsing contexts to share data without the DOM being exposed to malicious cross-origin scripting. Unlike other forms of cross-site communication, web messaging never directly exposes the DOM - dzone.com

# My wiki talks to your wiki

We anticipate creating an api for the wiki-client using window.postmessage. This would require defining the following type of event listener in the client:

//respond to events window.addEventListener('message',function(event) { if(event.origin !== 'https://davidwalsh.name') return; console.log('message received: ' + event.data,event); event.source.postMessage('holla back youngin!',event.origin); },false);

This would enable web pages to embed wiki as an iFrame, or wiki to communicate to or be communicated with other apps in browser tabs or wasm components.

# Avoiding being pushy

The federation looks to avoid push. This causes us a great deal of problems. It prevents wiki becoming famous or rich. But it achieves an invaluable form of protection from the most common forms of malware. It provides us an affordable harbour.

# Navigation

Let's navigate to an internal page on the site:

wiki.doInternalLink('welcome-visitors')

Remote Links can be navigated to using the same syntax with additional parameters:

wiki.doInternalLink('folder', null, 'fedwiki.org')

The external link is handled in wiki.resolveLinks which handles both internal and external links in a block of text. The code is in github

# Creating Ghost Pages

Let's display a "hello world" ghost-page:

wiki.showResult(wiki.newPage({title:'hello world'}))

Should we wish to accept json from an external source:

var pageJson = '{"title":"Ghost Page"}'; var pageArray = JSON.parse(pageJson); wiki.showResult(wiki.newPage(pageArray));

# Fetching Pages

Let's fetch a page with javascript and display it as a ghost-page:

let page = await fetch('https://wiki.dbbs.co/welcome-visitors.json').then(res => res.json()) wiki.showResult(wiki.newPage(page))

Alternatively without using `await`:

fetch('https://wiki.dbbs.co/welcome-visitors.json') .then(res => res.json()) .then(json => wiki.showResult(wiki.newPage(json)))

Let's fetch a page with wiki-client javascript. You need to construct some javascript of the form:

wiki.site('site').get('page', cb())

An example with a callback that calls `console.log`:

wiki.site('fedwiki.org').get('welcome-visitors.json', (page) => console.log(page))

There are actually two callback parameters:

wiki.site('wiki.dbbs.co').get('welcome-visitors.json',(err,page)=>wiki.showResult(wiki.newPage(page)))

# Search

let's use wiki-client to construct an array based on searching the neighborhood:

wiki.neighborhoodObject.search('how to')

Here is the code we use to format a search result as a ghost page: - https://github.com/fedwiki/wiki-client/blob/master/lib/search.coffee#L14-L27

# Info

Let's find out what wiki-client nows about the wiki-site:

Let's identify the first roster in the lineup:

wiki.site('fedwiki.org')

$('.roster-source').get(0).getRoster()

# See also

~

Wiki content is normally viewed as rendered by the client, which is a JavaScript app running in the browser. But the Wiki server also has an API for access to the raw data behind a site (which is what the client app uses as well).