lib/tpl/<template>/conf/default.php
这是本文档旧的修订版!
配置
兼容的版本 Dokuwiki
2017-07-20
The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
This extension is not in the 'plugin' or 'template' namespace and is therefore ignored.
默认设置
要使插件或模板可配置你必须提供一个包含默认设置的lib/plugins/<plugin>/conf/default.php
,还有一个包含配置管理器 所使用的描述配置元数据的lib/plugins/<plugin>/conf/metadata.php
,它可以将选项进行处理/显示。1).
$conf[<setting>] = <value>;
配置元数据
对于每一个在 lib/plugins/<your plugin>/conf/default.php
的设置它们都有一个 $meta[<setting>]
值定位于 lib/plugins/<your plugin>/conf/metadata.php
2):
$meta[<setting>] = array(<setting class>, <param name> => <param value>);
如果一个设置类不需要参数(参见下面),那么它就是简单的:
$meta[<setting>] = array(<setting class>);
例子:
$meta['_basic'] = array('fieldset'); $meta['title'] = array('string'); $meta['lang'] = array('dirchoice','_dir' => DOKU_INC.'inc/lang/'); $meta['dmode'] = array('numeric','_pattern' => '/0[0-7]{3,4}/'); // 只接受八进制表示法 $meta['allowdebug'] = array('onoff'); $meta['passcrypt'] = array('multichoice','_choices' => array('smd5','md5','sha1','ssha','crypt','mysql','my411'));
类
'' | 默认的类('setting'),文本框 ,最小输入验证,在引号中设置输出。 |
---|---|
'string' | 单行文本输入,最小输入验证,在引号中设置输出。 |
'numeric' | 文本输入,接受数字和算术运算符,设置没有引号的输出。 如果给定 _min 和_max 参数,则用于验证。 |
'numericopt' | 像上面一样,但是接受空值。 |
'onoff' | 复选框输入,设置输出“0”或“1”(注意,默认值应该是一个整数,而不是布尔)。 |
'multichoice' | 选择输入(单个选择),用引号设置输出,需要 _choices 参数。 |
'email' | 文本输入,输入必须符合电子邮件地址格式,在引号中设置输出。 |
'richemail' | 文本输入,输入必须符合电子邮件地址头格式,可能包括文本部分和替换模式,在引号中设置输出。 |
'password' | 密码输入,最小输入验证,在引号中设置输出纯文本。一旦设置了密码,就不再显示在配置管理器中了。可以通过 _code 参数对配置进行模糊处理。 |
'dirchoice' | 作为“多选”,根据 _dir 参数(必需)中指定的位置所找到的文件夹进行选择。 |
'multicheckbox' | 每个选项的复选框和一个 “other” 字符串输入,配置文件设置是一个逗号分隔的检查选项列表。 |
'fieldset' | 用于组配置设置,但它本身不是一个设置。为了在语言文件中清楚地说明,这种类型的键应该以_ 为开始 |
'authtype' | 创建了一组可用的身份验证方法,这些方法是根据inc/auth 的类名来匹配 authtype.class.php 模式。 |
'regex' | 正则表达式字符串,通常没有分隔符;至于 string ,还测试了是否将编译并作为正则表达式运行。除了 _pattern 外,还接受 _delimiter (默认/ ) 和_pregflags (默认ui )。 |
参数
'_pattern' | String, a regular expression. Input is tested against this pattern before being accepted. Optional all classes, except onoff , multichoice and dirchoice which ignore it. |
---|---|
'_choices' | Array of choices. Used to populate a selection box. Choice will be replaced by a localised language string, indexed by <setting name>_o_<choice> , if one exists.Required by multichoice & multicheckbox classes, ignored by others. |
'_dir' | Location of directory to be used to populate choice list. Required by dirchoice class, ignored by other classes. |
'_code' | Sets the obfuscation option for password fields. May be plain , base64 or uuencode . When using the latter two, you need to use conf_decodeString() to access the plain value. |
'_combine' | Complimentary output setting values which can be combined into a single display checkbox .Optional for multicheckbox , ignored by other classes. |
'_code' | Encoding method to use, accepted values: base64 , uuencode , plain . Defaults to plain. |
'_min' | Minimum numeric value. Optional for numeric and numericopt , ignored by others. |
'_max' | Maximum numeric value. Optional for numeric and numericopt , ignored by others. |
'_delimiter' | String, default / , a single character used as a delimiter for testing regex input values. |
'_pregflags' | String, default ui , valid preg pattern modifiers used when testing regex input values, for more information see http://uk1.php.net/manual/en/reference.pcre.pattern.modifiers.php. |
'_multiple' | Bool, allow multiple comma separated email values. Optional for email , ignored by others. |
'_other' | How to handle other values (not listed in _choices ). Accepted values: always , exists , never . Default value always .exists only shows 'other' input field when the setting contains value(s) not listed in choices (e.g. due to manual editing or update changing _choices ). This is safer than never as it will not discard unknown/other values.Optional for multicheckbox , ignored by others. |
例子
''multicheckbox'' 用 ''_other''
假设最初插件使用的语法:
$meta['multi'] = array('multicheckbox', '_choices' => array('a','b','c','d'));
这意味着多复选框将显示四个选项和一个字符串输入。
假设用户插入一个或多个额外的值,而不是在 _choices
.
在插件的下一个版本中,作者的插件决定在没有额外的字符串的情况下使用多复选框,但是为了向后兼容,采用:
$meta['multi'] = array('multicheckbox', '_other' => 'exists', '_choices' => array('a','b','c','d'));
这意味着:
- 如果用户插入逗号分隔值,则将在额外的字符串中打印;
- 否则不会显示额外的字符串。
还请注意,如果用户插入逗号分隔值已经存在(或一些)在 _choices
但:
- 它们已经被勾选,然后额外的字符串将被删除,其他的都没有;
- 它们还没有被勾选,然后额外的字符串将被删除,相对的值将被勾选。
访问设置
核心设置
在inc/init.php内部,配置设置被读取到一个全局数组 $conf[]
。当没有设置设置时,将从默认设置文件中读取这些设置。
你可以在任何地方访问核心设置通过使用 $conf[]
数组。
$startpage = $conf['start'];
插件设置
你可以访问设置在 插件 通过 $this->getConf('<setting>')
方法。
在你的插件类中,你使用:
$keyvalue = $this->getConf('key');
模板设置
标签在配置管理器
对于lib/plugins/<your plugin>/conf/default.php
中的每一个设置,都可以在lib/plugins/<your plugin>/lang/en/settings.php
中定义一个$lang[<setting>]
值。 这个值将作为配置管理器中的设置的标签显示。如果标签文件被省略,或者不包含设置的值,配置管理器将显示X“plugin <plugin name> <setting>
“作为标签。
您还可以创建一个 settings.php
文件为其他语言。
同样,这也适用于模板 (进一步的细节见定位)。