Extension:VIKI/Plugin Structure

Overview
By design, VIKI is architected to support either an individual wiki or a series of collectively managed wikis (wiki farm), and this support comes in the form of a hook structure for plugins. Similarly to MediaWiki, VIKI defines a set of points of time during the execution when it will call any hook functions which are registered with it.

Plugins are MediaWiki extensions themselves which register with VIKI hooks. Plugins may execute code on both the PHP side and the JavaScript side. If the plugin includes JavaScript, a resource module containing the JS files must be declared and registered with VIKI to load. As your plugin is a MediaWiki extension itself, you may choose to (for example) define MediaWiki API extensions in your plugin.

Currently, VIKI defines one PHP hook and 11 JavaScript hooks:

PHP Hooks

JavaScript Hooks

Declaring A Plugin
Declaring a JavaScript plugin requires two steps:   In your plugin's PHP file, register the name of the plugin function hook with $wgVIKI_Function_Hooks.   Also in your plugin's PHP file, have VIKI add the resource module for the plugin at ParserFirstCallInit. Note that for historical reasons, the core VIKI class is called 'VikiJS'.  

Declaring a PHP plugin requires one step:   In your plugin's PHP file, register the name of the plugin function hook with VIKI. Any parameters passed in should be passed as an array, and the function should be declared to take one parameter, which is the array of parameters.  

If the plugin contains both a PHP and JavaScript side, all three steps must be taken.

JavaScript Structure
VIKI takes advantage of the JavaScript Loose Augmentation Module Pattern. Core VIKI is declared as a submodule within the VIKI module called VikiJS, and any VIKI plugins with a JavaScript component are expected to be declared as submodules to VIKI as well.

If your JavaScript plugin is an object literal, it may take the following form:

If your JavaScript plugin is an object with a prototype, it may take the following form:

JavaScript Hook Functions
JavaScript hook functions all take the same parameters:
 * vikiObject – a reference to the VIKI object which this hook was called from
 * parameters – any parameters passed to the hook function (reference chart above)
 * hookName – the name of the hook this function was called from

All JavaScript hook functions must call  at the conclusion of their execution. is a JSON object of certain parameters that VIKI can handle. Currently, VIKI can handle three possible parameters:
 * - this will cause VIKI to redraw the entire graph at the completion of your hook.
 * - this will cause VIKI to redraw just the node you specify (below) at the completion of your hook.
 * - this passes a node back to VIKI to be used to redraw that node.

If the hook function involves one or more asynchronous operations, e.g. an AJAX call, care should be taken to ensure that hookCompletion is only called at the end of the last possible success/error handler, for example.

Wiki-Farm Support
VIKI is designed to support farms consisting of multiple wikis. If provided a list of known wikis, VIKI can recognize links between pages on different wikis as internal links and treat them as such, creating wiki page nodes in the graph and allowing for further elaboration of those pages. To take advantage of this, a plugin must perform the following actions:

  Register with the GetAllWikisHook.   During the function registered with this hook, access the VIKI object's allWikis array (empty by default).  Populate the object's allWikis array with objects containing the following key-value pairs:  Remember to call hookCompletion with the GetAllWikisHook name after populating the list. </li> </ol>
 * wikiTitle: title of wiki
 * apiURL: URL to the wiki's API, e.g. http://www.mediawiki.org/w/api.php
 * contentURL: wiki's content URL, usually the value of $wgServer + $wgArticlePath
 * logoURL: wiki's logo URL, which can be obtained from the value of $wgLogo
 * searchableWiki: whether this wiki is searchable through the MediaWikiAPI (boolean value). Note that if searchableWiki = false, then VIKI will recognize this wiki as a known wiki and will properly display pages from this wiki with the site logo, but this page cannot be elaborated in the graph because the API is closed.</li>

Below is an example of wiki data that VIKI could recognize:

Examples
We have developed several VIKI plugins which will be open-sourced over time. For now, two examples are available:
 * Extension:VikiSemanticTitle
 * Extension:VikiTitleIcon