diff options
Diffstat (limited to 'lib/plugins/acl/admin.php')
-rw-r--r-- | lib/plugins/acl/admin.php | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/lib/plugins/acl/admin.php b/lib/plugins/acl/admin.php index b38d2ac6e..1f666660c 100644 --- a/lib/plugins/acl/admin.php +++ b/lib/plugins/acl/admin.php @@ -17,6 +17,15 @@ if(!defined('DOKU_INC')) die(); class admin_plugin_acl extends DokuWiki_Admin_Plugin { var $acl = null; var $ns = null; + /** + * The currently selected item, associative array with id and type. + * Populated from (in this order): + * $_REQUEST['current_ns'] + * $_REQUEST['current_id'] + * $ns + * $ID + */ + var $current_item = null; var $who = ''; var $usersgroups = array(); var $specials = array(); @@ -72,6 +81,16 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { $this->ns = cleanID($_REQUEST['ns']); } + if ($_REQUEST['current_ns']) { + $this->current_item = array('id' => cleanID($_REQUEST['current_ns']), 'type' => 'd'); + } elseif ($_REQUEST['current_id']) { + $this->current_item = array('id' => cleanID($_REQUEST['current_id']), 'type' => 'f'); + } elseif ($this->ns) { + $this->current_item = array('id' => $this->ns, 'type' => 'd'); + } else { + $this->current_item = array('id' => $ID, 'type' => 'f'); + } + // user or group choosen? $who = trim($_REQUEST['acl_w']); if($_REQUEST['acl_t'] == '__g__' && $who){ @@ -167,7 +186,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { echo '<div class="level1">'.NL; echo '<div id="acl__tree">'.NL; - $this->_html_explorer($_REQUEST['ns']); + $this->_html_explorer(); echo '</div>'.NL; echo '<div id="acl__detail">'.NL; @@ -267,8 +286,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { usort($data,array($this,'_tree_sort')); $count = count($data); if($count>0) for($i=1; $i<$count; $i++){ - if($data[$i]['type'] == 'f') break; // namespaces come first, we're done - if($data[$i-1]['id'] == $data[$i]['id']) unset($data[$i]); + if($data[$i-1]['id'] == $data[$i]['id'] && $data[$i-1]['type'] == $data[$i]['type']) unset($data[$i]); } return $data; } @@ -279,13 +297,39 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * Sorts the combined trees of media and page files */ function _tree_sort($a,$b){ - if($a['type'] == 'd' && $b['type'] == 'f'){ + // handle the trivial cases first + if ($a['id'] == '') return -1; + if ($b['id'] == '') return 1; + // split up the id into parts + $a_ids = explode(':', $a['id']); + $b_ids = explode(':', $b['id']); + // now loop through the parts + while (count($a_ids) && count($b_ids)) { + // compare each level from upper to lower + // until a non-equal component is found + $cur_result = strcmp(array_shift($a_ids), array_shift($b_ids)); + if ($cur_result) { + // if one of the components is the last component and is a file + // and the other one is either of a deeper level or a directory, + // the file has to come after the deeper level or directory + if (empty($a_ids) && $a['type'] == 'f' && (count($b_ids) || $b['type'] == 'd')) return 1; + if (empty($b_ids) && $b['type'] == 'f' && (count($a_ids) || $a['type'] == 'd')) return -1; + return $cur_result; + } + } + // The two ids seem to be equal. One of them might however refer + // to a page, one to a namespace, the namespace needs to be first. + if (empty($a_ids) && empty($b_ids)) { + if ($a['type'] == $b['type']) return 0; + if ($a['type'] == 'f') return 1; return -1; - }elseif($a['type'] == 'f' && $b['type'] == 'd'){ - return 1; - }else{ - return strcmp($a['id'],$b['id']); } + // Now the empty part is either a page in the parent namespace + // that obviously needs to be after the namespace + // Or it is the namespace that contains the other part and should be + // before that other part. + if (empty($a_ids)) return ($a['type'] == 'd') ? -1 : 1; + if (empty($b_ids)) return ($b['type'] == 'd') ? 1 : -1; } /** @@ -473,8 +517,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { } // highlight? - if( ($item['type']=='d' && $item['id'] == $this->ns) || - ($item['type']!='d' && $item['id'] == $ID)) $cl = ' cur'; + if( ($item['type']== $this->current_item['type'] && $item['id'] == $this->current_item['id'])) + $cl = ' cur'; // namespace or page? if($item['type']=='d'){ |