.spec
File lib/LocalSite.cfg
. This file is simply
a series of key-value settings. In the beginning the only way to create
this file was to manually edit a template, and this approach is still
possible today. However things have moved on a bit since then, with the
development of the configure
script, that provides a web interface to
the configuration.
As the configuration of Foswiki became more complex we needed an abstract
model of the configuration data, so we could use it to drive user interfaces, and
generalise the checking process for different kinds of configuration item. Thus
the .spec
file was born. Foswiki uses a
master .spec
file called lib/Foswiki.spec
, and each extension may have an optional
Config.spec
. The format of these files is identical.
DevelopingPlugins gives a high-level view of the syntax of .spec
files, and
most developers will not need to explore beyond the capabilities described there. This guide
goes much more deeply into the nature and syntax of .spec
files, and is mainly for
the use of core developers.
.spec
files is that they are executable perl files that specify default
values for configuration keys. For example,
$Foswiki::cfg{DataDir} = '/my/data/directory';By using Perl syntax we leverage the ultra-fast Perl parser to best effect, and remain copy-paste compatibility with
LocalSite.cfg
.
Structured comments are used in the .spec files to provide additional information about individual keys, and
to subdivide the configuration into sections that are manageable in a UI. Additional structured comments provide information about the keys, such as type.
There are two places where .spec files are used. Firstly, the master lib/Foswiki.spec
is the schema for the core Foswiki configuration. It contains specifications for
all the controls that affect core modules. Secondly, extensions can have their own .spec files, called Config.spec
, which insert additional configuration items
specific to the extension.
Config.spec
elements $Foswiki::cfg
hash:
Location | Example | Notes |
---|---|---|
Under the {Extensions} namespace |
$Foswiki::cfg{Extensions}{BathPlugin}{PlugType} |
This is the recommended location, It is recommended for all new extensions, and strongly recommended for non-Plugin type extensions (Contribs, Skins, etc). |
Under the {Plugins} namespace |
$Foswiki::cfg{Plugins}{BathPlugin}{PlugType} |
This is traditionally where foswiki organizes all plugin settings. Foswiki automatically populates two settings for Plugins (and only plugins):
Config.spec file.We no longer recommend using this namespace for custom settings. |
Under the root namespace | $Foswiki::cfg{BathPlugin} |
Not Recommended Historical extensions place settings under the root, it results in a very cluttered configuration. |
{Extensions}
, even if it has a Plugin component.
{Plugins}
space but this is no longer recommended.
---+ Extensions ---++ BathPlugin $Foswiki::cfg{Plugins}{BathPlugin}{PlugType} = 'rubber'; $Foswiki::cfg{Extensions}{BathPlugin}{ToyType} = 'duckie'; $Foswiki::cfg{foobar} = 'some archaic root-level setting';
.spec
file is an executable Perl file. It consists of: 1;
to ensure that the file evaluates to "True" when executed.
.spec
file is structured into sections using TML syntax comments, such as
# ---+ Section Title # This is a comment describing the section. The first paragraph is special, and will always be shown in interfaces (other paragraphs may be expanded using controls in the interface). # The comment is formatted using a subset of the TML (Topic Markup Language) used in Foswiki topics. You can also embed raw HTML.These comments are used to create SECTION objects in the model when it is loaded, and thus drive the construction of a UI, but otherwise have no impact.
.spec
is in the specification of the keys.
The key specification is placed in comment before the configuration key, and consists of a type declaration followed by a comment. At it's simplest, this is just a type name in stars, followed by a comment:
# **NUMBER** # This describes the setting. The first paragraph is special, and will always be shown in interfaces (other paragraphs may be expanded using controls in the interface). # The description is formatted using a subset of the TML (Topic Markup Language) used in Foswiki topics. You can also embed raw HTML.The actual key looks like this:
$Foswiki::cfg{Extensions}{ConfigurePlugin}{ExampleKey} = 42;You can also specify a key that has no default (will be undefined) by placing the key in a # comment
# $Foswiki::cfg{Extensions}{ConfigurePlugin}{ExampleKey} = 42;DevelopingPlugins has more information on the types available and the basic options that can be used with them. The simple
NUMBER
type specification shown above can be extended by a number of attributes.
Most of these are described in DevelopingPlugins, but there are a few more not described there that are used in Foswiki.spec
, and are worth saying a bit more about.
FEEDBACK
- allows you to specify additional feedback requirements for the key. You can have as many FEEDBACK attributes as you want, each specifying the attributes for an action to be associated with the key (usually a button). A FEEDBACK is simply a semicolon-separated list of key-value pairs. These pairs specify the attributes for a button: label
the text to be used for the button
method
the checker / wizard method to be invoked by the button
wizard
(optional) if not given, the method
is called from the checker package for the item. If a wizard is given, then the wizard package is looked up in lib/Foswiki/Configure/Wizards
and the method run from there.
title
- an optional help string for the button.
CHECK
- is used to specify additional parameters to the checker for the key. This allows parameterisation of a generic checker without the need for a specific checker package for the key. A CHECK
attribute specifies a space-separated list of key-value pairs which have meaning to the generic checker. Each pair consists of an attribute name and an optional value. The value is a comma-separated list of keywords, numbers or strings. PATH
- supports a comma separated list of permissions and filters in the form of perms:<permstring>,<'filter regex'>,<permstring>,<'filter'>...
permstring
- validate file permissions using entered code. Code is a combination of {Store}{filePermission}
,
{Store}{dirPermission}
,
rwdp
filter
- regexp that filters files for which this check doesn't apply. Entered as a quoted string. Enter '*' as a place holder to match all files.
URLPATH
expand
expand $Foswiki::cfg
variables in value
nullok
allow item to be empty
notrail
disallow trailing /
user
Permit user@host
syntax
pass
Permit user:pass@host
syntax
URL
- as URLPATH
with the addition of: schemes
schemes allowed. Default: schemes:http,https
authtype
authority types allowed in item (from host, ip, hostip). Default: authtype:host
parts
- list of parts allowed in item (from scheme, authority, path, query, fragment). Default: parts:scheme,authority,path
partsreq
- list of parts required in item
NUMBER
radix
radix (2-36), specified in decimal. Default: radix:10
min
minimum in specified radix
max
maximum in specified radix
OCTAL
min
minimum in base 8
max
maximum in base 8
STRING
min
minimum length, Default min:0
max
maximum length
accept
list of regexp, one of which must match
filter
list of regexp, none of which may match
EMAILADDRESS
list
if present, permit a list of comma-separated addresses
DATE
zone
- default timezone (from utc, local)
raw
- assume raw user input (don't normalize to ISO format
noemptyok
)
noundefok
)
CHECKER
- normally a configuration item is checked by a checker found by looking up the keys for the value and loading a package. This allows you to redirect to a different checker. It is useful when two or more keys are inter-dependent and share identical checking requirements.
CHECK_ON_CHANGE
- specifies a list of keys to check when the value of this key is changed (dependencies). See CHECK_ON_CHANGE below.
SPELLCHECK
- if given, and the browser supports it, then allow spell-checking on the value of the item.
CHECK_ON_CHANGE
option, which allows you to specify a (comma-separated) list of other keys. This specifies that if the value of any of these other keys changes, then this key needs to be checked as well. For example,
**STRING CHECK_ON_CHANGE="{Y}"** $Foswiki::Cfg{X} = 1;tells the code that when the value of
{Y}
changes, then {X}
needs to be checked as well.
You can also specify the reverse relation using the CHECK
option. The also
switch specifies a list of other keys that will need to be checked if the value of this key changes. For example,
**STRING CHECK="also:{X}"** $Foswiki::Cfg{Y} = 1;is the equivalent of the
CHECK_ON_CHANGE
example above.
Foswiki.spec
file.
# **SELECTCLASS Foswiki::Store::* ** # Store implementation. $Foswiki::cfg{Store}{Implementation} = 'Foswiki::Store::PlainFile';However this definition can then be expanded from the definition in a Config.spec file, For example in the
PlainFileStoreContrib/Config.spec
file, the documentation is "Enhanced". The documentation in the Config.spec file is merged with the definition in Foswiki.spec.
# **ENHANCE {Store}{Implementation}** # * PlainFile - # (installed by the PlainFileStoreContrib) is just about the simplest store ... # is the reference implementation of a store.
lib/Foswiki/Configure/Pluggables
that are used to automatically construct blocks of keys by querying the environment. For example, the LANGUAGES
pluggable is responsible for determining what languages are available on the system, and creating keys
that correspond to each language. Pluggables are invoked in the .spec
by quoting the name of the pluggable in single stars:
# *LANGUAGES*
lib/Foswiki/Configure/Checkers
directory, in a directory structure that matches the position of the key in the configuration data. Take a look at that directory, and it should be fairly obvious.
As well as the checker modules for specific keys, there are also a number of generic type checkers. For example, lib/Foswiki/Configure/Checkers/STRING.pm
is a generic checker
for STRING-type configuration items. These generic checkers can be parameterised using information from the .spec
file, using the CHECK
option. For example,
# **URL CHECK="parts:scheme,authority \ # partsreq:scheme,authority \ # schemes:http,https \ # authtype:host" **This is the type specification for a configuration key that will contain a URL. The
CHECK
clause specifies what the URL must contain in order to pass the check. Individual generic type
checkers support different CHECK options, as described above.
Checkers normally declare a single function, check_current_value
, that checks the current value of the item. Checkers never : %Foswiki::cfg
, nothing)
print
to STDOUT or STDERR, and don't assume CGI is available)
%Foswiki::cfg
is there, but no other part of the Foswiki code can be assumed.
FEEDBACK
mechanism described next.
FEEDBACK
attribute. For example,
# **EMAILADDRESS FEEDBACK="label='Send Test Email';wizard='SendTestEmail'; method='send'"**The FEEDBACK attribute is a semicolon-separated list of key-value pairs, where the value is a quoted string (" and ' both supported) or a number. The following keys are supported:
label
- specifies a label that identifies the wizard.
title
- a wordy description of what the wizard does.
wizard
- specifies a code module to load from lib/Foswiki/Configure/Wizards
that contains the wizard method. Default is to look for the method in the checker.
method
- (required) specifies the name of the method (function) to call
auth
- if auth=1
then authentication is required (the wizard expects to be passed username and password, though what it does with them is up to the wizard)
wizard
attribute is
not given, then it will look for a function called method
in the checker code package.
The full specification of wizards are documented in the lib/Foswiki/Configure/Wizard.pm
module. Wizards in lib/Foswiki/Configure/Wizards
can report back to the caller and include
information about what aspects of the configuration were changed (whcih keys have new values as a result of running the wizard).
.spec
format is designed to specify the schema of a configuration without making any assumptions about the user interface being used to modify the configuration. In fact there are
two interfaces available, a command-line interface ( tools/configure
) and a web-based interface implemented as a Foswiki extension (ConfigurePlugin).
Other interfaces may become available in the future.
tools/configure
tools/configure
is a perl script that provides a fully-featured command-line interface that lets you explore and modify the configuration, call wizards and install/remove extensions. It is
internally documented - run
$ perl tools/configure -helpfor full help information.
ConfigurePlugin
consists of a server-side plugin module and a JQuery user interface. The server-side plugin provides a number of jsonrpc
entry points that support the retrieval of configuration information, checking, the invoking of wizards, and the saving of updated configurations. As far as possible the server side code is kept clear of any user interface assumptions.
The client-side Javascript (JQuery) module is responsible for all the presentation of the configuration data. It uses the jsonrpc
API of the plugin to perform queries over the configuration data.
-- CrawfordCurrie, GeorgeClark
TopicClassification | DeveloperDocumentation |
TopicSummary | Description of .spec files |
InterestedParties |