什么是XWiki脚本
XWiki脚本可以视为更高级的文档编辑语法,可以在脚本内调用后台接口。目前XWiki支持的脚本语言有
- Velocity Macro (installed by default in XWiki)
- Groovy Macro (installed by default in XWiki)
- Python Macro (installed by default in XWiki)
- Ruby Macro (not installed by default in XWiki)
- PHP Macro (not installed by default in XWiki)
授权
想要使用脚本进行文档编辑的话需要授权,需要把script权限打开。
快速体验
XWiki页面很多扩展都是用脚本实现的其中大部分都是用Velocity写的,一小部分复杂的功能是Groovy。比如,想要定制一条用户欢迎语,可以这样实现
{
{groovy}}
println("Your username is " + xcontext.getUser() + " welcome to the site.");
{
{/groovy}}
这个脚本获取了当前用户名,并且显示欢迎语,效果如下
XWiki脚本API
XWiki提供了一些已经绑定好的对象,在脚本中可以直接调用:
- 当前文档: doc
- Request的上下文: xcontext
- Request对象: request
- Response对象: response
- XWiki对象: xwiki
- The XWiki utils: util (deprecated)
- Various Script Services: services(自定义的后台服务就注册在该对象下)