cogDefines a way to add User Interface Extensions to the XWiki platform
TypeJAR
Category
Developed by

XWiki Development Team

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise

Description

Introduction

XWiki is a platform made of a collection of Extensions. Extensions can contribute UI changes through:

The goal of UI Extensions is to offer another way to contribute some small UI changes without requiring to build a completely new Skin. More precisely, through the concepts of UI Extension Points/UI Extension, it allows Skins (and any Extensions) to provide places in the UI to let other Extensions contribute some custom content that will be inserted.

Terminology:

  • UI Extension Points (known as UIXP): A place in the UI where Extensions can contribute custom content that will be inserted 
  • UI Extension (known as UIX): Some custom content to insert

To get an idea of UIXP, you can check the exhaustive list of existing UI Extension Points.

Writing a simple UI Extension

In this example we will write an extension for the Applications Panel UI Extension Point (ID: org.xwiki.platform.panels.Applications).

To create a UI Extension you need to:

Create a new document, for example Main.HelloWorldUIExtension

UIExtension-Step1.png

Switch to the object editor

UIExtension-Step2.png

Add a XWiki.UIExtensionClass object to it

UIExtension-Step3.png

Fill the information required by the UIXP (you need to refer to the UIXP documentation at this point). In this example the extension point requires the following:

  • Extension Point ID: in our example org.xwiki.platform.panels.Applications
  • Extension Name: any name would be fine but we're following a rule for this EP "platform.panels." + the name of your extension, in our case "HelloWorld"
  • Extension Content: the EP doesn't require any here
  • Extension Parameters: here's the important part, the EP requires 3 parameters:
    • label: the label of the link that will be created
    • target: the target of the link that will be created, it must be a reference to a document
    • icon: the icon that will be put in the link, it must be a reference to an image, to look good this image must be 16 pixels in both height and width. 
  • Extension Scope: defines where and for who your extension will appear: only in the current wiki (default value), globally (for a whole wiki farm) or only for the current user (ie. you, the user who wrote the extension)

UIExtension-Step4.png

Save the document

UIExtension-Step5.png

You can now see a new entry in the Applications Panel

UIExtension-Step6.png

More Details

When you contribute a new UIX, you should know the following:

  • The UIX Content can contain wiki syntax (in the syntax of the page holding the UIX xobject)
  • The UIX Parameters can contain Velocity scripts (each parameter's value is evaluated with Velocity). For example the following would work:
    label=$services.localization.render("key")

UI Extension Points

UIXP are "declared" or "created" through a call to the UIX api:

$services.uix.getExtensions('module.extensionPointId')

While they are easy to created you must remember that the UIXP itself will be considered as an API. They must not be renamed or removed once they've been released. 

Filters can be applied to the list of retrieved extensions, in order to exclude some of them for example. Filters are passed to the API through a Map:

$services.uix.getExtensions('module.extensionPointId', { "exclude" : "module.extensionToExclude, module.someOtherExtension" })
$services.uix.getExtensions('module.extensionPointId', { "exclude" : "module.extensionToExclude", "sortByParameter" : "parameterKey" })

The list of available filters is the following:

  • exclude : takes a list of UI Extension IDs as parameter. Those extensions won't be retrieved.
  • select : takes a list of UI Extension IDs as parameter. Only the listed extensions will be retrieved
  • sortByCustomOrder : takes a list of UI Extension IDs as parameter. The extensions will be in the same order as they've been listed, additional extensions will be put at the end of the list.
  • sortById : takes an empty string as parameter. The extensions will be ordered by their IDs, alphabetically.
  • sortByParameter : takes a parameter key as parameter. The extensions will be ordered by the value of this parameter, alphabetically. If all the parameter values appear to be numbers they will be numerically ordered.

Available UI Extension Points

Here is the exhaustive list of UI Extension Points (EP).

Tags:
Created by Jean-Vincent Drean on 2012/09/12 18:20
    

Get Connected