01250: Late farmconfig

Summary: Late farmconfig
Created: 2011-04-06 02:38
Status: Open
Category: CoreCandidate
Assigned:
Priority: 33
Version: n/a
OS: n/a

Description: Currently farmconfig.php gets loaded prior to config.php. This works in probably 95% (?) of cases, but sometimes you need something loaded for an entire farm but it needs to be loaded *after* the configuration in config.php.

For instance, currently the recipe UserAdmin needs to be loaded *after* $WikiTitle is set. If an administrator is using UserAdmin probably he/she will use it for all wikis in his/her farm, but probably the $WikiTitle will not be set until config.php. Thus the administrator is left with either doing a bunch of if-testing in farmconfig.php to set $WikiTitle early or he is left with having to do a separate UserAdmin include in each config.php to get a late include there.

(Of course the argument can be made that the recipe maintainer [me] should fix this dependency and I probably will. I'm just using it for example.)

However, if we just made this change to pmwiki.php, adding the final 2 lines of the snippet below:

===(snip)=== if (file_exists("$FarmD/local/farmconfig.php"))

  include_once("$FarmD/local/farmconfig.php");

if (IsEnabled($EnableLocalConfig,1)) {

  if (file_exists("$LocalDir/config.php")) 
    include_once("$LocalDir/config.php");
  elseif (file_exists('config.php'))
    include_once('config.php');

} if (file_exists("$FarmD/local/latefarmconfig.php"))

  include_once("$FarmD/local/latefarmconfig.php");

===(snip)===

then there would be great flexibility. (Perhaps farmconfig2.php or farmconfiglate.php might be a better name? I don't have a firm opinion on the filename.)

(A similar argument could be made for $LocalDir/earlyconfig.php, but that can be easily solved by editing farmconfig.php and putting an include from the $LocalDir there.)

This same task can be accomplished by an administrator by adding these lines at the end of each config.php:

===(snip)=== if (file_exists("$FarmD/local/latefarmconfig.php"))

  include_once("$FarmD/local/latefarmconfig.php");

===(snip)===

but that seems less than ideal since it would be so easy to have inconsistencies. An administrator could add a new wiki to his farm and very easily forget to add those lines to config.php, losing out on some key piece of functionality...

How about using $PostConfig ? --Petko April 06, 2011, at 05:17 AM

$PostConfig['MyFunc'] = 100;
function MyFunc($pagename) {
  global $WikiTitle;
  # whatever
}

That works great for functions that need to be run, but include_once() inside a function is going to have all kinds of variable scope issues. A recipe would have to be totally redesigned in order to be include-able from within a function... —Peter Bowers April 07, 2011, at 09:20 AM

I meant in config.php you include_once your scripts, but inside your scripts, you have a function like in my example. This function will be run after config.php and stdconfig.php, but before HandleActions. You can use XLSDV() from inside this function, it will set the variables like it does now. --Petko April 07, 2011, at 09:50 AM