[Pmwiki-users] Cookbook-Modules II

Patrick R. Michaud pmichaud
Thu Apr 22 16:24:03 CDT 2004


On Thu, Apr 22, 2004 at 05:15:06PM +0200, Nils Knappmeier wrote:
>
> In Debian GNU/Linux, there is a trend that goes from monolithic config 
> files to config dirs. [...]

Indeed, I fully agree with this concept -- in fact, its original basis
comes from the SysV-style for initialization scripts.

> So what would you think about this: Instead of config.php, we have many 
> files config-xxx.php
> All files "local/config(-.+)?\.php" are read instead of just config.php 
> and used as the global configuration.

Heh, I hate to say it, but this is already possible within local.php--see 
below.  However, instead of loading all files that begin with "config-", 
how about creating a local/config.d/ directory and any .php scripts 
stored in local/config.d/ become automatically loaded?  

However, there are some potential problems.  Greg Morgan correctly 
points out in a later message in this thread that there is a problem of
deciding the order in which such scripts should be loaded, and resolving
dependency conflicts between them.  But there's also the problem that
some admins may not want a cookbook module to *always* be enabled--they
may want it to only be active within specific groups or pages via a
per-group customization.  In this case having a module automatically
load its configuration script can be difficult to work around.

As far as resolving dependencies between scripts, there are a few options.
First, any script that depends on having some other script X already
loaded should do the equivalent of include_once("X").  This resolves
a lot of dependency problems.  Another standard mechanism in many contexts 
is to simply load scripts in alphabetic order (this is essentially what 
SysV-init does).  Script authors can then establish a convention whereby 
autoconfig scripts are named starting with a two-digit number, indicating 
its preferred relative placement in the configuration (e.g., 
"10-calendar.php", "25-rss.php", etc.).  But this still becomes a bit 
difficult to coordinate among multiple authors.

At any rate, here's my suggested config.php script to automatically 
load scripts stored in local/config.d/ (scripts are processed in 
alphabetic sequence):

  $dfp = @opendir('local/config.d');
  if ($dfp) {
    $c = array();
    while (($f = readdir($dfp))!==false) 
      if (preg_match('/\\.php$/',$f)) $c[] = $f;
    closedir($dfp);
    sort($c);
    foreach($c as $f) include_once("local/config.d/$f");
  }

I can probably be convinced to add code equivalent to this to
the distributed scripts/stdconfig.php.  However, a question--if 
this is done, should autoloaded scripts be processed before or after 
per-group/per-page customizations?

Finally, note that I'm still planning to design and implement a 
slightly different WikiCalendar module that should be a bit simpler
to install and configure for PmWiki installations.  I've also got
a "journaling" feature on its way whereby people can easily add/append 
comments into wiki pages.

Pm



More information about the pmwiki-users mailing list