DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:display_acls

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, you can display this information in the page footer. Remarks, suggestions etc. go to bihler [at] iai [dot] uni [dash] bonn [dot] de.

Instructions

Somewhere in your template's main.php, you'll find these lines (line 101-108 in the default template):

    <div class="meta">
      <div class="user">
        <?php tpl_userinfo()?>
      </div>
      <div class="doc">
        <?php tpl_pageinfo()?>
      </div>
    </div>

Replace these lines with the following code:

   <?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>
tips/display_acls.txt · Last modified: 2007-11-20 13:29 by 131.220.9.168

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki