[pmwiki-devel] Group.Name pattern

Patrick R. Michaud pmichaud at pobox.com
Fri Dec 8 14:59:28 CST 2006


On Fri, Dec 08, 2006 at 08:17:53PM +0000, Hans wrote:
> Friday, December 8, 2006, 7:11:33 PM, Patrick wrote:
> 
> > ...FmtPageName is your friend!
> 
> >     MatchPageNames($targetpage, FmtPageName('{$Group}.*', $pagename))
> 
> Thanks so much! I nearly got it all working now.
> But I don't know how to include exclusion patterns.
> I got this code, as part of a permission function:
> 
> $CommentNameFmt, array(
>     '{$Group}.*',          // all pages in current group    
>     '*.{$Name}-Comment',   // pages with -Comment prefix in any group
>     '{$FullName}-Talk',    // page with -Talk prefix in current group
>     '{$FullName}-Discuss', // page with -Discuss prefix in current group 
>     'Comments.{$Group}-{$Name}', //pages in Comments with name 'Group-Name'
> //    'Comments.*',        // all pages in Comments group
> //    '*.*',               // all pages!!!
> );
> 
>   foreach ((array)$CommentNameFmt as $n) {
>           if(MatchPageNames($targetname, FmtPageName($n, $pagename)))
>              return $CommentPermission=1;} //allow
>   }
> 
> so adding '-$SiteGroup.*' to the array does not work since it is
> looking for one allowed match, and if it finds one, its done.
> Do I need to run a match on an exclusion pattern array first?

MatchPageNames() already knows how to deal with arrays and multiple
patterns, so let it do the loop instead of you doing it.  Better:

  $CommentNameFmt = array(
      '{$Group}.*',          // all pages in current group    
      '*.{$Name}-Comment',   // pages with -Comment prefix in any group
      '{$FullName}-Talk',    // page with -Talk prefix in current group
      '{$FullName}-Discuss', // page with -Discuss prefix in current group 
      'Comments.{$Group}-{$Name}', //pages in Comments with name 'Group-Name'
      '-$SiteGroup.*'        // no pages in SiteGroup
  );

  $CommentPermission = 
    (boolean)MatchPageNames($targetname,
                            FmtPageName(implode(' ', CommentNameFmt),
                                        $pagename));
      
Pm



More information about the pmwiki-devel mailing list