diff options
author | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 19:12:04 +0100 |
---|---|---|
committer | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 19:12:04 +0100 |
commit | cb043f52e80e5b287f70b0f93e8dc81744fd9d50 (patch) | |
tree | 585bb4f0c57cd9ef21b26ec33811de7cbd4b64fb /inc | |
parent | 1cf7edcb7fe86b27057d5c66685b6437a0508b03 (diff) | |
download | rpg-cb043f52e80e5b287f70b0f93e8dc81744fd9d50.tar.gz rpg-cb043f52e80e5b287f70b0f93e8dc81744fd9d50.tar.bz2 |
Rework configuration loading to use a predefined file list or cascade
This change add the global $config_cascade which holds the list of files to be
read for each configuration setting group. Dokuwiki adds in its configuration
file values after preload.php, giving preload.php to set its own configuration
cascade.
One side effect of the change is "local.protected.php" is part of the default
cascade, removing the need for it to be included at the bottom of local.php.
darcs-hash:20090118181204-f07c6-fea1c406da1bbdb0a52ab40914f11b835e797728.gz
Diffstat (limited to 'inc')
-rw-r--r-- | inc/confutils.php | 66 | ||||
-rw-r--r-- | inc/init.php | 49 |
2 files changed, 76 insertions, 39 deletions
diff --git a/inc/confutils.php b/inc/confutils.php index aeb5f6c60..77f058e0e 100644 --- a/inc/confutils.php +++ b/inc/confutils.php @@ -39,11 +39,7 @@ function mimetype($file){ function getMimeTypes() { static $mime = NULL; if ( !$mime ) { - $mime = confToHash(DOKU_CONF.'mime.conf'); - if (@file_exists(DOKU_CONF.'mime.local.conf')) { - $local = confToHash(DOKU_CONF.'mime.local.conf'); - $mime = array_merge($mime, $local); - } + $mime = retrieveConfig('mime','confToHash'); } return $mime; } @@ -56,11 +52,7 @@ function getMimeTypes() { function getAcronyms() { static $acronyms = NULL; if ( !$acronyms ) { - $acronyms = confToHash(DOKU_CONF.'acronyms.conf'); - if (@file_exists(DOKU_CONF.'acronyms.local.conf')) { - $local = confToHash(DOKU_CONF.'acronyms.local.conf'); - $acronyms = array_merge($acronyms, $local); - } + $acronyms = retrieveConfig('acronyms','confToHash'); } return $acronyms; } @@ -73,11 +65,7 @@ function getAcronyms() { function getSmileys() { static $smileys = NULL; if ( !$smileys ) { - $smileys = confToHash(DOKU_CONF.'smileys.conf'); - if (@file_exists(DOKU_CONF.'smileys.local.conf')) { - $local = confToHash(DOKU_CONF.'smileys.local.conf'); - $smileys = array_merge($smileys, $local); - } + $smileys = retrieveConfig('smileys','confToHash'); } return $smileys; } @@ -90,11 +78,7 @@ function getSmileys() { function getEntities() { static $entities = NULL; if ( !$entities ) { - $entities = confToHash(DOKU_CONF.'entities.conf'); - if (@file_exists(DOKU_CONF.'entities.local.conf')) { - $local = confToHash(DOKU_CONF.'entities.local.conf'); - $entities = array_merge($entities, $local); - } + $entities = retrieveConfig('entities','confToHash'); } return $entities; } @@ -107,11 +91,7 @@ function getEntities() { function getInterwiki() { static $wikis = NULL; if ( !$wikis ) { - $wikis = confToHash(DOKU_CONF.'interwiki.conf',true); - if (@file_exists(DOKU_CONF.'interwiki.local.conf')) { - $local = confToHash(DOKU_CONF.'interwiki.local.conf'); - $wikis = array_merge($wikis, $local); - } + $wikis = retrieveConfig('interwiki','confToHash'); } //add sepecial case 'this' $wikis['this'] = DOKU_URL.'{NAME}'; @@ -125,11 +105,7 @@ function getInterwiki() { function getWordblocks() { static $wordblocks = NULL; if ( !$wordblocks ) { - $wordblocks = file(DOKU_CONF.'wordblock.conf'); - if (@file_exists(DOKU_CONF.'wordblock.local.conf')) { - $local = file(DOKU_CONF.'wordblock.local.conf'); - $wordblocks = array_merge($wordblocks, $local); - } + $wordblocks = retrieveConfig('wordblock','file'); } return $wordblocks; } @@ -138,11 +114,7 @@ function getWordblocks() { function getSchemes() { static $schemes = NULL; if ( !$schemes ) { - $schemes = file(DOKU_CONF.'scheme.conf'); - if (@file_exists(DOKU_CONF.'scheme.local.conf')) { - $local = file(DOKU_CONF.'scheme.local.conf'); - $schemes = array_merge($schemes, $local); - } + $schemes = retrieveConfig('scheme','file'); } $schemes = array_map('trim', $schemes); $schemes = preg_replace('/^#.*/', '', $schemes); @@ -183,6 +155,30 @@ function confToHash($file,$lower=false) { } /** + * Retrieve the requested configuration information + * + * @author Chris Smith <chris@jalakai.co.uk> + * + * @param string $type the configuration settings to be read, must correspond to a key/array in $config_cascade + * @param callback $fn the function used to process the configuration file into an array + * @return array configuration values + */ +function retrieveConfig($type,$fn) { + global $config_cascade; + + $combined = array(); + if (!is_array($config_cascade[$type])) trigger_error('Missing config cascade for "'.$type.'"',E_USER_WARNING); + foreach ($config_cascade[$type] as $file) { + if (@file_exists($file)) { + $config = $fn($file); + $combined = array_merge($combined, $config); + } + } + + return $combined; +} + +/** * check if the given action was disabled in config * * @author Andreas Gohr <andi@splitbrain.org> diff --git a/inc/init.php b/inc/init.php index 9c4baa988..9ef905d52 100644 --- a/inc/init.php +++ b/inc/init.php @@ -40,14 +40,55 @@ global $cache_authname; $cache_authname = array(); global $cache_metadata; $cache_metadata = array(); + //set the configuration cascade - but only if its not already been set in preload.php + global $config_cascade; + if (empty($config_cascade)) { + $config_cascade = array( + 'main' => array( + 'default' => array(DOKU_CONF.'dokuwiki.php'), + 'local' => array(DOKU_CONF.'local.php'), + 'protected' => array(DOKU_CONF.'local.protected.php'), + ), + 'acronyms' => array( + 'default' => array(DOKU_CONF.'acronyms.php'), + 'local' => array(DOKU_CONF.'acronyms.local.php'), + ), + 'entities' => array( + 'default' => array(DOKU_CONF.'entities.php'), + 'local' => array(DOKU_CONF.'entities.local.php'), + ), + 'interwiki' => array( + 'default' => array(DOKU_CONF.'interwiki.php'), + 'local' => array(DOKU_CONF.'interwiki.local.php'), + ), + 'mime' => array( + 'default' => array(DOKU_CONF.'mime.php'), + 'local' => array(DOKU_CONF.'mime.local.php'), + ), + 'scheme' => array( + 'default' => array(DOKU_CONF.'scheme.php'), + 'local' => array(DOKU_CONF.'scheme.local.php'), + ), + 'smileys' => array( + 'default' => array(DOKU_CONF.'smileys.php'), + 'local' => array(DOKU_CONF.'smileys.local.php'), + ), + 'wordblock' => array( + 'default' => array(DOKU_CONF.'wordblock.php'), + 'local' => array(DOKU_CONF.'wordblock.local.php'), + ), + ); + } + //prepare config array() global $conf; $conf = array(); - // load the config file(s) - require_once(DOKU_CONF.'dokuwiki.php'); - if(@file_exists(DOKU_CONF.'local.php')){ - require_once(DOKU_CONF.'local.php'); + // load the global config file(s) + foreach ($config_cascade['main'] as $config_group) { + foreach ($config_group as $config_file) { + @include($config_file); + } } //prepare language array |