Programming

Version 14.6 by Vincent Massol on 2017/09/07

Bored of simple text in your pages? Are you interested in giving life to your wiki? Then you can make use of XWiki's powerful programming API directly from your wiki pages. XWiki offers support for several scripting languages: Velocity, Groovy, Python, Ruby and even PHP.

XWiki exposes APIs that allows you to manipulate the wiki and its pages easily.

To whet your appetite simply put the following code in your page:

{{velocity}}
#set($query = "where doc.parent is null or doc.parent='' order by doc.name asc")

#foreach($item in $services.query.xwql($query).execute())
#set($orphanedDoc = $xwiki.getDocument($item))
  * [[$orphanedDoc.displayTitle>>$orphanedDoc]] (located in space //$orphanedDoc.space//, contains $orphanedDoc.attachmentList.size() attachments)
#end
{{/velocity}}

You'll get a list of orphaned pages (i.e. pages that have no parent). For example:

velocityexampleresult.png

Check the Developer's Guide and especially the XWiki Scripting section to learn more.

You might also want to check out the Snippets wiki which contains a lot of code snippets that you can reuse in your pages. And you can also check the Extensions wiki to install ready-to-use extensions built using these mechanisms.

Get Connected