[pmwiki-devel] Group.Name pattern

Hans design5 at softflow.co.uk
Fri Dec 8 11:43:49 CST 2006


I am looking for a good way to match a target pagename against
patterns in an array.

In the first of the following arrays I can conditionally check the
pagenames against the target pagename. In the second I can check
against a regex pattern. The first is easier to write and would be my
preferred choice, but it does not handle any wildcard characters.
The second array item does not work (to indicate all pages in the
current  group). The second array handles this, but I find it is a lot
to ask from any admin to insert usable regex patterns. Therefor my
question and ask for help, to come up with a good and admin friendly
way, ideally similar to using wildcards in pagelist, because that is
very short and we get used to it.

// Default allowed pagenames
SDVA($CommentNameFmt, array(
    '{$Group}.{$Name}-Comments',
    '{$Group}.*',              //this does not work (no wildcards!)
));

    foreach ((array)$CommentNameFmt as $n) {
       $n = FmtPageName($n, $pagename);
       if($n==$targetname) return $EditPermission=1; //allow page edit
    }
    
// Default patterns for allowed pagenames
$name = PageVar($pagename, '$Name');
$group = PageVar($pagename, '$Group');
SDVA($CommentNamePattern, array(
        $group.'\.(.*)',      // this works
        $group.$name.'-Comment',
        $group.$name.'-Talk',
        'Comments.'.$group.'-'.$name,
));

    foreach ((array)$CommentNamePattern as $v) {
       $match = preg_match("/^($v)$/i", $targetname);
       if($match) return $EditPermission=1; //allow page edit
    }  


-- 
Best regards,
 Hans




More information about the pmwiki-devel mailing list