[pmwiki-users] Method to selectively include template markup based on auth level
Patrick R. Michaud
pmichaud at pobox.com
Fri Sep 2 12:09:23 CDT 2005
On Fri, Sep 02, 2005 at 05:53:04PM +0100, Mr Wappy wrote:
> I have been using a skin which has tabs for view,
> edit, attr etc which are displayed all the time. I
> have been trying to determine how I could selectively
> display them based on the current users permissions.
The PmWiki 2 default skin does this for its tabs. For example, see
http://www.pmwiki.org/wiki/PmWiki/PmWiki
http://www.pmwiki.org/wiki/Main/WikiSandbox
and notice that the "Attach" link appears only where upload permissions
are enabled.
This is all handled from the Site.PageActions page, which has
something like the following (simplified here for clarity):
* %item class=browse% [[{$FullName} | View]]
* %item class=edit% [[{$FullName}?action=edit | Edit]]
* %item class=history% [[{$FullName}?action=diff | History]]
(:if auth upload:)
* %item class=upload% [[{$FullName}?action=upload | Attach]]
(:if:)
* %item class=print% [[{$FullName}?action=print | Print]]
Notice that the (:if ...:) causes the "Attach" link to be displayed
only if the visitor is currently authorized to upload attachments.
In the skin template, we simply do:
<!--wiki:$SiteGroup.PageActions-->
which includes the above page, and then use CSS to style the list
into tabs.
More generally, one could use:
(:if auth read:)
* %item class=browse% [[{$FullName} | View]]
(:if auth edit:)
* %item class=edit% [[{$FullName}?action=edit | Edit]]
* %item class=history% [[{$FullName}?action=diff | History]]
(:if auth upload:)
* %item class=upload% [[{$FullName}?action=upload | Attach]]
(:if auth read:)
* %item class=print% [[{$FullName}?action=print | Print]]
(:ifend:)
to display only those actions for which the visitor has authorization.
The "class=xyz" items above make it possible to style the "active tab"
based on the current action, as seen in
http://www.pmwiki.org/wiki/Test/Tabs .
The magic that makes this per-action highlight happen is in the
local customization file:
$HTMLStylesFmt[] =
" #wikicmds li.$action
{ background-color:white; border-bottom:1px solid white; } ";
which styles the list item corresponding to $action with a
different background color from the other items. (Obviously
more complex styling could be done here.)
Pm
More information about the pmwiki-users
mailing list