[pmwiki-users] Skin Change list

Patrick R. Michaud pmichaud at pobox.com
Fri Mar 3 18:26:24 CST 2006

On Fri, Mar 03, 2006 at 04:37:10PM -0700, H. Fox wrote:
> On 3/3/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
> > On Fri, Mar 03, 2006 at 08:40:23AM -0500, Susan wrote:
> > >
> > > http://www.pmwiki.org/wiki/Cookbook/SkinChange
> > >
> > > Gives a section of php code to put in /local/config.php that will build
> > > a list of skins automatically.
> >
> > Actually, I think that code may be a little bit of overkill -- one can
> > do a similar thing much more quickly with:
> >
> >     include_once('cookbook/skinchange.php');
> >     if (!$Skin && preg_match('/^[-\\w]+$/', $sk)
> >         && is_dir("$FarmD/pub/skins/$sk")) $Skin = $sk;
> What does this do?  How does it replace
> [...]
> ? Doesn't the list of skins, automatically generated or not, need to
> be defined *before* including skinchange.php?

In order for skinchange.php to set the skin, yes, $PageSkinList
needs to be set beforehand.  

However, I'm cheating a bit here -- I'm letting skinchange.php
do the "heavy lifting" of setting the cookie and $Skin variable
if it can do so from $PageSkinList, and if it isn't able to
do it then the if statement takes over.

So, think of skinchange.php as doing the following:
  - grabbing the correct value of "skin=" or "setskin="
  - setting a cookie if "setskin=" is specified
  - setting $Skin based on a lookup from $PageSkinList

Of course, if $PageSkinList is empty, then $Skin isn't set, but
the other two items still take place, and the skin the browser
requested is in the "$sk" variable.  So, this is where the
if statement takes over -- rather than scan the entire skins
directory to build $PageSkinList, we just look for the one skin
that the browser requested, and set $Skin to that one skin if
it exists.

There are a couple of advantages to this approach -- first and foremost,
we avoid the cost of reading the skins directory and building 
$PageSkinsList on every page request.  Second, the administrator 
can use $PageSkinList to "hide" certain skins that might be in the 
pub/skins directory -- for example, to force ?setskin=pmwiki to 
use the 'light' skin:

    $PageSkinList = array('pmwiki' => 'light');
    if (!$Skin && preg_match('/^[-\\w]+$/', $sk)
        && is_dir("$FarmD/pub/skins/$sk")) $Skin = $sk;


More information about the pmwiki-users mailing list