[pmwiki-users] Feature request: Action lists in skins

Patrick R. Michaud pmichaud at pobox.com
Wed Apr 6 21:25:15 CDT 2005


On Wed, Apr 06, 2005 at 04:58:29PM -0500, Jonathan Scott Duff wrote:
> <!--function:ActionList 
> 	sep="~" wrapbegin="((" wrapend="))"
> 	actions="edit,print,diff"
> 	print_text="print this page"
> 	diff_text="page history"
> -->
> 
> where the text for the action is just the action itself unless no
> action_text is specified.
> 
> So far, writing this email has made me lean more towards Pm's side of
> the continuum. I've just added so many knobs to this feature that I
> might as well have coded the HTML myself. 

... and since you have to know a fair bit about HTML anyway to
have gotten this far, basically what we've accomplished is add a 
lot of complexity for no benefit to an admin who is trying to create a
simple skin.  I.e., simple things are no longer simple.

I'll also note that Scott's interpretation above is certainly *not*
Joachim's interpretation -- the actions would have to go into a PHP
array of some sort in order for it to be shared across skins.  But
it's still a fair amount of extra complexity, even for simple skins.
And we still haven't handled extra attributes to the actions,
such as opening in another window (printable view or uploads), or
perhaps adding a template argument to an edit link.

> And just to compare:
> 
> <a href='$PageUrl?action=print'>$[Printable View]</a>
> <a href='$PageUrl?action=diff'>$[Page History]</a>
> <a href='$PageUrl?action=edit'>$[Edit Page]</a>

This is definitely more straightforward.  More to the point, 
consider how we would generate the equivalent of:

    <a href='$ScriptUrl/$Group/RecentChanges'>$[Recent Changes]</a>
    <a target='_blank' href='$PageUrl?action=print'>$[Printable View]</a>
    <a target='_blank' href='$PageUrl?action=upload'>$[Attachments]</a>
    <a href='$PageUrl?action=diff'>$[Page History]</a>
    <a href='$PageUrl?action=edit'>$[Edit Page]</a>

> BTW, the HTML was much easier to generate for me because "the
> boilerplate code is already in pmwiki.tmpl". :-)

Bingo.  And since you already knew HTML (a prerequisite of sorts for
anyone working at this level), it was reasonably obvious what was 
happening, and how to change it.

However, this all points to another possibility, we should embrace HTML
here instead of trying to run away from it.  In particular, a skin 
that wants to allow shared actions can just do:

    <div id='actions'>$ActionLinksFmt</div>

and let the administrator set $ActionLinksFmt with

    $ActionLinksFmt = 
      "<ul><li><a href='$PageUrl?action=print'>$[Printable View]</a></li>
        <li><a href='$PageUrl?action=diff'>$[Page History]</a></li>
        <li><a href='$PageUrl?action=edit'>$[Edit Page]</a></li></ul>";

Of course, the skin.php file can use SDV($ActionLinksFmt, "...") to set 
the default actions if the administrator hasn't defined any.  Then if 
a skin wants to reformat the action list some other way, it can use
something like:

    <div id='actions'><!--function:SkinActionSlicerDicer--></div>

and define a custom function to extract and reformat the <a>...</a> 
tags with something like:

    function SkinActionSlicerDicer($pagename, $x) {
      global $ActionLinksFmt;
      preg_match_all("/<a\\s.*?<\\/a>/is", $ActionLinksFmt, $anchors);
      return implode(' ~ ', (array)$anchors[0]);
    }

As an example, with $ActionLinksFmt set as listed above, the skin
would end up displaying (newlines added for clarity):

    <div id='actions'><a href='$PageUrl?action=print'>$[Printable View]</a> ~
    <a href='$PageUrl?action=diff'>$[Page History]</a> ~
    <a href='$PageUrl?action=edit'>$[Edit Page]</a></div>

As you can see, the anchor tags were taken out of $ActionListFmt and 
reformatted with ' ~ ' between them.  Of course the skin designer 
could make the custom function reformat the links with whatever 
HTML tags are desired.

The nice thing about this approach is that
   - administrators and designers of simple skins only need knowledge 
     of basic HTML
   - advanced skins can still do custom formatting of the links
   - the method is highly portable across skins and actions
   - skins can easily provide suitable default actions

All of that said, I'm probably not going to have something like
$ActionLinksFmt in the default distribution skin.  However, I think
it's a useful convention that other skin authors may want to adopt,
and I'll probably do something like this in some of the more complex
skins I plan to publish.  And without too much more work we could 
extend the convention so that the list of actions can be generated from
other wiki pages as well as the $ActionLinksFmt variable.  :-)

Pm



More information about the pmwiki-users mailing list