-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
if nopg, guess for nodes without headpage based on the headpage setting
If using default settings, `:start:` is always first, so behaviour is unchanged. It uses the first enabled option if multiple options are enabled. Improves #106 Edge case: if all headpage options are disabled and no custom headpage name is given, it resulted in an empty string value, which was converted in ns1: which is in general interpreted as ns1:<startpage>. Custom headpage should be not blank.
- Loading branch information
Showing
1 changed file
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,9 +325,9 @@ public function searchIndexmenuItems(&$data, $base, $file, $type, $lvl, $opts) | |
} | ||
//Set title and headpage | ||
$title = static::getNamespaceTitle($id, $headpage, $hns); | ||
//link namespace nodes to start pages when excluding page nodes | ||
if (!$hns && $opts['nopg']) { | ||
$hns = $id . ":" . $conf['start']; | ||
// when excluding page nodes: guess a headpage based on the headpage setting | ||
if ($opts['nopg'] && $hns === false) { | ||
$hns = $this->guessHeadpage($headpage, $id); | ||
} | ||
} else { | ||
//Nopg. Dont show pages | ||
|
@@ -511,9 +511,10 @@ public function searchIndexmenuItemsNew(&$data, $base, $file, $type, $lvl, $opts | |
|
||
//Set title and headpage | ||
$title = static::getNamespaceTitle($id, $headpage, $hns); | ||
//link namespace nodes to start pages when excluding page nodes | ||
if (!$hns && $opts['nopg']) { | ||
$hns = $id . ":" . $conf['start']; | ||
|
||
// when excluding page nodes: guess a headpage based on the headpage setting | ||
if ($opts['nopg'] && $hns === false) { | ||
$hns = $this->guessHeadpage($headpage, $id); | ||
} | ||
} else { | ||
//Nopg.Dont show pages | ||
|
@@ -539,8 +540,8 @@ public function searchIndexmenuItemsNew(&$data, $base, $file, $type, $lvl, $opts | |
//start page is in root | ||
if ($id == $conf['start']) return false; | ||
|
||
$ahp = explode(",", $headpage); | ||
foreach ($ahp as $hp) { | ||
$hpOptions = explode(",", $headpage); | ||
foreach ($hpOptions as $hp) { | ||
switch ($hp) { | ||
case ":inside:": | ||
if (noNS($id) == noNS(getNS($id))) return false; | ||
|
@@ -677,7 +678,7 @@ public function customSearch(&$data, $base, $func, $opts, $dir = '', $lvl = 1) | |
* | ||
* @param string $ns namespace | ||
* @param string $headpage comma-separated headpages options and headpages | ||
* @param string $hns reference pageid of headpage, false when not existing | ||
* @param string|false $hns reference pageid of headpage, false when not existing | ||
* @return string when headpage & heading on: title of headpage, otherwise: namespace name | ||
* | ||
* @author Samuele Tognini <[email protected]> | ||
|
@@ -690,8 +691,8 @@ public static function getNamespaceTitle($ns, $headpage, &$hns) | |
if (empty($headpage)) { | ||
return $title; | ||
} | ||
$ahp = explode(",", $headpage); | ||
foreach ($ahp as $hp) { | ||
$hpOptions = explode(",", $headpage); | ||
foreach ($hpOptions as $hp) { | ||
switch ($hp) { | ||
case ":inside:": | ||
$page = $ns . ":" . noNS($ns); | ||
|
@@ -705,7 +706,9 @@ public static function getNamespaceTitle($ns, $headpage, &$hns) | |
break; | ||
//inside pages | ||
default: | ||
$page = $ns . ":" . $hp; | ||
if(!blank($hp)) { //empty setting results in empty string here | ||
$page = $ns . ":" . $hp; | ||
} | ||
} | ||
//check headpage | ||
if (@file_exists(wikiFN($page)) && auth_quickaclcheck($page) >= AUTH_READ) { | ||
|
@@ -789,4 +792,45 @@ private function getSortValue($item) | |
} | ||
return $sort; | ||
} | ||
|
||
/** | ||
* Guess based on first option of the headpage config setting (default :start: if enabled) the headpage of the node | ||
* | ||
* @param string $headpage config setting | ||
* @param string $ns namespace | ||
* @return string guessed headpage | ||
*/ | ||
private function guessHeadpage(string $headpage, string $ns): string | ||
{ | ||
global $conf; | ||
$hns = false; | ||
|
||
$hpOptions = explode(",", $headpage); | ||
foreach ($hpOptions as $hp) { | ||
switch ($hp) { | ||
case ":inside:": | ||
$hns = $ns . ":" . noNS($ns); | ||
break 2; | ||
case ":same:": | ||
$hns = $ns; | ||
break 2; | ||
//it's an inside start | ||
case ":start:": | ||
$hns = ltrim($ns . ":" . $conf['start'], ":"); | ||
break 2; | ||
//inside pages | ||
default: | ||
if (!blank($hp)) { | ||
$hns = $ns . ":" . $hp; | ||
break 2; | ||
} | ||
} | ||
} | ||
|
||
if ($hns === false) { | ||
//fallback to start if headpage setting was empty | ||
$hns = ltrim($ns . ":" . $conf['start'], ":"); | ||
} | ||
return $hns; | ||
} | ||
} |