Extension:VIKI/Developer Notes
Appearance
Below are notes on the structure and code path of the VIKI extension.
Files
[edit]- VIKI.php - legacy for MW 1.24 and earlier
- VikiJS.class.php - PHP side, hooks, sets up VIKI.js to run, also load resource modules for VIKI plugins
- vex.js (version 2.0.1) used for modals, spin.min.js (version 2.0.1) for the spinner, contextmenu.js (version r2) for the right-click menu
- VIKI.js: where all the action takes place; most of the functions are already documented in the file
- entry point:
initialize()
, sets up a lot of the views, callsInitializationCompleteHook
andGetAllWikis
hook and/orGetAllWikis
hookCompletion()
, which then callsfetchContentNamespaces()
fetchContentNamespaces()
fetches all content namespaces, and on completion, callspopulateInitialGraph()
populateInitialGraph()
->startElaboratingNodes()
creates nodes from the initial set, adds them to graph, visits them (to verify existence, get categories, etc), and callselaborateWikiNode()
on each of the elaborate-able nodes
- entry point:
Node management
[edit]- Node objects are created in
createExternalNode()
,createWikiNodeFromWiki()
, andcreateWikiNodeFromExternalLink()
- They're not added to the graph until
addNode()
is called addNode()
does not automatically redraw the graph, because redraws can be expensive;redraw()
calls are explicit and generally only after a batch of nodes are added- D3 doesn't have (very easy) built-in support for hiding and showing nodes and links, which makes for tricky code scattered throughout VIKI related to carefully hiding and showing nodes and links by removing them from the node and link arrays... this is a limitation of D3.
Node Elaboration
[edit]- probably needs to be refactored, it's pretty ugly
elaborateWikiNode()
takes parameters:node
,completionHandler
block, andelaborationType
(initial population, normal, or 2nd order)- makes three AJAX calls to get links out, links in, and external links
checkElaborationQueriesComplete()
only proceeds when all three calls have returned, thencompleteElaboration()
called oncecompleteElaboration()
calls the success handlers of all three AJAX types, then conditionally callsfindSecondOrderLinks()
(if this wasn't already a 2nd order link query and the flag is set to find 2nd order links)findSecondOrderLinks()
callselaborateWikiNode()
on all these nodes again to find 2nd order links, this time with the elaborationType for 2nd order links- these three success handlers are very similar, probably have duplicate code and probably could be combined with some logic
- there are tons of conditionals that handle a lot of edge cases
- there is careful logic to add a new node only if the node's not already in the graph, and to add links if they're not already in the graph
Node Hiding
[edit]- each node maintains boolean flags for reasons it may want to be hidden: hidden category, explicitly hidden by user, hidden as part of a hub, or is an incoming/outgoing link (and the user selected "hide incoming links" or "hide outgoing links")
- hiding functions will filter for the appropriate nodes, set their appropriate flag, and call
hideNode()
- unhiding functions will call
unhideNodesIfValid()
to selectively un-hide nodes hideNode()
does not explicitly callredraw()
on the graph - the calling hide function (e.g.hideCluster()
) must do theredraw()
afterward.