replace preset _cautionList property with _caution config metadata parameter, plugins can now easily set cautions on their settings

This commit is contained in:
Christopher Smith 2013-02-18 17:51:45 +00:00
parent d433710d80
commit 9dc3b8ab75
2 changed files with 43 additions and 29 deletions

View File

@ -366,12 +366,11 @@ if (!class_exists('setting')) {
var $_pattern = '';
var $_error = false; // only used by those classes which error check
var $_input = null; // only used by those classes which error check
var $_caution = null; // used by any setting to provide an alert along with the setting
// valid alerts, 'warning', 'danger', 'security'
// images matching the alerts are in the plugin's images directory
var $_cautionList = array(
'basedir' => 'danger', 'baseurl' => 'danger', 'savedir' => 'danger', 'cookiedir' => 'danger', 'useacl' => 'danger', 'authtype' => 'danger', 'superuser' => 'danger', 'userewrite' => 'danger',
'start' => 'warning', 'camelcase' => 'warning', 'deaccent' => 'warning', 'sepchar' => 'warning', 'compression' => 'warning', 'xsendfile' => 'warning', 'renderer_xhtml' => 'warning', 'fnencode' => 'warning',
'allowdebug' => 'security', 'htmlok' => 'security', 'phpok' => 'security', 'iexssprotect' => 'security', 'remote' => 'security', 'fullpath' => 'security'
);
static protected $_validCautions = array('warning','danger','security');
function setting($key, $params=null) {
$this->_key = $key;
@ -473,8 +472,22 @@ if (!class_exists('setting')) {
function error() { return $this->_error; }
function caution() {
if (!array_key_exists($this->_key, $this->_cautionList)) return false;
return $this->_cautionList[$this->_key];
if (!empty($this->_caution)) {
if (!in_array($this->_caution, setting::$_validCautions)) {
trigger_error('Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', E_USER_WARNING);
return false;
}
return $this->_caution;
}
// compatibility with previous cautionList
// TODO: check if any plugins use; remove
if (!empty($this->_cautionList[$this->_key])) {
$this->_caution = $this->_cautionList[$this->_key];
unset($this->_cautionList);
return $this->caution();
}
return false;
}
function _out_key($pretty=false,$url=false) {

View File

@ -51,6 +51,7 @@
* Any setting commented or missing will use 'setting' class - text input, minimal validation, quoted output
*
* Defined parameters:
* '_caution' - no value (default) or 'warning', 'danger', 'security'. display an alert along with the setting
* '_pattern' - string, a preg pattern. input is tested against this pattern before being accepted
* optional all classes, except onoff & multichoice which ignore it
* '_choices' - array of choices. used to populate a selection box. choice will be replaced by a localised
@ -89,26 +90,26 @@ $config['heading'] = 'Dokuwiki\'s Main Configuration File - Local Settings';
$meta['_basic'] = array('fieldset');
$meta['title'] = array('string');
$meta['start'] = array('string','_pattern' => '!^[^:;/]+$!'); // don't accept namespaces
$meta['start'] = array('string','_caution' => 'warning','_pattern' => '!^[^:;/]+$!'); // don't accept namespaces
$meta['lang'] = array('dirchoice','_dir' => DOKU_INC.'inc/lang/');
$meta['template'] = array('dirchoice','_dir' => DOKU_INC.'lib/tpl/','_pattern' => '/^[\w-]+$/');
$meta['tagline'] = array('string');
$meta['sidebar'] = array('string');
$meta['license'] = array('license');
$meta['savedir'] = array('savedir');
$meta['basedir'] = array('string');
$meta['baseurl'] = array('string');
$meta['cookiedir'] = array('string');
$meta['savedir'] = array('savedir','_caution' => 'danger');
$meta['basedir'] = array('string','_caution' => 'danger');
$meta['baseurl'] = array('string','_caution' => 'danger');
$meta['cookiedir'] = array('string','_caution' => 'danger');
$meta['dmode'] = array('numeric','_pattern' => '/0[0-7]{3,4}/'); // only accept octal representation
$meta['fmode'] = array('numeric','_pattern' => '/0[0-7]{3,4}/'); // only accept octal representation
$meta['allowdebug'] = array('onoff');
$meta['allowdebug'] = array('onoff','_caution' => 'security');
$meta['_display'] = array('fieldset');
$meta['recent'] = array('numeric');
$meta['recent_days'] = array('numeric');
$meta['breadcrumbs'] = array('numeric','_min' => 0);
$meta['youarehere'] = array('onoff');
$meta['fullpath'] = array('onoff');
$meta['fullpath'] = array('onoff','_caution' => 'security');
$meta['typography'] = array('multichoice','_choices' => array(0,1,2));
$meta['dformat'] = array('string');
$meta['signature'] = array('string');
@ -117,19 +118,19 @@ $meta['toptoclevel'] = array('multichoice','_choices' => array(1,2,3,4,5)); //
$meta['tocminheads'] = array('multichoice','_choices' => array(0,1,2,3,4,5,10,15,20));
$meta['maxtoclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5));
$meta['maxseclevel'] = array('multichoice','_choices' => array(0,1,2,3,4,5)); // 0 for no sec edit buttons
$meta['camelcase'] = array('onoff');
$meta['deaccent'] = array('multichoice','_choices' => array(0,1,2));
$meta['camelcase'] = array('onoff','_caution' => 'warning');
$meta['deaccent'] = array('multichoice','_choices' => array(0,1,2),'_caution' => 'warning');
$meta['useheading'] = array('multichoice','_choices' => array(0,'navigation','content',1));
$meta['sneaky_index'] = array('onoff');
$meta['hidepages'] = array('regex');
$meta['_authentication'] = array('fieldset');
$meta['useacl'] = array('onoff');
$meta['useacl'] = array('onoff','_caution' => 'danger');
$meta['autopasswd'] = array('onoff');
$meta['authtype'] = array('authtype');
$meta['authtype'] = array('authtype','_caution' => 'danger');
$meta['passcrypt'] = array('multichoice','_choices' => array('smd5','md5','apr1','sha1','ssha','lsmd5','crypt','mysql','my411','kmd5','pmd5','hmd5','mediawiki','bcrypt','djangomd5','djangosha1','sha512'));
$meta['defaultgroup']= array('string');
$meta['superuser'] = array('string');
$meta['superuser'] = array('string','_caution' => 'danger');
$meta['manager'] = array('string');
$meta['profileconfirm'] = array('onoff');
$meta['rememberme'] = array('onoff');
@ -138,7 +139,7 @@ $meta['disableactions'] = array('disableactions',
'_combine' => array('subscription' => array('subscribe','unsubscribe'), 'wikicode' => array('source','export_raw')));
$meta['auth_security_timeout'] = array('numeric');
$meta['securecookie'] = array('onoff');
$meta['remote'] = array('onoff');
$meta['remote'] = array('onoff','_caution' => 'security');
$meta['remoteuser'] = array('string');
$meta['_anti_spam'] = array('fieldset');
@ -146,12 +147,12 @@ $meta['usewordblock']= array('onoff');
$meta['relnofollow'] = array('onoff');
$meta['indexdelay'] = array('numeric');
$meta['mailguard'] = array('multichoice','_choices' => array('visible','hex','none'));
$meta['iexssprotect']= array('onoff');
$meta['iexssprotect']= array('onoff','_caution' => 'security');
$meta['_editing'] = array('fieldset');
$meta['usedraft'] = array('onoff');
$meta['htmlok'] = array('onoff');
$meta['phpok'] = array('onoff');
$meta['htmlok'] = array('onoff','_caution' => 'security');
$meta['phpok'] = array('onoff','_caution' => 'security');
$meta['locktime'] = array('numeric');
$meta['cachetime'] = array('numeric');
@ -191,20 +192,20 @@ $meta['rss_show_summary'] = array('onoff');
$meta['_advanced'] = array('fieldset');
$meta['updatecheck'] = array('onoff');
$meta['userewrite'] = array('multichoice','_choices' => array(0,1,2));
$meta['userewrite'] = array('multichoice','_choices' => array(0,1,2),'_caution' => 'danger');
$meta['useslash'] = array('onoff');
$meta['sepchar'] = array('sepchar');
$meta['sepchar'] = array('sepchar','_caution' => 'warning');
$meta['canonical'] = array('onoff');
$meta['fnencode'] = array('multichoice','_choices' => array('url','safe','utf-8'));
$meta['fnencode'] = array('multichoice','_choices' => array('url','safe','utf-8'),'_caution' => 'warning');
$meta['autoplural'] = array('onoff');
$meta['compress'] = array('onoff');
$meta['cssdatauri'] = array('numeric','_pattern' => '/^\d+$/');
$meta['gzip_output'] = array('onoff');
$meta['send404'] = array('onoff');
$meta['compression'] = array('compression');
$meta['compression'] = array('compression','_caution' => 'warning');
$meta['broken_iua'] = array('onoff');
$meta['xsendfile'] = array('multichoice','_choices' => array(0,1,2,3));
$meta['renderer_xhtml'] = array('renderer','_format' => 'xhtml','_choices' => array('xhtml'));
$meta['xsendfile'] = array('multichoice','_choices' => array(0,1,2,3),'_caution' => 'warning');
$meta['renderer_xhtml'] = array('renderer','_format' => 'xhtml','_choices' => array('xhtml'),'_caution' => 'warning');
$meta['readdircache'] = array('numeric');
$meta['_network'] = array('fieldset');