This [Contributed Plugin] allows you to execute JavaScript code on the server. Useful for creating pages with dynamic content. This plugin is stable but experimental; clearly better wiki integration and server safety issues need to be addressed.

[{InsertPage page='SecurityRisk'}]

See also:
* [Groovy Plugin]
* [Tcl Plugin]

The plugin's JavaScript implementation is Mozilla's [Rhino|]. The public discussion for Mozilla's JavaScript implementations is at [netscape.public.mozilla.jseng|].

For more information please contact [Andrew Gilmartin] at

!! Building
To built you will need to add the following libraries to the project's lib directory:
* JSPWiki.jar from your JSPWiki 2.8 installation;
* servlet-api.jar from your Apache Tomcat 5.5 or 6.x installation;
* js.jar from Rhino 1.7 at [];

The plugin is available for

* JSPWiki 2.8, Rhino 1.7, and Apache Tomcat 6 at []
* others...

Then run {{ant}}.

The code does not yet conform to the [JSPWiki Coding Standard|My Coding Standard].

!! Installing

Copy the file {{build/jspwiki-js-plugin.jar}} and {{lib/js.jar}} to JSPWiki's {{WEB-INF/lib}} directory.

!! Using

The plugin is called using

%%( font-size: 80%; margin: 2ex; )
[{com.ingenta.jspwiki.plugin.js.JSPlugin scriptPage='wikiPage' scriptResult='text|xml|wiki' }]

[{com.ingenta.jspwiki.plugin.js.JSPlugin script='javascript' scriptResult='text|xml|wiki' }]

[{com.ingenta.jspwiki.plugin.js.JSPlugin scriptResult='text|xml|wiki'

.. javascript body content ..

[{scriptPage scriptResult='text|xml|wiki'

.. data body content ..

For most installations you need only refer to the plugin as ''JSPlugin'' as the installation will have added {{com.ingenta.jspwiki.plugin.js}} to the ''jspwiki.plugin.searchPath'' property.

The ''script'' and ''scriptPage'' parameter or body content selects the JavaScript code to execute. The ''scriptResult'' parameter determines how the script's result is further processed; ''xml'' result output is sent as is to the browser; ''text'' result output is send to the browser after escaping &, <, >, and " characters; ''wiki'' result output is send to the browser after first converting to HTML. The default scriptResult value is ''wiki''.

Using the ''scriptPage'' as the name of the plugin only works for JSPWiki implementations using the modified ''com.ecyrd.jspwiki.plugin.PluginManager'' supporting the ''jspwiki.plugin.unknownPlugin'' property. For more information see [ScriptedPlugin|].

During execution the following global variables are available to the script:

| wikiInfo | An instance of class JSWikiInfo
| wikiPage | An instance of class JSWikiPage for the page containing the plugin
| pluginArgs | An associative array containing the arguments to the plugin. For example {{format = pluginArgs[[ "scriptResult" ];}}.
| pluginBody | The content of the plugin body. This is only set if the body does not contain the script.

See [JSPluginScripts] for examples of scripts.

Note that the current interpreter is not a safe one. Thus all event, file, socket, and use of Java classes is enabled.

!! Class and method detail

! class ~JSWikiPage
| | The name of the page.
| | The author name of the most recient version.
| o.created | The creation date of the most recient version.
| o.modified | The last modified date of the most recient version.
| o.versionNumber | The version number of the most recient version.
| o.versions | Returns a list of page's versions. See JSWikiPageVersionInfo
| o.attachments | Returns a list of the page's attachments. See JSWikiPageAttachmentInfo
| o.content | Returns the content of the page.
| o.setContent( pageContent ) | Sets the content of the page (and creates a new version)

! class ~JSWikiPageVersionInfo
| | The name of the author.
| o.modified | The last modified date.
| o.versionNumber | The version number.

! class ~JSWikePageAttachmentInfo

|| method || description
| o.fileName | The attachment's file name.
| o.fileSize | The attachment's file size in bytes.

! class ~JSWikiInfo
|| method || description
| o.pluginVersion | The version number of this plugin.
| o.pages | Returns a list of the pages.
| o.hasPage( pageName ) | Returns true if the named page exists.
| o.getPage( pageName ) | Returns the named page. It is an error if the page does not exist.
| o.createPage( pageName, pageContent ) | Creates a new page with the given name and content. It is an error if the page already exists.
| o.deletePage( pageName ) | Deletes the named page. It is an error if the page does not exist.