Skip to content

Commit de301a3

Browse files
committed
Fix display of media manager namespace hierarchy
When the media manager is called with ns parameter set to a value higher than the last namespace defined in the wiki, the non-existing namespace is not added to the hierarchy. This behavior is not consistent with what happens when the namespace's name is lower. In this case, an entry is inserted in the tree at the appropriate location. Fixed by appending the temporary namespace at the end of the tree if it was not inserted by the search loop. Fixes dokuwiki#4276
1 parent 9988e85 commit de301a3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

inc/media.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,21 +1692,26 @@ function media_nstree($ns)
16921692
$ns_parts = explode(':', $ns);
16931693
$tmp_ns = '';
16941694
$pos = 0;
1695+
$insert = false;
16951696
foreach ($ns_parts as $level => $part) {
16961697
if ($tmp_ns) $tmp_ns .= ':' . $part;
16971698
else $tmp_ns = $part;
16981699

1699-
// find the namespace parts or insert them
1700+
// find the namespace parts
17001701
while (array_key_exists($pos, $data) && $data[$pos]['id'] != $tmp_ns) {
17011702
if (
17021703
$pos >= count($data) ||
17031704
($data[$pos]['level'] <= $level + 1 && Sort::strcmp($data[$pos]['id'], $tmp_ns) > 0)
17041705
) {
1705-
array_splice($data, $pos, 0, [['level' => $level + 1, 'id' => $tmp_ns, 'open' => 'true']]);
1706+
$insert = true;
17061707
break;
17071708
}
17081709
++$pos;
17091710
}
1711+
// insert namespace in hierarchy; if not found in above loop, append it to the end
1712+
if ($insert || $pos == count($data)) {
1713+
array_splice($data, $pos, 0, [['level' => $level + 1, 'id' => $tmp_ns, 'open' => 'true']]);
1714+
}
17101715
}
17111716

17121717
echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li');

0 commit comments

Comments
 (0)