[dokuwiki] cascading config pathes

Hello Dokuwiki,

After changing some things in my dokuwiki installation I wanted to check
if they might be usable for the main branch. Any comments greatly
appreciated.

I'm running a farm for multiple domains. Domain specific direcotries
contain the config, template, lang and data -files for animals. Default
settings are inherited and can be overwritten per setting. Files are
inherited if they dont exist.

This is usefull for animal specific changes to language or template
files. But also allows to keep more config files out of the source code
and template file in non-web directories
I also want to change the admin and config plugin to display only
settings contained in the animal-specific config directories.

Here are some changes I made for the template_dir in php, edited for
readability in mail. I wonder if a page to discuss this already exists.
Like farm2 or discuss in devel:preload. I might write some doku on my
own page also.

I m using the cascade_config global var to keep an array of directories
to search for files.

inc/preload.php

$config_cascade[template_dir] = array(
    default => array( $farmer_dir.lib/tpl/ ),
    local => array( $animal_dir.tpl/ ),
    );

$config_cascade[lang_dir] = array(
    default => array( $farmer_config./lang/, $farmer_dir ),
    local => array( DOKU_CONF.lang/,  ),
    protected => array( ),
    );


This is the function to retrieve the path for files that are included
only once. ie template files, lang files etc.
For config.php and lang.php files different logic is used.

/**
 * type     the configuration settings to be read,
 *          must correspond to a key/array in $config_cascade
 * file     the name of the wanted file
 * @return  the full path to the first occurence of the file,
 *          searching in this order: protected, local, default
 */

function getConfigPath($type, $file) {
  global $config_cascade;

  if (!is_array( $config_cascade[$type] ))
      trigger_error( Missing config for ".$type.",E_USER_WARNING );

  foreach (array(protected, local,default ) as $config_group ) {
    if ( empty( $config_cascade[$type][$config_group] )) continue;
    foreach( $config_cascade[$type][$config_group] as $path ) {
        if( file_exists( $path.$file )) {
            return $path.$file;
        }
    }

  }
}


lib/exe/css.php is changed in some places to be able to choose path on a
per file basis with this function:

/**
 * t    template, fallback to custom conf vars
 * file style.ini or a css file
 */

function css_getpath( $t, $file ) {
    global $conf;
    if( $return = getConfigPath( template_dir, $t./.$file ))
      return $return;
    if( $return = getConfigPath( template_dir,
                           $conf[default_tpl]./.$file )) return $return;

#echo "fallback ".DOKU_INC."lib/tpl/".$conf[base_tpl]."/".$file;
    return DOKU_INC.lib/tpl/.$conf[base_tpl]./.$file;
}






As suggested in irc including of php file has to be treated specially.
So for overwriting templates I use the following function. It allows
inclusion of given files according to template_dir from cascade.
base_tpl, as in css.php, is actually a copy of the
config-template-setting as that might get overwritten by plugins or
elsewhere.

function tpl_include( $file, $t=false, $allowphp=true ) {
    global $conf, $ID, $INFO;

    if( !$t ) { $t = $conf[template]; }
    if( !$t || !$include = getConfigPath( template_dir, $t./.$file )) {

      if( $t != $conf[default_tpl] )
          $include = getConfigPath( template_dir,
                                     $conf[default_tpl]./.$file );
    }

    if( !$include )
        $include = DOKU_INC.lib/tpl/.$conf[base_tpl]./.$file;

    if( $allowphp || $conf[tpl_allowphp] ) {
        include( $include );
    } else {
        // TODO, read file
    }
    return $include;

}



Finally I added a parameter to lib/exe/fetch.php to serve the template
images. htaccess can be used to redirect and set the parameter.

  if(auth_quickaclcheck(getNS($MEDIA).':X') < AUTH_READ){
      //media to local file
      // ...
  } elseif( $MODE == styleimg ) {


      if( !$FILE = getConfigPath( template_dir, $TPL./images/.$MEDIA ))


          $FILE = getConfigPath( template_dir,
                                 $conf[base_tpl]./images/.$MEDIA );

  }else{
    // ...
    $FILE  = mediaFN($MEDIA);




I love the options this setup gives me. And I can grant write access to
template and lang files to animal admins via sftp. Animals are
interchangeable between different branches and servers which run the
same setup.

I m using postgres for storing the users. The code is maintained in
darcs with newest patches applied though the diff might be quite long
these days with lang_dir and the mentioned functions. Some of them might
be appropriate for a plugin while I would love to have the basic cascade
functionality in the dokuwiki.org branch. Probably with a php inclusion
switch for farm maintainers.

For suggestions and questions I'm also present in the dokuwiki irc
channel.  -- alice|wl


-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: