[pmwiki-users] Problems with the embedded CSS in pmwiki.php

Patrick R. Michaud pmichaud at pobox.com
Mon Oct 30 14:28:16 CST 2006


On Mon, Oct 30, 2006 at 07:30:14PM +0000, Hans wrote:
> Monday, October 30, 2006, 6:52:14 PM, Patrick wrote:
> 
> >> With this second option I do not see that it is up to the skin.php to
> >> load a pmwiki-core.css file. It could just as well be loaded from
> >> pmwiki.php with a $HTMLHeaderFmt['pmwiki-core'] definition. This will
> >> load at the beginning of HTMlHeader, leaving admin/local
> >> customisations etc to override styles if needed. A skin can still load
> >> a css file later.
> 
> > ... but then how does the admin override the skin's customizations?
> 
> Just like now. If pmwiki adds the pmwiki-core.css in pmwiki.php with
> 
>   $HTMLHeaderFmt['pmwiki-core'] = "
>     <link rel='stylesheet' href='\$FarmPubDirUrl/css/pmwiki-core.css' type='text/css' />\n";
> 
> replacing $HTMLStylesFmt['pmwiki'], then it will be loaded first thing
> in HTMLHeader, and all HTMLStylesFmt definitions come later, and the
> pub/css/local.css etc local css customisations even later.

Either you're misreading my question or I'm misreading your statement.
If a "skin can still load a css file later" (and I'm assuming you mean 
from a template), then how can an admin override the skin's 
customization?  I'm thinking of the situation of:

    <!--HTMLHeader--> 
    <link rel='stylesheet' href='$SkinDirUrl/skin-extra.css' type='text/css' />

How can an administrator override the settings in skin-extra.css?

> > Suppose Alice has an existing skin that doesn't want any of the PmWiki
> > core styles.  In order to get rid of those, Alice has put the following
> > in her skin.php file:
> > 
> >     global $HTMLStylesFmt;
> >     $HTMLStylesFmt['pmwiki'] = '';
> > 
> > If we now change PmWiki's default setting so that it uses
> > $HTMLHeaderFmt to set its core styles instead of $HTMLStylesFmt,
> > as in:
> > 
> >     $HTMLHeaderFmt['pmwiki-core'] = "<link ... />";
> > 
> > Then when Alice upgrades her version of PmWiki, her skin
> > will no longer display properly because the PmWiki core styles
> > are being inserted back into her skin.  
> 
> True. But $HTMLStylesFmt['pmwiki'] = ''; was chiefly done to avoid the
> insertion of <Styles>...</Styles> into each page head, or at least
> reduce these.  

Many people do $HTMLStylesFmt['pmwiki'] = '' because they want to
override the default settings in a skin.css, and not chiefly to
eliminate/reduce <style>...</style>.

> The styles would have been replaced in a css file, which
> will be loaded later than the pmwiki-core.css file, thus overriding
> these settings. 

It's not necessarily true (or even likely) that the replacement styles 
are in a css file that is loaded later than the <!--HTMLHeader-->
directive.  With $HTMLStylesFmt['pmwiki'] set to null, the skin ought to
be doing

    <link rel='stylesheet' href='$SkinDirUrl/skin.css' type='text/css' />
    <!--HTMLHeader-->

Because we've nulled out the embedded styles, the skin doesn't have
to worry about them interfering with the skin.css file, so it gets
loaded first (before the administrative/local settings).

If we now change the default such that a pmwiki-core.css is added
via $HTMLHeaderFmt, then that changes things because then the
core styles are being loaded after the skin.css file, at the
point given by <!--HTMLHeader-->.  Since the skin didn't expect
the core styles to be present
if we change the default such that a pmwiki-core.css file suddenly
appears in the output (at the point given by <!--HTMLHeader-->),
then those settings will start to override the skin's settings
and the existing site will break.

> And any skin designer going to the trouble of eliminating the pmwiki
> styles with $HTMLStylesFmt['pmwiki'] = ''; etc. will be very happy
> that there is now an actual pmwiki-core.css file, which can be easily
> replaced.

I'm more concerned about how this affects site administrators more
than skin designers.  Upgrades affect site administrators more directly,
because things that once worked suddenly stop working.  And if the
site administrator isn't the skin designer, they may not have any
clue that there is such a thing as $HTMLStylesFmt, or that it's the
source of the change.

> > If I understood correctly, your proposal was that a skin designer
> > would use the following in a template file:
> 
> >     <link rel='stylesheet'
> > href='$FarmPubDirUrl/css/pmwiki-core.css' type='text/css' />
> >     <link rel='stylesheet' href='$SkinDirUrl/skin.css' type='text/css' />
> >     <!--HTMLHeaderFmt-->
> 
> > But if PmWiki is setting $HTMLHeaderFmt['pmwiki-core'] by default, 
> > then it's also necessary for the skin.php file to unset that value 
> > in order to avoid having pmwiki-core.css load a second time
> > (and after the skin.css).  So, the skin designer still has to
> > manipulate $HTMLHeaderFmt in order to make things work properly.
> 
> As skin designer I would use in the skin template just as now:
>
>        <link rel='stylesheet' href='$SkinDirUrl/skin.css' type='text/css' />
>        <!--HTMLHeaderFmt-->
>
> and to override any css introduced with HTMLHeader I could add a
> second css file with
> 
>       <link rel='stylesheet' href='$SkinDirUrl/skin-extra.css' type='text/css' />

As noted before, with this approach an admin cannot override settings in
skin-extra.css without modifying the skin.

> or in skin.php with
> 
>    $HTMLHeaderFmt['skin-extra'] = "
>      <link rel='stylesheet' href='\$SkinDirUrl/css/skin-extra.css' type='text/css' />\n";

This works in the current version of PmWiki, and has the advantage that
css files in pub/css/ will override the skin-extra.css settings.
But in this case, there's also no need to have separate skin.css and
skin-extra.css files -- all of the settings can be safely placed into
a single css file, and configured with:

    $HTMLHeaderFmt['skin'] = "
      <link rel='stylesheet' href='\$SkinDirUrl/css/skin.css' type='text/css' />\n";

> Or if I wanted to replace pmwiki-core.css with my own version:
> 
>    $HTMLHeaderFmt['pmwiki-core'] = "
>      <link rel='stylesheet' href='\$SkinDirUrl/css/skin-extra.css' type='text/css' />\n";

This can also be done now with:

    $HTMLStylesFmt['pmwiki'] = '';
    $HTMLHeaderFmt['skin'] = "<link ... />";

Forgive me if I'm misreading things, but you seem to be approaching this
from the perspective of "it would be better to have the core settings in
a .css file instead of embedded styles".  I don't disagree, but that isn't
the issue that started this thread, which is "how can a skin override
the core settings and still allow an admin to override the skin's settings?"
(Yes, you did say you entered the discussion in mid-thread.  :-)

If all we're doing is changing PmWiki's embedded styles into an
external CSS, but not changing anything with respect to the other
issue, I don't see that it's worth the hassle to existing sites to
change this.  As noted above, skins can already move the core styles 
into an external css without too much difficulty, and without needing to
change PmWiki's existing defaults.

To support that, I don't see a major problem with including a 
pub/css/pmwiki-core.css file in the distribution.  Then a skin
can simply set $HTMLStylesFmt['pmwiki'] = '' in skin.php, and 
the template can have:

    <link href='$FarmPubDirUrl/css/pmwiki-core.css' ... />
    <link href='$SkinDirUrl/skin.css' ... />
    <!--HTMLHeader-->

But, as I've been saying, I do see a problem with switching
PmWiki's defaults to use the pmwiki-core.css file, because it will
break existing sites that are expecting the defaults to be in 
$HTMLStylesFmt[] and not $HTMLHeaderFmt[] .  And I do think it'll
be a fairly substantial issue for many sites that have built
custom skins.

Pm




More information about the pmwiki-users mailing list