Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

CMSLike

Summary: Make PmWiki behave as a CMS by showing only the actions the current user is allowed to perform
Version: 0.32
Prerequisites: UserAuth
Status:
Maintainer: Didier Lebrun
Categories: Administration, CMS

Question answered by this recipe

To make PmWiki behave as a CMS, by showing only the actions the current user is allowed to perform.

Files

Containing:
  • cookbook/cmslike.php
  • pub/skins/cmslike/cmslike.tmpl

Description

This PmWiki plugin builds dynamic actions menus, depending on the current user rights, according to UserAuth, so the user will only be presented the actions he can perform. It disables the WikiWords create links too in the text when the user is not allowed to edit.

Note: This recipe can be regarded obsolete in the sense that the same functionality (user dependent action links) can be obtained meanwhile more flexibly also with pmwiki built-in means, using conditional markup (:if auth edit:) [[Edit -> ?action=edit]] (:if:) for example in Site.PageActions. ThomasP April 18, 2007, at 04:18 AM

Requirements

It relies on UserAuth, and requires it of course. There is no point anyway to use this plugin if you don't use UserAuth.

Apart from UserAuth, there is no other requirement. It doesn't require several templates, contrarily to another CMS like recipe (see PmWikiAsACMS) and can be used with any templates, including PmWiki standard one.

Installation

  • copy cmslike.php in your cookbook directory
  • add the following lines in your local/config.php file and adjust them to your taste:
 
 #$CmsLikeMenuItems = array(
 # 'print' => '<a href="$PageUrl?action=print" target="_blank"
 #      rel="nofollow">$[Printable View]</a>',
 # 'history' => '<a href="$PageUrl?action=diff"
 #      rel="nofollow">$[Page History]</a>',
 # 'edit' => '<a href="$PageUrl?action=edit"
 #      rel="nofollow">$[Edit Page]</a>',
 # 'upload' => '<a href="$PageUrl?action=upload"
 #      rel="nofollow">$[Uploads]</a>',
 # 'attr' => '<a href="$PageUrl?action=attr"
 #      rel="nofollow">$[Attributes]</a>',
 # 'admin' => '<a href="$PageUrl?action=admin"
 #      rel="nofollow">$[UserAuth Admin]</a>',
 # 'pwchange' => '<a href="$PageUrl?action=pwchange"
 #      rel="nofollow">$[Change Password]</a>');
 #$CmsLikeMenuSep = ' ';
 #$CmsLikeAltMenuItems = $CmsLikeMenuItems;
 #$CmsLikeAltMenuSep = ' - ';
 include_once('cookbook/cmslike.php'); # you need this !
 
  • in your template:
    • replace your static actions menu with <!--function:CmsLikeMenuFmt--> for the standard menu setup
    • ... or with <!--function:CmsLikeMenuFmt alt--> for the alternate menu setup

The cmslike.tmpl file is a sample template based on pmwiki.tmpl. You can just substitute it to pmwiki.tmpl to get it working.

Configuration

The following variables can be defined before cmslike.php is included in config.php:

  • $CmsLikeMenuItems : HTML strings used in the actions menu
  • $CmsLikeMenuSep : separator to be inserted between two menu items
  • $CmsLikeAltMenuItems : alternate menu definition strings
  • $CmsLikeAltMenuSep : alternate menu separator string

Notes

  • UserAuth interception is used for calling CmsLikeMakeActionsList when the group is known, so as to establish the relevant rights. The conditions reproduce UserAuth ones.
  • <!--function:CmsLikeMenuFmt[ alt]--> in the template is used to evaluate the variables when they are fully defined.
  • You can use the "alt" optional arg to get the alternate menu setup instead of the standard (default) one, so you can have 2 different layouts in the same page (ex: a vertical one and an horizontal one like those in PmWiki default template)

History

  1. March 11, 2005: Version 0.1
    1. Initial version
  2. March 14, 2005: Version 0.2
    1. Change $_SESSION[...] calls to $UserInstanceVars->... (see userauth-0.6 changes)
    2. Added page level auth conditions (see userauth-0.6 changes)
    3. Rewrote auth processing to be cleaner and more adaptative to changes
    4. Added Admin Tool and Change Password actions (see userauth-admintool and userauth-pwchange)
    5. Change the template tags to <!--function:CmsLikeMenuFmt[ alt]--> (adjust your template !)
    6. Fixed a potential bug when the configured $CmsLikeMenuItems lacks some actions
  3. March 17, 2005: Version 0.3
    1. Delegate auth processing to UserAuth (thanks to JamesMcDuffie)
    2. Restore create link disabling depending on edit rights (disappeared by mistake in 0.2 !)
    3. Keep $CmsLikeMenuItems and $CmsLikeAltMenuItems configured order for display
  4. March 18, 2005: Version 0.31
    1. Fixed create link disabling
  5. March 23, 2005: Version 0.32
    1. Fixed create link disabling on spaced words

Author and Contributors

Copyright

Copyright 2005 by DidierLebrun, under the GNU GPL License

Comments & Bugs

Below this line, please.


March 13, 2005

  • I just released UserAuth version 0.6 and I have changed the way the session username and password are tracked. Instead of using the $_SESSION array directly in userauth.php, I have abstracted away the functionality into an object defined by the $UserInstanceVars variable. I made this change to allow people to possibly implement cookie based tracking of the username and password. Therefore, you will have to change CMSLike to be consistent.
  • I also wanted to mention that the configuration variables for this script can also be placed inside of a skin's .php file. This might be a better place to put the CMSLike configuration when distributing a skin that depends on it.
  • UserAuth has administrative and password change extensions, is it possible to add menu items for these actions?
  • Is it possible to simplify the necessary changes to a template file? Instead of having to make a function call and then place a variable later on in the template, could you make it such that only one function call or variable needs to be placed in the template per menu?
  • I have released the skin I use for my site, EvolverSkin. I integrated both UserAuth and CMSLike functionality.
  • Great extension, thanks for creating it!

-- JamesMcDuffie


March 14, 2005

Thanks for your review. I'm pleased you like it and adopted it straight away :) I've not taken the time yet to review the changes in UserAuth version 0.6 and their impact on CMSLike, but I'll do it as soon as possible. You're true about the function + variable calls in the template. I was aware of that, but neglected it in the first release.

... A few hours later, the CMSLike version 0.2 is released, with all the wanted functionalities in,... I hope so anyway ;)

-- DidierLebrun


March 15, 2005

I upgraded to version 0.2 and noticed that the pwchange button would show up whenever I was logged out. This was the result of how you were checking abilities. I then changed CMSLike to do the following at around line 130:

 
 if( UserAuth($pagename, $level, false) ) {
 

Instead of this:

 
 $userauth_level = CmsLikeUserAuthLevel($level, $group, $name);
 if($UserInfoObj->UserHasAbility($username, $userauth_level)
   || $UserInfoObj->UserHasAbility($GuestUsername, $userauth_level)
   || $UserInfoObj->UserHasAbility($LoggedInUsername, $userauth_level)
   || $UserInfoObj->UserHasAbility($username, $level.'_all') ) {
 

I realized upon doing this that there was a bug in UserAuth where an error message could be displayed inside the CheckUserAuthPassword function. I fixed this bug and now your CMSLike module can directly call the UserAuth function for checking the permissions of each level just as I have shown above. Hopefully, this will make CMSLike better able to deal with any changes to UserAuth in the future. Hope this helps. -- JamesMcDuffie

One more thing, is it possible for CMSLike to preserve the order that a user defines menu items in? For instance, I like having my edit link at the very left, but instead print is the left most item -- JamesMcDuffie


March 17, 2005

Your idea of simply delegating auth processing to UserAuth instead of implementing a parallel behavior is bright ! I wander why I didn't think of it before ? The script is much leaner and cleaner like that :) In the meantime, I realized I had forgotten the line for disabling the create links when the user doesn't have edit rights in version 0.2, although it was there in 0.1. So I put it back in place. I changed the output processing too, so as to keep the configured menu items order. With all these changes, I made version 0.3. Thanks again for your debugging and suggestions --DidierLebrun


March 17, 2005

Great addon! I still can't get the edit links to disappear, any help?

Could you tell a bit more about your config ?--DidierLebrun

I haven't changed much. I've included userauth, admintool, pwchange and cmslike in config and set $Skin to cmslike. I've turned off LinkWikiWords and rewrite URLs to be pretty. Cmslike is version 0.3. You can se the site at http://spiser.pylse.cx/~krav/wikii/(approve links), there's a test user with password test. --Kristoffer?

Ok. I see the problem. I made a small modification after testing, and introduced a bug. I've fixed it in version 0.31 --DidierLebrun

Great, it works with WikiWords, but not with links like this?. See my wiki for an example. -- Kristoffer?

That's true ! I found the bug and fixed it in version 0.32 --DidierLebrun


How about moving the list of actions into config.php? We'd be able to keep the decisions what extensions go into the wiki in a single place, like this:

  $Actions = array(
    'print'    => 'Printable View',
    'history'  => 'Page History',
    'edit'     => 'Edit Page',
    'upload'   => 'Upload',
    'attr'     => 'Attributes',
    'rename'   => 'Rename Page'
    'admin'    => 'UserAuth Admin',
    'pwchange' => 'Change Password',
  );

  include_once('local/rename.php');
  include_once('local/userauth.php');
  include_once('local/changepw.php');

Currently, I must consistently update both local/config.php and pub/skins/the_skin/the_skin.tmpl if I change anything about the available actions, and that's both annoying and error-prone.

Joachim Durchholz March 20, 2005, at 05:34 AM


I don't understand your point in relation with CMSLike, since CMSLike does actually replace the actions menu in the template by a single function call, and does manage the actions menu in config vars !?

- DidierLebrun March 26, 2005


Sorry for being obtuse. I meant that this functionality belongs to the PmWiki core, so that skin writers can rely on it. Joachim Durchholz April 04, 2005, at 06:25 AM

There are advantages, but drawbacks too in integrating optional features in the core package. It's a complex philosophical question, with lots of side effects to consider. Usually, free software projects prefer the more modular approach of independant and complementary sub-projects, since it relieves the maintainers of the main project from having to take care of too many things when releasing a new version. - DidierLebrun April 5, 2005


Very Nice, Thankyou! I would like to see the logout option be an available CmsLikeMenuOption
'logout' => '<a href="$PageUrl?action=logout" rel="nofollow">Logout</a>

It's a good idea. You can actually do that with the current version by adjusting a bit the config vars, but I'll integrate it in the default config in next version. - DidierLebrun April 5, 2005

Insert 'logout' => '<a href="$PageUrl?action=logout" rel="nofollow">$[Logout]</a>', into the config.php and cmslike.php (it should be obvious where) and change:
$CmsLikeLevelToActions['pwchange'] = array('pwchange');
array_push($CmsLikeLevelToActions['admin'], 'pwchange');

to
$CmsLikeLevelToActions['pwchange'] = array('pwchange','logout');
array_push($CmsLikeLevelToActions['admin'], 'pwchange','logout');
Doug Nov 14, 2005


I use PmWiki as a CMS and don't bother with conditional edit links. I used a bookmarklet in my browser so I can click on the bookmark for ANY PmWiki page I want to edit -- saves me from hunting the Edit Page link down (scrolling up and down looking for it) or typing the variable & value into the URL. See OtherBookmarklets

I do know this won't work for everyone -- but it can be a timesaver whether or not you have edit page links on the page.

         --XES

The menu did disapeared when I replaced pmwiki.tmpl with cmslike.tmpl, after aplieing this fix, the left menu works.

In cmslike.tmpl (around rule 53), the left page (menu) is defined by
<!--PageLeftFmt-->
I replaced the existing
<!--wiki:$Group.SideBar Main.SideBar--></td>
With
<!--wiki:{$Group}.SideBar {$SiteGroup}.SideBar--></td>

Now the left menu works.\\ -- FreekNL?

User notes? : If you use, used or reviewed this recipe, you can add your name. 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 10, 2011, at 11:42 AM