Write an Editor in a Wiki Page

Last modified by superadmin on 2026/10/14 10:44

Steps

Add an editor to a running instance without compiling anything, by writing it as a wiki page instead of in Java.

The editor is an XWiki.EditorClass object on a page, and the object's properties say what it edits, under which identifier and with which code. The example below is a plain text area for wiki content, in the text category.

  1. Create the page that will hold the editor. Its title becomes the editor's name and its content the editor's description, read from the translated page every time the editor is described, so both follow the reader's language:
    Title:   Simple Text Area
    Content: A plain text area with no toolbar, for editing wiki syntax by hand.
  2. Add an object of type XWiki.EditorClass to that page with the Object editor:

    The object editor of the Simple Text Area page, with EditorClass typed in the New object field and XWiki EditorClass offered in the drop down list below it

  3. Fill the object's six properties:
    PropertyValue in this exampleWhat it is
    Data Typeorg.xwiki.rendering.syntax.SyntaxContentthe Java type the editor edits
    Role Hintsimple-textareathe editor's identifier
    Code(the next step)the wiki content that produces the editor
    Iconpencilthe icon shown for the editor
    Categorytextthe editing mode the editor belongs to
    ScopeCurrent Wikiwhere the editor is registered

    The EditorClass object of the Simple Text Area page, with Data Type set to org.xwiki.rendering.syntax.SyntaxContent, Role Hint to simple-textarea, the Code property holding the editor code, Icon set to pencil, Category to text and Scope to Current Wiki

    The first two decide whether the editor exists at all: the query that collects the editors defined in wiki pages skips an object whose Role Hint is empty, and an object whose Data Type is not a type the instance can load fails to register, with the reason in the log. Scope is the one thing a Java editor cannot choose: Current User registers the editor for the page's author only, Current Wiki for the wiki holding the page, Global for every wiki of the farm, and an empty value is read as Current Wiki.

  4. Write the Code property. Unlike the template of a Java editor it is page content, so it is written in the page's own syntax and may use macros. It reads $edit.data and $edit.parameters from the same edit binding a Java editor's template uses:
    {{velocity}}
    {{html clean="false"}}
    <div class="box infomessage">Editing $escapetool.xml($edit.data.syntax.toIdString()) content.</div>
    <textarea id="$!edit.parameters.id" name="$!edit.parameters.name"
      rows="$!edit.parameters.rows" cols="$!edit.parameters.cols">$escapetool.xml($edit.data.content)</textarea>
    {{/html}}
    {{/velocity}}
    Warning

    The code runs with the rights of the editor page's author, but in the context of the page being edited, which is how it reaches the data put on the script context. Giving edit right on the editor page is therefore giving the ability to run code for everyone who opens the editor.

  5. Save the page. The editor is registered as soon as the page is saved, and naming it in the query string of an edit URL is enough to see it at work on the data type and category it declared:
    /bin/edit/Sandbox/MeetingNotes?editor=wiki&SyntaxContent.text.editor=simple-textarea

    The wiki edit form of the Meeting Notes page rendering the Simple Text Area editor, with the message Editing xwiki 2.1 content above the content text area

    To hand the editor to a user, a space or the whole wiki without naming it in the URL, see Configure the Default Editor.

Two of the editors shipped with XWiki are written this way and are worth reading as examples: CKEditor.SyntaxContentEditor registers ckeditor in the wysiwyg category, and XWiki.Realtime.WikiEditor registers realtime-wiki in the text category, both with the Current Wiki scope. Both keep the editor code in the page content and set the Code property to an include of their own page, and both guard that content so that it renders only while the page is being used as an editor, which keeps it out of the editor's description.

Related

Get Connected