This page (revision-1) was last changed on 2019-12-18 09:13 by UnknownAuthor

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 added 140 lines
The __[IffPlugin]__ extends the JSPWiki [IfPlugin|JSPWiki:IfPlugin] to include support for page attributes and an '{{ELSE}}' alternative text (if the test
fails). This plugin is designed to and may replace the IfPlugin (in which case its name would be changed to "IfPlugin").
See the [IffPluginTestPage] for examples.
----
The __IfPlugin__ is a [JSPWikiPlugin] that allows parts of a WikiPage to be executed conditionally. You can also use the shorthand "If" to run it.
!! Parameters:
* __group__ = '''list'''. A "|"-separated list of group names
* __user__ = '''list'''. A "|"-separated list of user names
* __ip__='''list'''. A "|"-separated list of IP addresses
* __attribute__='''attribute'''. A page attribute
* __var__='''name'''. A [WikiVariable|JSPWiki:WikiVariable]
* __page__='''name'''. A page name
* __contains__='''regex'''. A Perl5 [regexp|JSPWiki:RegularExpressionSyntax] pattern
* __is__='''regex'''. A Perl5 [regexp|JSPWiki:RegularExpressionSyntax] pattern
* __exists__='''true|false'''
!! Usage
If any of them match, the body of the plugin is executed. You can negate the content by prefixing it with a "{{!}}". For example, to greet all admins, put the following in your LeftMenu:
{{{
[{If group='Admin'
Hello, Admin, and your mighty powers!}]
}}}
In order to send a message to everybody except Jack use
{{{
[{If user='!Jack'
%%warning
Jack's surprise birthday party at eleven!
%%}]
}}}
Note that you can't use {{"!Jack|!Jill"}}, because for Jack, {{!Jill}} matches; and for Jill, {{!Jack}} matches. These are not [regular expressions|JSPWiki:RegularExpressionSyntax] (though they might become so in the future).
To check for page content, use
{{{
[{If page='TestPage' contains='xyzzy'
Page contains the text "xyzzy"}]
}}}
The difference between "{{contains}}" and "{{is}}" is that "{{is}}" is always an exact match, whereas "{{contains}}" just checks if a pattern is available.
To check for page existence, use
{{{
[{If page='TestPage' exists='true'
Page "TestPage" exists.}]
}}}
With the same mechanism, it's also possible to test for the existence of a variable - just use "{{var}}" instead of "page".
To check for the existence of a page attribute, use
{{{
[{If page='TestPage' attribute='10.author'
This page has had at least ten authors.}]
}}}
To check the specific value of a page attribute, include an equals ('=') sign in the parameter value, e.g.,
{{{
[{If page='TestPage' attribute='*.author=Janne.*'
This page has been authored by Janne.}]
}}}
Use can use Perl-style regular expressions in both the attribute name and value.
!! Use of 'ELSE'
If the plugin body contains an uppercase "ELSE" the plugin will include the content of the body before the ELSE if
the test returns true, otherwise the content after the ELSE if false.
{{{
[{If page='TestPage' attribute='*.author=Janne.*'
This page has been authored by Janne.
ELSE
This page was not authored by Janne.
}]
}}}
!! Notes
Another caveat is that the plugin body content is not counted towards ReferenceManager links. So any links do not appear on any reference lists. Depending on your position, this may be a good or a bad thing, though considering that the purpose of this plugin is to ''conditionally'' include the content, any links should only be counted by the ReferenceManager if the plugin test ''passed.''
! Note
In general, the content of a plugin is considered a part of the parent page.
This means that showing the source of a page (view page source) will reveal the content of every plugin.
Actually, retrieving the source of a page does not invoke the plugin itself.
{{{
[{If user='Simon'
Secret stuff of simon
}]
}}}
The {{Secret stuff of simon}} will only be shown on the page when Simon is logged in. However this info will be accessible to other users when they access the page source (view page source) or open the page for editing.
You can avoid this by putting the ''secret'' plugin content in another page, eg. by using the [InsertPagePlugin] plugin. This other page will then contain an {{ [[{ALLOW ... }] }} ACL to define the right security rules.
The access to that page will always pass via the security gates of JSPWiki before revealing its content to the user.
{{{
[{If user='Simon'
[{InsertPage page=SimonsSecretStuff}]
}]
}}}
This plugin can also be used to secure parts of a page, such as:
{{{
[{If var='loginstatus' is='authenticated'
This part of the page is only for authenticated users.
}]
}}}
----
See: [JSPWikiCorePlugins|JSPWiki:JSPWikiCorePlugins]
----
[Category.Plugins|JSPWiki:Category.Plugins]