Extensions Wiki » Extensions » PHP Macro

PHP Macro

Last modified by Thomas Mortagne on 2013/06/04 08:19
cogAdds ability to write scripts in PHP in wiki pages
TypeJAR
Developed by

XWiki Development Team

LicenseGNU Lesser General Public License 2.1
Installable with the Extension Manager

View Source

Download v5.0.3

Description

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:

Parameters definition

See the Script Macro for details.

Example 1

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

Result:
 Hello World!

Example 2

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

Limitations

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}}

Prerequisites & Installation Instructions

Put the jar file into WEB-INF/lib folder and restart XWiki.


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.

Dependencies

  • org.xwiki.rendering:xwiki-rendering-api 5.0.3
  • com.caucho:resin-quercus 3.2.1
  • org.xwiki.rendering:xwiki-rendering-transformation-macro 5.0.3
  • org.xwiki.platform:xwiki-platform-rendering-macro-script 5.0.3
Tags: php script
Created by Guillaume Lerouge on 2009/10/21 17:50

Download XWiki