DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:display_acls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tips:display_acls [2007-10-15 15:49]
131.220.9.183 made mail address clickable
tips:display_acls [2007-11-20 13:29] (current)
131.220.9.168 Small bugfix
Line 1: Line 1:
 +====== Display ACLs in page footer ======
  
 +Sometimes, it is interesting to know, who is allowed to view the current page. Checking this in the ACL plugin is difficult and only possible for admins. By patching your favorite [[:Template|template]], you can display this information in the page footer. Remarks, suggestions etc. go to <bihler@iai.uni-bonn.de>.
 +
 +===== Instructions =====
 + 
 +Somewhere in your template's ''main.php'', you'll find these lines (line 101-108 in the default template):
 +
 +<code php>
 +    <div class="meta">
 +      <div class="user">
 +        <?php tpl_userinfo()?>
 +      </div>
 +      <div class="doc">
 +        <?php tpl_pageinfo()?>
 +      </div>
 +    </div>
 +</code>
 +
 +Replace these lines with the following code:
 +
 +<code php>
 +   <?php
 +    function tpl_aclinfo() {
 + global $ID, $AUTH_ACL;
 +
 + if (auth_quickaclcheck($ID) == 0) 
 +     return; // no rights to view, no rights to get this info
 +
 + $page_acls = array();
 + $namespaces = array();
 +    
 + $ns = getNS($ID);
 + while ($ns) {
 +    array_unshift($namespaces,$ns . ':*');
 +    $ns = getNS($ns);  
 + }
 + array_unshift($namespaces,'*'); // root
 +       
 + $namespaces[] = $ID;
 +       
 + // check matches
 + foreach ($namespaces as $level) {
 + $matches = preg_grep('/^'.preg_quote($level,'/').'\s+\S+\s+\d+\s*$/',$AUTH_ACL);
 +     $this_acls = array();
 + foreach($matches as $match){
 +       $match = preg_replace('/#.*$/','',$match); //ignore comments
 +       $acl   = preg_split('/\s+/',$match);
 +       $this_acls[urldecode($acl[1])] = $acl[2];
 +       if ($acl[1] == "@ALL" // overwrites stuff from upper level
 +         $page_acls = array();
 +     }
 +     $page_acls =  array_merge($page_acls,$this_acls);
 + }
 +    
 + // check if visible to everyone:
 + if (($page_acls['@ALL'] !== false) && $page_acls['@ALL'] > 0) 
 +   return; // page is visible to everyone
 +    
 + $list = array();
 + foreach ($page_acls as $user => $right) {
 +     if ($right > 0 && $user != "@admin" ) // admins can see everything
 +         array_push($list,$user);
 + }
 + if (count($list)) {
 +     sort($list);
 + print "(page visible to: ";
 + print join(', ',$list);
 + print ")";
 + }
 +
 + // Uncomment this, if you want to display users/groups who cannot access this page, too:
 + /* $list = array();
 + foreach ($page_acls as $user => $right) {
 +     if ($right == 0)
 +         array_push($list,$user);
 + }
 + if (count($list)) {
 +     sort($list);
 + print "(page hidden to: ";
 + print join(', ',$list);
 + print ")";
 + }
 + */
 +
 +}
 +  ?>
 +
 +    <div class="meta">
 +      <div class="user">
 +        <?php tpl_userinfo()?> 
 +        <?php tpl_aclinfo()?>
 +      </div>
 +      <div class="doc">
 +        <?php tpl_pageinfo()?>
 +      </div>
 +    </div>
 +</code>
tips/display_acls.txt ยท Last modified: 2007-11-20 13:29 by 131.220.9.168