internal package
Foswiki::Plugins::EmptyPlugin Foswiki::Func
writeWarning
and
writeDebug
functions. These logs can be found in the Foswiki/working/logs
directory. You can also print STDERR
; the output will appear in the
webserver error log. The ENVironment setting $ENV{FOSWIKI_ASSERTS}
setting makes
Foswiki less tolerant of errors, and it is recommended to set it during
development. It can be set by editing bin/LocalLib.cfg
, (If missing, see bin/LocalLib.cfg.txt
)
Most handlers can also throw exceptions (e.g.
Foswiki::OopsException)
For increased performance, all handler functions except initPlugin
are
commented out below. To enable a handler remove the leading #
from
each line of the function. For efficiency and clarity, you should
only uncomment handlers you actually use.
NOTE: When developing a plugin it is important to remember that
Foswiki is tolerant of plugins that do not compile. In this case,
the failure will be silent but the plugin will not be available.
See InstalledPlugins for error messages.
NOTE: Foswiki:Development.StepByStepRenderingOrder helps you decide which
rendering handler to use. When writing handlers, keep in mind that these may
be invoked on included topics. For example, if a plugin generates links to the
current topic, these need to be generated before the afterCommonTagsHandler
is run. After that point in the rendering loop we have lost the information
that the text had been included from another topic.
NOTE: Not all handlers (and not all parameters passed to handlers) are
available with all versions of Foswiki. Where a handler has been added
the POD comment will indicate this with a "Since" line
e.g. Since: Foswiki::Plugins::VERSION 1.1
Deprecated handlers are still available, and can continue to be used to
maintain compatibility with earlier releases, but will be removed at some
point in the future. If you do implement deprecated handlers, then you can
do no harm by simply keeping them in your code, but you are recommended to
implement the alternative as soon as possible.
See http://foswiki.org/Download/ReleaseDates for a breakdown of release
versions.
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$user
- the login name of the user
$installWeb
- the name of the web the plugin topic is in (usually the same as $Foswiki::cfg{SystemWebName}
)
Foswiki::Func::writeWarning
and return 0. In this case
%FAILEDPLUGINS% will indicate which plugins failed.
In the case of a catastrophic failure that will prevent the whole
installation from working safely, this handler may use 'die', which
will be trapped and reported in the browser.
Note: Please align macro names with the Plugin name, e.g. if
your Plugin is called FooBarPlugin, name macros FOOBAR and/or
FOOBARSOMETHING. This avoids namespace issues.
initPlugin
is called, before any preferences are loaded, before
even the store is loaded, and before the user has been identified.
It is intended for use when there is sufficient information available
from the request object and the environment to make a decision
on something. For example, it could be used to check the source IP
address of a request, and decide whether to service it or not.
preload
can use the methods of Foswiki::Func
to access the request,
but must not access the store, or any user or preference information.
Caveat emptor! You have been warned!
The best way to terminate the request from preload
is to throw an
exception. You can do this using a die
, which will result in a
text/plain
response being sent to the client. More sophisticated
implementations can use Foswiki::OopsException
to craft a response.
Since: Foswiki 2.0
preload
but before initPlugin
. It is
called after the Foswiki infrastructure has been set up. If it returns
a non-null error string, the plugin will be disabled. You can also
terminate the request from this method by throwing one of the
exceptions handled by Foswiki::UI
(for example, Foswiki::OopsException
).
$loginName
- login name recovered from $ENV{REMOTE_USER}
$url
- request url
$path_info
- path_info from the Foswiki::Request
earlyInitPlugin
.
Since: Foswiki::Plugins::VERSION = '2.0'
$data
- a hashref containing all the formfields POSTed to the registration script
die
)
Since: Foswiki::Plugins::VERSION = '2.0'
$web
- the name of the web in the current CGI query
$wikiName
- users wiki name
$loginName
- users login name
$data
- a hashref containing all the formfields POSTed to the registration script
$text
- text to be processed
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$included
- Boolean flag indicating whether the handler is invoked on an included topic
$meta
- meta-data object for the topic MAY BE undef
Foswiki::Func::registerTagHandler
(see initPlugin
).
Internal Foswiki macros, (and any macros declared using
Foswiki::Func::registerTagHandler
) are expanded before, and then again
after, this function is called to ensure all %MACROS% are expanded.
NOTE: when this handler is called, <verbatim> blocks have been
removed from the text (though all other blocks such as <pre> and
<noautolink> are still present).
NOTE: meta-data is not embedded in the text passed to this
handler. Use the $meta
object.
NOTE: Read the developer supplement at
Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
addToZone()
from this handler
Since: $Foswiki::Plugins::VERSION 2.0
$text
- text to be processed
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$meta
- meta-data object for the topic MAY BE undef
commonTagsHandler
i.e. it may be called many times during the
rendering of a topic.
NOTE: meta-data is not embedded in the text passed to this
handler.
NOTE: This handler is not separately called on included topics.
NOTE: Read the developer supplement at
Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
addToZone()
from this handler
$text
- text to be processed
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$meta
- meta-data object for the topic MAY BE undef
commonTagsHandler
i.e. it may be called many times during the
rendering of a topic.
NOTE: meta-data is not embedded in the text passed to this
handler.
NOTE: Read the developer supplement at
Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
addToZone()
from this handler
$text
- text, with the head, verbatim and pre blocks replaced with placeholders
\%removed
- reference to a hash that maps the placeholders to the removed blocks.
<pre class='slobadob'> XYZ </pre>the map will contain:
$removed->{'pre1'}{text}: XYZ $removed->{'pre1'}{params}: class="slobadob"Iterating over blocks for a single tag is easy. For example, to prepend a line number to every line of every pre block you might use this code:
foreach my $placeholder ( keys %$map ) { if( $placeholder =~ m/^pre/i ) { my $n = 1; $map->{$placeholder}{text} =~ s/^/$n++/gem; } }NOTE: This handler is called once for each rendered block of text i.e. it may be called several times during the rendering of a topic. NOTE: meta-data is not embedded in the text passed to this handler. NOTE: Read the developer supplement at Foswiki:Development.AddToZoneFromPluginHandlers if you are calling
addToZone()
from this handler
Since Foswiki::Plugins::VERSION = '2.0'
$text
- the text that has just been rendered. May be modified in place.
addToZone()
from this handler
Since Foswiki::Plugins::VERSION = '2.0'
$text
- text that will be edited
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
edit
script is run.
NOTE: meta-data may be embedded in the text passed to this handler
(using %META: tags)
Since: Foswiki::Plugins::VERSION = '2.0'
$text
- text that is being previewed
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$meta
- meta-data for the topic.
preview
script is run.
NOTE: this handler is not called unless the text is previewed.
NOTE: meta-data is not embedded in the text passed to this
handler. Use the $meta
object.
Since: $Foswiki::Plugins::VERSION 2.0
$text
- text with embedded meta-data tags
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$meta
- the metadata of the topic being saved, represented by a Foswiki::Meta object.
$text
(using %META: tags). If you modify
the $meta
object, then it will override any changes to the meta-data
embedded in the text. Modify either the META in the text or the $meta
object, never both. You are recommended to modify the $meta
object rather
than the text, as this approach is proof against changes in the embedded
text format.
Since: Foswiki::Plugins::VERSION = 2.0
$text
- the text of the topic excluding meta-data tags (see beforeSaveHandler)
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$error
- any error string returned by the save.
$meta
- the metadata of the saved topic, represented by a Foswiki::Meta object
$oldWeb
- name of old web
$oldTopic
- name of old topic (empty string if web rename)
$oldAttachment
- name of old attachment (empty string if web or topic rename)
$newWeb
- name of new web
$newTopic
- name of new topic (empty string if web rename)
$newAttachment
- name of new attachment (empty string if web or topic rename)
\%attrHash
- reference to hash of attachment attribute values
$meta
- the Foswiki::Meta object where the upload will happen
attachment
=> the attachment name - must not be modified
user
- the user id - must not be modified
comment
- the comment - may be modified
stream
- an input stream that will deliver the data for the attachment. The stream can be assumed to be seekable, and the file pointer will be positioned at the start. It is not necessary to reset the file pointer to the start of the stream after you are done, nor is it necessary to close the stream.
{stream}
to a
new stream.
For example:
sub beforeUploadHandler { my ( $attrs, $meta ) = @_; my $fh = $attrs->{stream}; local $/; # read the whole stream my $text = <$fh>; # Modify the content $text =~ s/investment bank/den of thieves/gi; $fh = new File::Temp(); print $fh $text; $attrs->{stream} = $fh; }Since: Foswiki::Plugins::VERSION = 2.1
\%attrHash
- reference to hash of attachment attribute values
$meta
- a Foswiki::Meta object where the upload has happened
attachment
=> the attachment name
comment
- the comment
user
- the user id
differences
array is an array of hash references, where each hash contains the
following fields: $diff
=> one of the characters '+', '-', 'c' or ' '. new
contains text inserted in the new version
old
contains text deleted from the old version
old
contains text from the old version, and new
text from the version being saved
new
contains text common to both versions, or the change only involved whitespace
$old
=> text from version currently saved
$new
=> text from version being saved
\%info
is a reference to the form field description { name, title, type, size, value, tooltip, attributes, referenced }. It must not be wrtten to. This parameter will be undef when merging the body text of the topic.
{ diff=>'c', old=>'Leafy', new=>'Barky' }
might be resolved as
'Treelike'
. If the plugin cannot resolve a difference it should return
undef.
The merge handler will be called several times during a save; once for
each difference that needs resolution.
If any merges are left unresolved after all plugins have been given a
chance to intercede, the following algorithm is used to decide how to
merge the data: new
is taken for all radio
, checkbox
and select
fields to resolve 'c' conflicts
<del>conflict</del> <ins>markers</ins>
are used to mark 'c' merges in text fields
\%headers
- reference to a hash of existing header values
$query
- reference to CGI query object
$headers->{expires} = '+1h';Note that this is the HTTP header which is not the same as the HTML <HEAD> tag. The contents of the <HEAD> tag may be manipulated using the
Foswiki::Func::addToHEAD
method.
Since: Foswiki::Plugins::VERSION 2.0
$name
- name of form field
$type
- type of form field (checkbox, radio etc)
$size
- size of form field
$value
- value held in the form field
$attributes
- attributes of form field
$possibleValues
- the values defined as options for form field, if any. May be a scalar (one legal value) or a ref to an array (several legal values)
Foswiki::Form::FieldDefinition
to implement
the new type (see Foswiki::Extensions.JSCalendarContrib
and
Foswiki::Extensions.RatingContrib
for examples). This is the preferred way to
extend the form field types.
$linkText
- the text for the link i.e. for [[Link][blah blah]]
it's blah blah
, for BlahBlah
it's BlahBlah
, and for BlahBlah it's Blah Blah
.
$hasExplicitLinkLabel
- true if the link is of the form [[Link][blah blah]]
(false if it's =[Blah]] or =BlahBlah
)
$web
, $topic
- specify the link being rendered
$html
- the body of the page (normally <html>..$lt;/html>)
$httpHeaders
- the HTTP headers. Note that the headers do not contain a Content-length
. That will be computed and added immediately before the page is actually written. This is a string, which must end in \n\n.
$session
- The Foswiki object associated with this request.
$subject
- The invoked subject (may be ignored)
$verb
- The invoked verb (may be ignored)
$response
reference to the Foswiki::Response object that is used to compose a reply to the request
redirectto
parameter is not present on the request, then the return
value from the handler is used to determine the endpoint for the
request. It can be: undef
- causes the core to assume the handler handled the complete request i.e. the core will not generate any response to the request.
text
- any other non-undef value will be written out as the content of an HTTP 200 response. Only the standard headers in the response are written.
view
, diff
, etc. the static
context is used
to indicate that the resulting output will be read offline, such as in a PDF, and
dynamic links (edit, sorting, etc) should not be rendered.
A comprehensive list of core context identifiers used by Foswiki is found in
IfStatements Please be careful not to
overwrite any of these identifiers!
For more information, check CommandAndCGIScripts
For information about handling error returns from REST handlers, see
Foswiki:Support.Faq1
Since: Foswiki::Plugins::VERSION 2.0
$query
- the CGI query
$url
- the URL to redirect to
\%attrHash
- reference to hash of attachment attribute values
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
attachment
=> the attachment name
comment
- the comment
user
- the user id
tmpFilename
- name of a temporary file containing the attachment data
beforeUploadHandler()
instead.
\%attrHash
- reference to hash of attachment attribute values
$topic
- the name of the topic in the current CGI query
$web
- the name of the web in the current CGI query
$error
- any error string generated during the save process (always undef in 2.1)
attachment
=> the attachment name
comment
- the comment
user
- the user id
afterUploadHandler()
instead.
![]() |
© 2025 D.Soost & D.Marxsen - All rights reserved © Of all articles by authors Trademarks are the property of their respective owners © Logo by Wikipedia, modified by Administrator | Impressum Disclaimer Datenschutzerklärung |