Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

DynamicPageActions

Summary: Dynamic PageActions
Version: 1.1
Prerequisites: PmWiki 2.1.beta33 or later, AuthUser or UserAuth
Status:
Maintainer: hartwork

Questions answered by this recipe

How can I show/hide certain page actions for logged-out users? This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

This recipe provides a Site.PageActions page that adapts itself according to the current login status and page action.
This table shows under what conditions a button is available:

Button Condition
Attach Logged in, upload allowed
Edit Logged in, action not "edit"
History Logged in, action not "diff"
Login Not logged in
Logout Logged in
Print Action not "print"
Search true
View Action not "browse"

Installation

These files have to be modified:

  • config.php
  • Site.PageActions

config.php

Add these lines to you local/config.php:

# Provide action conditional (:if action ACTION:)
$Conditions['action'] = '\$GLOBALS["action"]==\$condparm';
# Viewing the diff also requires "edit" rights
# which logged-out users usually don't have.
# Thanks for this to Hagan Fox.
$HandleAuth['diff'] = 'edit';

Site.PageActions

This recipe works with AuthUser or UserAuth.
Choose one of these two:

Variant for AuthUser

Change your Site.PageActions to:

* [[{$FullName}?action=search | $[Search] ]]
(:if ( ! action browse ) :)
* %item class=browse accesskey='$[ak_view]'%[[{$FullName} | $[View] ]]
(:if ( auth edit && ! action edit ) :)
* %item rel=nofollow class=edit accesskey='$[ak_edit]'%[[{$FullName}?action=edit | $[Edit] ]]
(:if ( auth edit && ! action diff ) :)
* %item rel=nofollow class=diff accesskey='$[ak_history]'%[[{$FullName}?action=diff | $[History] ]]
(:if ( auth upload ) :)
* %item rel=nofollow class=upload accesskey='$[ak_attach]'%[[{$FullName}?action=upload | $[Attach] ]]
(:if ( ! action print ) :)
* %item rel=nofollow class=print accesskey='$[ak_print]'%[[{$FullName}?action=print | $[Print] ]]
(:if ( authid ) :)
* %item rel=nofollow class=login accesskey='$[ak_login]'%[[{$FullName}?action=logout | $[Logout] ]]
(:if ( ! authid ):)
* %item rel=nofollow class=logout accesskey='$[ak_logout]'%[[{$FullName}?action=login | $[Login] ]]
(:if:)

Variant for UserAuth

Change your Site.PageActions to:

* [[{$FullName}?action=search | $[Search] ]]
(:if ( ! action browse ) :)
* %item class=browse accesskey='$[ak_view]'%[[{$FullName} | $[View] ]]
(:if ( loggedin && ! action edit ) :)
* %item rel=nofollow class=edit accesskey='$[ak_edit]'%[[{$FullName}?action=edit | $[Edit] ]]
(:if ( loggedin && ! action diff ) :)
* %item rel=nofollow class=diff accesskey='$[ak_history]'%[[{$FullName}?action=diff | $[History] ]]
(:if ( loggedin && auth upload ) :)
* %item rel=nofollow class=upload accesskey='$[ak_attach]'%[[{$FullName}?action=upload | $[Attach] ]]
(:if ( ! action print ) :)
* %item rel=nofollow class=print accesskey='$[ak_print]'%[[{$FullName}?action=print | $[Print] ]]
(:if ( loggedin ) :)
* %item rel=nofollow class=login accesskey='$[ak_login]'%[[{$FullName}?action=logout | $[Logout] ]]
(:if ( ! loggedin ) :)
* %item rel=nofollow class=logout accesskey='$[ak_logout]'%[[{$FullName}?action=login | $[Login] ]]
(:if:)

Notes

Tested with PmWiki 2.1.2
Don't use with StaticPages as the generated pages won't have all actions on it.

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments


I was only able to get this to work by inserting an asterix before each $FullName. This is necessary with PmWiki version 2.2.0-beta1 and beyond. i.e..

* [[{*$FullName}?action=search | $[Search] ]]

-- James

Yes, thanks James. I found that without the asterisk, $Fullname would resolve to "site.pageActions" instead of the current page when viewing any but site and main groups. -- Dave


This does not work without UserAuth? Is it possible to have the Loggin when you're using passwords? Thanks a log- Chris

I'm not fully sure what you mean. UserAuth is needed for the "loggedin" conditional. --hartwork

I found a solution for myself. I'm not sure if it's right to add it here. Feel free to move it! If you want a Login when your using Passwords (View - Edit - History - Upload is hidden without a valid pass), your Site.PageActions should have something like this:

(:if !auth edit:)
* %item class=edit accesskey=$[ak_edit]%[[{$FullName}?action=edit | Login ]]
(:if auth edit:)
* %item class=browse accesskey=$[ak_view]%[[{$FullName} | $[View] ]]
(:if auth edit:)
* %item class=edit accesskey=$[ak_edit]%[[{$FullName}?action=edit | $[Edit] ]]
* %item class=diff accesskey=$[ak_history]%[[{$FullName}?action=diff | $[History] ]]
(:if auth upload:)
* %item class=upload accesskey=$[ak_attach]%[[{$FullName}?action=upload | $[Attach] ]]
(:if:)
* %item class=print accesskey=$[ak_print]%[[{$FullName}?action=print | $[Print] ]] }

The Login guides you to a password prompt and then to the edit mode. The View-Edit-History-Upload Buttons appear.

If you're using sectionEdit you may want, that the Edit section buttons do appear also after the Login. You have to modify the include_once for this file in your local config to this Code:

if (CondAuth ($pagename, 'edit')) {include_once('cookbook/sectionedit.php');}

Hope someone finds this helpful - Chris.

I indeed find this very usefull. Thanks Chris! I wonder why this is not default in PmWiki? - Bastian, 2006-08-24

Now if you want login/logout based strictly on whether a password has been used in the session, you can use

(:if !enabled AuthPw:)
* [[{$FullName}?action=login | Login ]]
(:if enabled AuthPw:)
* [[Main/HomePage?action=logout | Logout ]]

A lot like Cookbook/AuthUserCMSLike, but with a different page. So, perhaps the two recipes should be merged?


This is my code for UserAuth 0.70:

* item class=browse accesskey='$[ak_view]' [[{$FullName} | $[View] ]]
(:if loggedin:)
* item rel=nofollow class=edit accesskey='$[ak_edit]' [[{$FullName}?action=edit | $[Edit] ]]
* item rel=nofollow class=diff accesskey='$[ak_history]' [[{$FullName}?action=diff | $[History] ]]
(:if:)
(:if auth upload:)(:if loggedin:)
* item rel=nofollow class=upload accesskey='$[ak_attach]'%25[[{$FullName}?action=upload | $[Attach] ]]
(:if:)(:if:)
* item rel=nofollow class=print accesskey='$[ak_print]'%25[[{$FullName}?action=print | $[Print] ]]

Maybe be helpfull.

See Also

AuthUser
UserAuth
PmWiki as a CMS
Bookmarklet an alternative approach to provide "clean" pages for visitors, but action links for editors.

Contributors

User notes?: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date
* (-) Optional negative comment. Name, date

These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on September 11, 2007, at 11:56 AM