At the moment it is really hard for plugins to know where their handlers were invoked from. One of the problems this causes is that a plugin which generates active content (e.g. forms and javascript) doesn't know if the context is a
view, a
preview, an
rdiff or a
changes. So the plugins have to use rather dodgy methods of trying to determine their context. For example,
CommentPlugin does this:
my $scriptname = $ENV{'SCRIPT_NAME'} || '';
my $previewing = ($scriptname =~ /\/(preview|gnusave|rdiff)/);
It would be much better to have a reliable way for a plugin to determine what context it is in. Here are some of the context identifiers I would find useful in my various plugins:
| Context |
Comments |
| active |
Plain view requiring active content e.g. view, edit |
| passive |
Plain view requiring disabled content e.g. preview, rdiff. Mutually exclusive with active. |
| text |
Rendering main text body |
| include |
Rendering included text |
| formfield= |
Rendering form field data |
| template |
Rendering template text |
(Please add to/modify the table above as appropriate)
The specific proposal is to add:
StaticMethod TWiki::Func::getContext() -> $attrs
-
$attrs - comma-separated list of attributes of the current context.
Determine the context of this handler call. For example, to determine if a form input field should be disabled in the current rendering context, you might write:
my $context = TWiki::Func::getContext();
if( $context =~ /\bpassive\b/ ) {
$_[0] =~ s/%TAG%/<input disabled="disabled" name="bah" value="BAH" \/>/g;
} elsif( $context =~ /\bactive\b/ ) {
$_[0] =~ s/%TAG%/<input name="bah" value="BAH" \/>/g;
} else {
# neither active nor passive, so don't do any changes to the text
}
Contributors:
CrawfordCurrie
No comments or support, so I'm moving this off the Dakar list.
Done in Dakar.