Skip to content

Commit

Permalink
Item2030: add showdenied acl support, it uses some more perf to test …
Browse files Browse the repository at this point in the history
…ACLs but on the target system its not important yet

git-svn-id: http://svn.foswiki.org/trunk/MenuListPlugin@15636 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Oct 18, 2012
1 parent 22a5171 commit bee0977
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 68 deletions.
126 changes: 65 additions & 61 deletions data/System/MenuListPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ One line description, required for extensions repository catalog.
%TOC%

---++ Usage
Create a topic (in this example =MenuTopic=), containing a multi-level bullet list of topics
Create a topic (in this example =MenuTopic=), containing a multi-level bullet list of web.topics
you want to make a folding menu with.

__Note: its important that the links include the web, as the menu may be referenced from another web.__

Then add =%<nop>MENULIST{topic="MenuTopic"}%= to your sidebar.

If the currently viewed topic is in the list, MenuListPlugin will open up all the nodes leading up to where it is, and direct child nodes of this topic.
Expand All @@ -22,6 +24,7 @@ If the currently viewed topic is in the list, MenuListPlugin will open up all th
| =format=, =separator= | see %SYSTEMWEB%.FormattedSearch | bullet list |
| =quiet= | in =collapse= mode, if you are not on a topic that is listed in the Menu topic, show nothing at all | false |
| =showlevel= | filters to only show menu entries of that level (works in both collapse and full mode) | unset (0) |
| =showdenied= | filters to only show menu entries that the current user has VIEW permission for | =false= |
| =levels= | how many levels of menu to show (single integer) | =all= (9999) |


Expand All @@ -30,71 +33,71 @@ If the currently viewed topic is in the list, MenuListPlugin will open up all th
if =MenuTopic= contains

<verbatim>
* FoswikiSiteSkin
* FoswikiSiteSkinNavigationTemplate
* MoveableTypeSkin
* PatternSkin
* PatternSkinCss
* PatternSkinColorSettings
* PatternSkinCssCookbook
* PatternSkinCssCookbookCenterPage
* PatternSkinCssCookbookCenterPageBorder
* PatternSkinCssCookbookEditTableStyle
* PatternSkinCssCookbookFonts
* PatternSkinCssCookbookNoLeftBar
* PatternSkinCssCookbookNoTopBar
* PatternSkinCustomization
* PatternSkinElements
* PatternSkinGraphics
* PatternSkinHeaderArt
* PatternSkinWebCreateNewTopicTemplate
* PlainSkin
* PrintSkin
* Skins
* SkinBrowser
* SkinTemplates
* SlionSkin
* SlionSkinColorSettings
* SlionSkinCss
* SlionSkinCssCookbook
* SlionSkinCssCookbookCenterPageBorder
* SlionSkinCssCookbookCenterPage
* SlionSkinCssCookbookEditTableStyle
* SlionSkinCssCookbookFonts
* SlionSkinCssCookbookNoLeftBar
* SlionSkinCssCookbookNoTopBar
* SlionSkinCustomization
* SlionSkinElements
* SlionSkinGraphics
* SlionSkinHeaderArt
* SlionSkinWebCreateNewTopicTemplate
* WidgetsSkin
* System.FoswikiSiteSkin
* System.FoswikiSiteSkinNavigationTemplate
* System.MoveableTypeSkin
* System.PatternSkin
* System.PatternSkinCss
* System.PatternSkinColorSettings
* System.PatternSkinCssCookbook
* System.PatternSkinCssCookbookCenterPage
* System.PatternSkinCssCookbookCenterPageBorder
* System.PatternSkinCssCookbookEditTableStyle
* System.PatternSkinCssCookbookFonts
* System.PatternSkinCssCookbookNoLeftBar
* System.PatternSkinCssCookbookNoTopBar
* System.PatternSkinCustomization
* System.PatternSkinElements
* System.PatternSkinGraphics
* System.PatternSkinHeaderArt
* System.PatternSkinWebCreateNewTopicTemplate
* System.PlainSkin
* System.PrintSkin
* System.Skins
* System.SkinBrowser
* System.SkinTemplates
* System.SlionSkin
* System.SlionSkinColorSettings
* System.SlionSkinCss
* System.SlionSkinCssCookbook
* System.SlionSkinCssCookbookCenterPageBorder
* System.SlionSkinCssCookbookCenterPage
* System.SlionSkinCssCookbookEditTableStyle
* System.SlionSkinCssCookbookFonts
* System.SlionSkinCssCookbookNoLeftBar
* System.SlionSkinCssCookbookNoTopBar
* System.SlionSkinCustomization
* System.SlionSkinElements
* System.SlionSkinGraphics
* System.SlionSkinHeaderArt
* System.SlionSkinWebCreateNewTopicTemplate
* System.WidgetsSkin
</verbatim>

and you added =%<nop>MENULIST{topic="MenuTopic"}%= to the WebLeftBar topic in the System web, then navigated to PatternSkinCssCookbook
you would get

* FoswikiSiteSkin
* MoveableTypeSkin
* PatternSkin
* PatternSkinCss
* PatternSkinColorSettings
* PatternSkinCssCookbook
* PatternSkinCssCookbookCenterPage
* PatternSkinCssCookbookEditTableStyle
* PatternSkinCssCookbookFonts
* PatternSkinCssCookbookNoLeftBar
* PatternSkinCssCookbookNoTopBar
* PatternSkinCustomization
* PatternSkinElements
* PatternSkinGraphics
* PatternSkinHeaderArt
* PatternSkinWebCreateNewTopicTemplate
* PlainSkin
* PrintSkin
* Skins
* SlionSkin
* WidgetsSkin
* System.FoswikiSiteSkin
* System.MoveableTypeSkin
* System.PatternSkin
* System.PatternSkinCss
* System.PatternSkinColorSettings
* System.PatternSkinCssCookbook
* System.PatternSkinCssCookbookCenterPage
* System.PatternSkinCssCookbookEditTableStyle
* System.PatternSkinCssCookbookFonts
* System.PatternSkinCssCookbookNoLeftBar
* System.PatternSkinCssCookbookNoTopBar
* System.PatternSkinCustomization
* System.PatternSkinElements
* System.PatternSkinGraphics
* System.PatternSkinHeaderArt
* System.PatternSkinWebCreateNewTopicTemplate
* System.PlainSkin
* System.PrintSkin
* System.Skins
* System.SlionSkin
* System.WidgetsSkin

---++ Installation Instructions

Expand All @@ -110,6 +113,7 @@ Many thanks to the following sponsors for supporting this work:
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL 3 (Gnu General Public License)]] |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 18 Oct 2012: | added showdenied="off" mode to only show menu items the user is allowed to navigate to |
| 8 May 2010: | added =levels= option so you can show several levels below =showlevel=, also changed output so that if you use =showlevel= the default =ul= bullet list starts from only _one_ bullet level |
| 1 Aug 2009: | added =quiet= param for collapsed view |
| 22 Jul 2009: | add non-collapse mode, level and formatting so we can show a menu in a table |
Expand Down
57 changes: 50 additions & 7 deletions lib/Foswiki/Plugins/MenuListPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ use strict;
require Foswiki::Func; # The plugins API
require Foswiki::Plugins; # For the API version

our $VERSION = '$Rev$';
our $RELEASE = '$Date$';
our $SHORTDESCRIPTION = 'dynamic Folding menu list';
our $VERSION = '2.0';
our $RELEASE = '18-Nov-2012';
our $SHORTDESCRIPTION = 'dynamic Folding menu list';
our $NO_PREFS_IN_TOPIC = 1;
our $baseWeb;
our $baseTopic;
our $sessionUser;

sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;
Expand All @@ -38,8 +39,9 @@ sub initPlugin {
return 0;
}

$baseTopic = $topic;
$baseWeb = $web;
$baseTopic = $topic;
$baseWeb = $web;
$sessionUser = $user;

Foswiki::Func::registerTagHandler( 'MENULIST', \&MENULIST );

Expand Down Expand Up @@ -83,9 +85,12 @@ sub MENULIST {
if ( $line =~ /^(\t+)\*\s+(.*)$/ ) {
push( @list, { tabs => $1, length => length($1), string => $2 } );

# my ($w, $t) = Foswiki::Func::normalizeWebTopicName($baseWeb, $list[$#list]{string});
my $webTopicRegex = "$baseWeb.$baseTopic";

#deal with both dots and slashes as web separators
$webTopicRegex =~ s/[.\/]/[.\/]/g;
if ( ( $currentTopicIndex < 0 )
and ( $list[$#list]{string} =~ /.*$baseWeb\.$baseTopic.*/ ) )
and ( $list[$#list]{string} =~ /$webTopicRegex/ ) )
{
$currentTopicIndex = $#list;
}
Expand Down Expand Up @@ -191,6 +196,44 @@ sub MENULIST {
}
}

if ( !Foswiki::Func::isTrue( $params->{showdenied}, 0 ) ) {

#copied from Foswiki::Render..

# Spaced-out Wiki words with alternative link text
# i.e. [[$1][$3]]
my $webtopic;
if ( $list[$idx]{string} =~
/\[\[([^\]\[\n]+)\](\[([^\]\n]+)\])?\]/ )
{
$webtopic = $1;

# } elsif ($list[$idx]{string} =~ s($STARTWW
}
elsif (
$list[$idx]{string} =~ /
(?:($Foswiki::regex{webNameRegex})\.)?
($Foswiki::regex{wikiWordRegex}|
$Foswiki::regex{abbrevRegex})
($Foswiki::regex{anchorRegex})?/xom
)
{
$webtopic = ( defined($1) ? $1 . '.' . $2 : $2 );
}
my ( $w, $t ) =
Foswiki::Func::normalizeWebTopicName( $baseWeb, $webtopic );
my $permitted = (
Foswiki::Func::checkAccessPermission(
'VIEW', $sessionUser, undef, $t, $w
)
);

#print STDERR "---$sessionUser is $permitted allowed to view $w . $t\n";
next unless $permitted;

#TODO: it'd be faster to skip the entire branch once we find one that is out.
}

my $str = $format;
$str =~ s/\$tabs/$list[$idx]{tabs}/g;
$str =~ s/\$depth/$list[$idx]{length}/g;
Expand Down

0 comments on commit bee0977

Please sign in to comment.