summaryrefslogtreecommitdiff
path: root/inc/confutils.php
diff options
context:
space:
mode:
authorChris Smith <chris.eureka@jalakai.co.uk>2009-01-18 19:12:04 +0100
committerChris Smith <chris.eureka@jalakai.co.uk>2009-01-18 19:12:04 +0100
commitcb043f52e80e5b287f70b0f93e8dc81744fd9d50 (patch)
tree585bb4f0c57cd9ef21b26ec33811de7cbd4b64fb /inc/confutils.php
parent1cf7edcb7fe86b27057d5c66685b6437a0508b03 (diff)
downloadrpg-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/confutils.php')
-rw-r--r--inc/confutils.php66
1 files changed, 31 insertions, 35 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>