-
Notifications
You must be signed in to change notification settings - Fork 6
Home
In Semantic MediaWikis@SMW the data model is defined through semantic attributes and the usage of templates. The Semantic Forms Extension@SemanticForms builds on top of that and adds the capability to define forms.
The Attributes, Templates and Forms are implemented as Wiki Pages, using the wikitext syntax. Templates can be reused in different Forms, but almost all the options how to generate the forms are within the forms itself and cannot be shared. Depending on the model this introduces a lot of duplicate code that makes the maintenance and consistency of the model difficult.
There is already a schema based extension available, called Page Schemas@PageSchemas which embeds additional XML into the Wiki sites and has a web based GUI. However this extension supports no inheritance. Given the case that two or more forms share the same model but require minor details to be different, the template has to be duplicated and adjusted.
In the following sections an alternative approach based on JSON Schema and Node.js will be introduced.
The developed toolset is collection of CLI scripts that work as a MediaWiki Bot. Additionally it provides a rudimentary web GUI. The toolset its not integrated into the MediaWiki software in any way, it runs completely independent on the developers computer. This is further explained through the next sections.
JSON Schema@JSONSchema is an Internet Engineering Task Force (IETF) standard which is currently in draft state. It is somewhat similar to the better known XML Schema@Beech:12:WXS but relies on the simpler JSON format instead of XML, which makes it easier to use and to learn. JSON Schema can be easily extended through custom attributes.
Using a schema in general provides several advantages: With a single schema the user can define the expected structure of the resulting data. Thus it can serve both for client-side and server-side validation.
The schema can not just be used for the obvious validation purposes. It is possible to auto-generate complete forms@JSONEditor, user documentation@Docson, random content@SchematicIpsum or UI elements just from the schema information.
To avoid duplicate code in the model it is useful to support features like inheritance. JSON Schema already supports $ref attributes that allow the aggregation of external JSON Schema files. Depending on the implementation this does support inheritance or not.
To avoid misconceptions and make this more obvious the toolset implements its own JSON Schema interpreter which introduces a few additional properties. In this case $extend is introduced. It creates a deep copy of the current object/scope it is in and merges the referenced object in. If an property already exists, the referenced object will overwrite it with its own property. This also implicitly defines the relationships between the different objects. From those a graph oriented database model is generated.
Below, a simple example of an abstract model:
The following model will inherit its properties and extend them:
Note that the property “radius” is also inherited. The following JSON object is not a complete JSON Schema; it just describes a single property. That way properties can be shared between different models.
To meet the requirements of SMW the model orients itself some along the SMW Structure of Attributes, Templates and Forms. The development model consists of Fields, Models and Forms. While those map roughly to their SMW counterparts, there are differences: Since properties can be inherited from bottom to top, a field can contain information how it should be rendered and validated in the form. Those information are inherited and can be overwritten through the model up to the form. In SMW Forms this has to be defined in the form itself along with many other information. A SMW attribute contains only the datatype, a template only the names of attributes used and how they should be rendered in the final document.
The toolset is based on modern web technologies and tools. It is written in JavaScript and uses Node.js@Node.js. It is a collection of modules and CLI scripts. Automation is provided via the Grunt Task Runner@Grunt. The user-interface provided through a Node.js webserver as a HTML5 web app.
The toolset consists of CLI scripts that are run through the Node.js interpreter. Behind those there are various Node.js modules that can be used and shared between the scripts if necessary.
The main script that handles the complete development workflow works as follows:
-
Search the filesystem for JSON Schema files that define the model. Those will be loaded and stored into an internal registry.
-
Search the filesystem for files that contain the last upload state
-
Use a recursive inheritance algorithm which first includes all fields into the models, then handles model to model inheritance and then inherits the models into the forms. While this is being done the toolset also builds a graph structure (that can be imported to Gephi@Gephi and viewed through the GUI) of the model and validates for common errors.
-
After the model is complete it is converted from JSON Schema to the final wikitext structure. This is done through some preprocessing that handles specific logic and the Handlebars.js@Handlebars.js template engine. The resulting wikitext with their according sitenames is stored into the internal registry.
-
Calculate the difference between the new state and the last uploaded state if availabe.
-
Use a bot account to log into an external wiki to upload and delete the sites accordingly. A report of the bot activity will be uploaded too.
Several options are available to configure the system, skip specific steps or force others (like full upload).
If the Grunt taskrunner is used it will look for changes in the filesystem and trigger the scripts accordingly in real-time. If the developer changes the content of a field this will automatically trigger the recalculation of the model and the upload of only those Wiki sites that are affected through this change. See Fig. \ref{fig:cli} as an example.
\centering![CLI Script example][]
\label{fig:cli}
To gain some insight about the current state of the model and preview its state in the browser the toolset also provides a web GUI (Fig. \ref{fig:webgui}). Node.js is used as a webserver to provide the sites. The GUI lists and displays the completely calculated and inherited fields, models and forms from the development model. It also lists all generated Wiki sites in the resulting wikitext format.