PHP Macro

This is a XWiki macro, which isn't bundled with any XWiki product by default.
Macro developed by the XWiki Development Team.
This macro can be downloaded.

PHP Macro

This macro executes embedded PHP scripts.

Usage:

{{php}}<?php echo 'Hello World!'; ?>{{/php}}

Result:
Hello World!

Installation

To use the php macro, you need to install the following three libraries inside WEB-INF/lib directory of your XE installation:

Once these libraries are in place, you need to restart your XE installation for the changes to take effect.

Unfortunately, the quercus library does not contain all the PHP libraries, so at startup you will get some exceptions in the logs, like:

INFO: Failed loading com.caucho.quercus.lib.dom.DOMText
java.lang.ClassNotFoundException: com.caucho.quercus.lib.dom.DOMText

The missing modules are: bam, dom, pdf, and resin. If you want to use them, they are found in the main Resin jar.

Usage

Unlike the other scripting languages available for XWiki, PHP is a semi-templating scripting language, which means that it must explicitly wrap code sections inside <?php ?> markers:

Some *wiki* content.
{{php}} Some static content inside the PHP macro,
<?php echo("and some dynamic content."); ?> {{/php}}

A current limitation of the Quercus library is that variables and class definitions are only valid inside the same macro block.

{{php}} <?php $i = 5; ?>
$i will be visible inside the same macro block:
<?php echo ($i); ?>
The correct value of i will be printed, 5.
{{/php}}

Unfortunately, here $i will not be valid:

{{php}} <?php echo ($i); ?> {{/php}}

Licensing

Quercus is licensed under the GPL, so using it inside your wiki will force the entire software to respect the GPL license.

Tags:
Created by Guillaume Lerouge on 2009/10/21 17:50
Last modified by Sergiu Dumitriu on 2009/10/26 19:05

This wiki is licensed under a Creative Commons license
2.2.1.27354